The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2006 The Android Open Source Project |
| 3 | // |
| 4 | // State bundle. Used to pass around stuff like command-line args. |
| 5 | // |
| 6 | #ifndef __BUNDLE_H |
| 7 | #define __BUNDLE_H |
| 8 | |
| 9 | #include <stdlib.h> |
Mathias Agopian | 3b4062e | 2009-05-31 19:13:00 -0700 | [diff] [blame] | 10 | #include <utils/Log.h> |
| 11 | #include <utils/threads.h> |
| 12 | #include <utils/List.h> |
| 13 | #include <utils/Errors.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14 | #include <utils/String8.h> |
| 15 | #include <utils/Vector.h> |
| 16 | |
| 17 | /* |
| 18 | * Things we can do. |
| 19 | */ |
| 20 | typedef enum Command { |
| 21 | kCommandUnknown = 0, |
| 22 | kCommandVersion, |
| 23 | kCommandList, |
| 24 | kCommandDump, |
| 25 | kCommandAdd, |
| 26 | kCommandRemove, |
| 27 | kCommandPackage, |
| 28 | } Command; |
| 29 | |
| 30 | /* |
| 31 | * Bundle of goodies, including everything specified on the command line. |
| 32 | */ |
| 33 | class Bundle { |
| 34 | public: |
| 35 | Bundle(void) |
| 36 | : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false), |
| 37 | mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false), |
| 38 | mUpdate(false), mExtending(false), |
| 39 | mRequireLocalization(false), mPseudolocalize(false), |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 40 | mWantUTF16(false), mValues(false), |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 41 | mCompressionMethod(0), mOutputAPKFile(NULL), |
| 42 | mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL), |
Mårten Kongstad | 57f4b77 | 2011-03-17 14:13:41 +0100 | [diff] [blame] | 43 | mIsOverlayPackage(false), |
Xavier Ducrohet | 99080c7 | 2010-02-04 18:45:31 -0800 | [diff] [blame] | 44 | mAutoAddOverlay(false), mAssetSourceDir(NULL), mProguardFile(NULL), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | mAndroidManifestFile(NULL), mPublicOutputFile(NULL), |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 46 | mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL), |
Dianne Hackborn | fa6baa2 | 2009-05-15 18:45:15 -0700 | [diff] [blame] | 47 | mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL), |
Josiah Gaskin | ce89f15 | 2011-06-08 19:31:40 -0700 | [diff] [blame^] | 48 | mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL), |
Xavier Ducrohet | d06c1af | 2011-02-14 16:58:00 -0800 | [diff] [blame] | 49 | mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | mArgc(0), mArgv(NULL) |
| 51 | {} |
| 52 | ~Bundle(void) {} |
| 53 | |
| 54 | /* |
| 55 | * Set the command value. Returns "false" if it was previously set. |
| 56 | */ |
| 57 | Command getCommand(void) const { return mCmd; } |
| 58 | void setCommand(Command cmd) { mCmd = cmd; } |
| 59 | |
| 60 | /* |
| 61 | * Command modifiers. Not all modifiers are appropriate for all |
| 62 | * commands. |
| 63 | */ |
| 64 | bool getVerbose(void) const { return mVerbose; } |
| 65 | void setVerbose(bool val) { mVerbose = val; } |
| 66 | bool getAndroidList(void) const { return mAndroidList; } |
| 67 | void setAndroidList(bool val) { mAndroidList = val; } |
| 68 | bool getForce(void) const { return mForce; } |
| 69 | void setForce(bool val) { mForce = val; } |
| 70 | void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; } |
| 71 | int getGrayscaleTolerance() { return mGrayscaleTolerance; } |
| 72 | bool getMakePackageDirs(void) const { return mMakePackageDirs; } |
| 73 | void setMakePackageDirs(bool val) { mMakePackageDirs = val; } |
| 74 | bool getUpdate(void) const { return mUpdate; } |
| 75 | void setUpdate(bool val) { mUpdate = val; } |
| 76 | bool getExtending(void) const { return mExtending; } |
| 77 | void setExtending(bool val) { mExtending = val; } |
| 78 | bool getRequireLocalization(void) const { return mRequireLocalization; } |
| 79 | void setRequireLocalization(bool val) { mRequireLocalization = val; } |
| 80 | bool getPseudolocalize(void) const { return mPseudolocalize; } |
| 81 | void setPseudolocalize(bool val) { mPseudolocalize = val; } |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 82 | bool getWantUTF16(void) const { return mWantUTF16; } |
| 83 | void setWantUTF16(bool val) { mWantUTF16 = val; } |
Dianne Hackborn | e17086b | 2009-06-19 15:13:28 -0700 | [diff] [blame] | 84 | bool getValues(void) const { return mValues; } |
| 85 | void setValues(bool val) { mValues = val; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | int getCompressionMethod(void) const { return mCompressionMethod; } |
| 87 | void setCompressionMethod(int val) { mCompressionMethod = val; } |
Doug Zongker | dbe7a68 | 2009-10-09 11:24:51 -0700 | [diff] [blame] | 88 | bool getJunkPath(void) const { return mJunkPath; } |
| 89 | void setJunkPath(bool val) { mJunkPath = val; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | const char* getOutputAPKFile() const { return mOutputAPKFile; } |
| 91 | void setOutputAPKFile(const char* val) { mOutputAPKFile = val; } |
Jeff Hamilton | 2fee0ed | 2010-01-06 15:46:38 -0600 | [diff] [blame] | 92 | const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; } |
| 93 | void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 94 | const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; } |
| 95 | void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; } |
Mårten Kongstad | 57f4b77 | 2011-03-17 14:13:41 +0100 | [diff] [blame] | 96 | bool getIsOverlayPackage() const { return mIsOverlayPackage; } |
| 97 | void setIsOverlayPackage(bool val) { mIsOverlayPackage = val; } |
Xavier Ducrohet | 99080c7 | 2010-02-04 18:45:31 -0800 | [diff] [blame] | 98 | bool getAutoAddOverlay() { return mAutoAddOverlay; } |
| 99 | void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
Doug Zongker | dbe7a68 | 2009-10-09 11:24:51 -0700 | [diff] [blame] | 101 | /* |
| 102 | * Input options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | */ |
| 104 | const char* getAssetSourceDir() const { return mAssetSourceDir; } |
| 105 | void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; } |
Joe Onorato | 1553c82 | 2009-08-30 13:36:22 -0700 | [diff] [blame] | 106 | const char* getProguardFile() const { return mProguardFile; } |
| 107 | void setProguardFile(const char* file) { mProguardFile = file; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; } |
| 109 | void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); } |
| 110 | const char* getAndroidManifestFile() const { return mAndroidManifestFile; } |
| 111 | void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; } |
| 112 | const char* getPublicOutputFile() const { return mPublicOutputFile; } |
| 113 | void setPublicOutputFile(const char* file) { mPublicOutputFile = file; } |
| 114 | const char* getRClassDir() const { return mRClassDir; } |
| 115 | void setRClassDir(const char* dir) { mRClassDir = dir; } |
| 116 | const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; } |
| 117 | void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } } |
| 118 | const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; } |
| 119 | void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; } |
| 120 | const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; } |
| 121 | void addPackageInclude(const char* file) { mPackageIncludes.add(file); } |
| 122 | const android::Vector<const char*>& getJarFiles() const { return mJarFiles; } |
| 123 | void addJarFile(const char* file) { mJarFiles.add(file); } |
| 124 | const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; } |
| 125 | void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); } |
| 126 | |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 127 | const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; } |
| 128 | void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; } |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 129 | const char* getMinSdkVersion() const { return mMinSdkVersion; } |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 130 | void setMinSdkVersion(const char* val) { mMinSdkVersion = val; } |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 131 | const char* getTargetSdkVersion() const { return mTargetSdkVersion; } |
| 132 | void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; } |
| 133 | const char* getMaxSdkVersion() const { return mMaxSdkVersion; } |
| 134 | void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; } |
| 135 | const char* getVersionCode() const { return mVersionCode; } |
| 136 | void setVersionCode(const char* val) { mVersionCode = val; } |
| 137 | const char* getVersionName() const { return mVersionName; } |
| 138 | void setVersionName(const char* val) { mVersionName = val; } |
Xavier Ducrohet | 63459ad | 2009-11-30 18:05:10 -0800 | [diff] [blame] | 139 | const char* getCustomPackage() const { return mCustomPackage; } |
| 140 | void setCustomPackage(const char* val) { mCustomPackage = val; } |
Josiah Gaskin | ce89f15 | 2011-06-08 19:31:40 -0700 | [diff] [blame^] | 141 | const char* getExtraPackages() const { return mExtraPackages; } |
| 142 | void setExtraPackages(const char* val) { mExtraPackages = val; } |
Ficus Kirkpatrick | 588f228 | 2010-08-13 14:13:08 -0700 | [diff] [blame] | 143 | const char* getMaxResVersion() const { return mMaxResVersion; } |
| 144 | void setMaxResVersion(const char * val) { mMaxResVersion = val; } |
Xavier Ducrohet | 6487b09 | 2010-08-31 10:45:31 -0700 | [diff] [blame] | 145 | bool getDebugMode() { return mDebugMode; } |
| 146 | void setDebugMode(bool val) { mDebugMode = val; } |
Xavier Ducrohet | d06c1af | 2011-02-14 16:58:00 -0800 | [diff] [blame] | 147 | bool getNonConstantId() { return mNonConstantId; } |
| 148 | void setNonConstantId(bool val) { mNonConstantId = val; } |
Eric Fischer | 9096404 | 2010-09-15 15:59:21 -0700 | [diff] [blame] | 149 | const char* getProduct() const { return mProduct; } |
| 150 | void setProduct(const char * val) { mProduct = val; } |
Doug Zongker | dbe7a68 | 2009-10-09 11:24:51 -0700 | [diff] [blame] | 151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | /* |
| 153 | * Set and get the file specification. |
| 154 | * |
| 155 | * Note this does NOT make a copy of argv. |
| 156 | */ |
| 157 | void setFileSpec(char* const argv[], int argc) { |
| 158 | mArgc = argc; |
| 159 | mArgv = argv; |
| 160 | } |
| 161 | int getFileSpecCount(void) const { return mArgc; } |
| 162 | const char* getFileSpecEntry(int idx) const { return mArgv[idx]; } |
| 163 | void eatArgs(int n) { |
| 164 | if (n > mArgc) n = mArgc; |
| 165 | mArgv += n; |
| 166 | mArgc -= n; |
| 167 | } |
| 168 | |
| 169 | #if 0 |
| 170 | /* |
| 171 | * Package count. Nothing to do with anything else here; this is |
| 172 | * just a convenient place to stuff it so we don't have to pass it |
| 173 | * around everywhere. |
| 174 | */ |
| 175 | int getPackageCount(void) const { return mPackageCount; } |
| 176 | void setPackageCount(int val) { mPackageCount = val; } |
| 177 | #endif |
| 178 | |
Kenny Root | c9f3088 | 2010-03-24 11:55:16 -0700 | [diff] [blame] | 179 | /* Certain features may only be available on a specific SDK level or |
| 180 | * above. SDK levels that have a non-numeric identifier are assumed |
| 181 | * to be newer than any SDK level that has a number designated. |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 182 | */ |
Kenny Root | c9f3088 | 2010-03-24 11:55:16 -0700 | [diff] [blame] | 183 | bool isMinSdkAtLeast(int desired) { |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 184 | /* If the application specifies a minSdkVersion in the manifest |
| 185 | * then use that. Otherwise, check what the user specified on |
| 186 | * the command line. If neither, it's not available since |
| 187 | * the minimum SDK version is assumed to be 1. |
| 188 | */ |
| 189 | const char *minVer; |
| 190 | if (mManifestMinSdkVersion != NULL) { |
| 191 | minVer = mManifestMinSdkVersion; |
| 192 | } else if (mMinSdkVersion != NULL) { |
| 193 | minVer = mMinSdkVersion; |
| 194 | } else { |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | char *end; |
| 199 | int minSdkNum = (int)strtol(minVer, &end, 0); |
| 200 | if (*end == '\0') { |
Kenny Root | c9f3088 | 2010-03-24 11:55:16 -0700 | [diff] [blame] | 201 | if (minSdkNum < desired) { |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 202 | return false; |
| 203 | } |
| 204 | } |
| 205 | return true; |
| 206 | } |
| 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | private: |
| 209 | /* commands & modifiers */ |
| 210 | Command mCmd; |
| 211 | bool mVerbose; |
| 212 | bool mAndroidList; |
| 213 | bool mForce; |
| 214 | int mGrayscaleTolerance; |
| 215 | bool mMakePackageDirs; |
| 216 | bool mUpdate; |
| 217 | bool mExtending; |
| 218 | bool mRequireLocalization; |
| 219 | bool mPseudolocalize; |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 220 | bool mWantUTF16; |
Dianne Hackborn | e17086b | 2009-06-19 15:13:28 -0700 | [diff] [blame] | 221 | bool mValues; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | int mCompressionMethod; |
Doug Zongker | dbe7a68 | 2009-10-09 11:24:51 -0700 | [diff] [blame] | 223 | bool mJunkPath; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | const char* mOutputAPKFile; |
Jeff Hamilton | 2fee0ed | 2010-01-06 15:46:38 -0600 | [diff] [blame] | 225 | const char* mManifestPackageNameOverride; |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 226 | const char* mInstrumentationPackageNameOverride; |
Mårten Kongstad | 57f4b77 | 2011-03-17 14:13:41 +0100 | [diff] [blame] | 227 | bool mIsOverlayPackage; |
Xavier Ducrohet | 99080c7 | 2010-02-04 18:45:31 -0800 | [diff] [blame] | 228 | bool mAutoAddOverlay; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | const char* mAssetSourceDir; |
Joe Onorato | 1553c82 | 2009-08-30 13:36:22 -0700 | [diff] [blame] | 230 | const char* mProguardFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | const char* mAndroidManifestFile; |
| 232 | const char* mPublicOutputFile; |
| 233 | const char* mRClassDir; |
| 234 | const char* mResourceIntermediatesDir; |
| 235 | android::String8 mConfigurations; |
| 236 | android::Vector<const char*> mPackageIncludes; |
| 237 | android::Vector<const char*> mJarFiles; |
| 238 | android::Vector<const char*> mNoCompressExtensions; |
| 239 | android::Vector<const char*> mResourceSourceDirs; |
Doug Zongker | dbe7a68 | 2009-10-09 11:24:51 -0700 | [diff] [blame] | 240 | |
Kenny Root | 1741cd4 | 2010-03-18 12:12:11 -0700 | [diff] [blame] | 241 | const char* mManifestMinSdkVersion; |
Dianne Hackborn | a96cbb4 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 242 | const char* mMinSdkVersion; |
| 243 | const char* mTargetSdkVersion; |
| 244 | const char* mMaxSdkVersion; |
| 245 | const char* mVersionCode; |
| 246 | const char* mVersionName; |
Xavier Ducrohet | 63459ad | 2009-11-30 18:05:10 -0800 | [diff] [blame] | 247 | const char* mCustomPackage; |
Josiah Gaskin | ce89f15 | 2011-06-08 19:31:40 -0700 | [diff] [blame^] | 248 | const char* mExtraPackages; |
Ficus Kirkpatrick | 588f228 | 2010-08-13 14:13:08 -0700 | [diff] [blame] | 249 | const char* mMaxResVersion; |
Xavier Ducrohet | 6487b09 | 2010-08-31 10:45:31 -0700 | [diff] [blame] | 250 | bool mDebugMode; |
Xavier Ducrohet | d06c1af | 2011-02-14 16:58:00 -0800 | [diff] [blame] | 251 | bool mNonConstantId; |
Eric Fischer | 9096404 | 2010-09-15 15:59:21 -0700 | [diff] [blame] | 252 | const char* mProduct; |
Doug Zongker | dbe7a68 | 2009-10-09 11:24:51 -0700 | [diff] [blame] | 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | /* file specification */ |
| 255 | int mArgc; |
| 256 | char* const* mArgv; |
| 257 | |
| 258 | #if 0 |
| 259 | /* misc stuff */ |
| 260 | int mPackageCount; |
| 261 | #endif |
Kenny Root | b5ef7ee | 2009-12-10 13:52:53 -0800 | [diff] [blame] | 262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | #endif // __BUNDLE_H |