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> 10 #include <utils/Log.h> 11 #include <utils/threads.h> 12 #include <utils/List.h> 13 #include <utils/Errors.h> 14 #include <utils/String8.h> 15 #include <utils/Vector.h> 16 17 enum { 18 SDK_CUPCAKE = 3, 19 SDK_DONUT = 4, 20 SDK_ECLAIR = 5, 21 SDK_ECLAIR_0_1 = 6, 22 SDK_MR1 = 7, 23 SDK_FROYO = 8, 24 SDK_HONEYCOMB_MR2 = 13, 25 SDK_ICE_CREAM_SANDWICH = 14, 26 SDK_ICE_CREAM_SANDWICH_MR1 = 15, 27 SDK_L = 21, 28 }; 29 30 /* 31 * Things we can do. 32 */ 33 typedef enum Command { 34 kCommandUnknown = 0, 35 kCommandVersion, 36 kCommandList, 37 kCommandDump, 38 kCommandAdd, 39 kCommandRemove, 40 kCommandPackage, 41 kCommandCrunch, 42 kCommandSingleCrunch, 43 kCommandDaemon 44 } Command; 45 46 /* 47 * Pseudolocalization methods 48 */ 49 typedef enum PseudolocalizationMethod { 50 NO_PSEUDOLOCALIZATION = 0, 51 PSEUDO_ACCENTED, 52 PSEUDO_BIDI, 53 } PseudolocalizationMethod; 54 55 /* 56 * Bundle of goodies, including everything specified on the command line. 57 */ 58 class Bundle { 59 public: Bundle(void)60 Bundle(void) 61 : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false), 62 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false), 63 mUpdate(false), mExtending(false), 64 mRequireLocalization(false), mPseudolocalize(NO_PSEUDOLOCALIZATION), 65 mWantUTF16(false), mValues(false), mIncludeMetaData(false), 66 mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL), 67 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL), 68 mAutoAddOverlay(false), mGenDependencies(false), 69 mCrunchedOutputDir(NULL), mProguardFile(NULL), 70 mAndroidManifestFile(NULL), mPublicOutputFile(NULL), 71 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL), 72 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL), 73 mVersionCode(NULL), mVersionName(NULL), mReplaceVersion(false), mCustomPackage(NULL), 74 mExtraPackages(NULL), mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), 75 mProduct(NULL), mUseCrunchCache(false), mErrorOnFailedInsert(false), 76 mErrorOnMissingConfigEntry(false), mOutputTextSymbols(NULL), 77 mSingleCrunchInputFile(NULL), mSingleCrunchOutputFile(NULL), 78 mBuildSharedLibrary(false), 79 mArgc(0), mArgv(NULL) 80 {} ~Bundle(void)81 ~Bundle(void) {} 82 83 /* 84 * Set the command value. Returns "false" if it was previously set. 85 */ getCommand(void)86 Command getCommand(void) const { return mCmd; } setCommand(Command cmd)87 void setCommand(Command cmd) { mCmd = cmd; } 88 89 /* 90 * Command modifiers. Not all modifiers are appropriate for all 91 * commands. 92 */ getVerbose(void)93 bool getVerbose(void) const { return mVerbose; } setVerbose(bool val)94 void setVerbose(bool val) { mVerbose = val; } getAndroidList(void)95 bool getAndroidList(void) const { return mAndroidList; } setAndroidList(bool val)96 void setAndroidList(bool val) { mAndroidList = val; } getForce(void)97 bool getForce(void) const { return mForce; } setForce(bool val)98 void setForce(bool val) { mForce = val; } setGrayscaleTolerance(int val)99 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; } getGrayscaleTolerance()100 int getGrayscaleTolerance() const { return mGrayscaleTolerance; } getMakePackageDirs(void)101 bool getMakePackageDirs(void) const { return mMakePackageDirs; } setMakePackageDirs(bool val)102 void setMakePackageDirs(bool val) { mMakePackageDirs = val; } getUpdate(void)103 bool getUpdate(void) const { return mUpdate; } setUpdate(bool val)104 void setUpdate(bool val) { mUpdate = val; } getExtending(void)105 bool getExtending(void) const { return mExtending; } setExtending(bool val)106 void setExtending(bool val) { mExtending = val; } getRequireLocalization(void)107 bool getRequireLocalization(void) const { return mRequireLocalization; } setRequireLocalization(bool val)108 void setRequireLocalization(bool val) { mRequireLocalization = val; } getPseudolocalize(void)109 short getPseudolocalize(void) const { return mPseudolocalize; } setPseudolocalize(short val)110 void setPseudolocalize(short val) { mPseudolocalize = val; } setWantUTF16(bool val)111 void setWantUTF16(bool val) { mWantUTF16 = val; } getValues(void)112 bool getValues(void) const { return mValues; } setValues(bool val)113 void setValues(bool val) { mValues = val; } getIncludeMetaData(void)114 bool getIncludeMetaData(void) const { return mIncludeMetaData; } setIncludeMetaData(bool val)115 void setIncludeMetaData(bool val) { mIncludeMetaData = val; } getCompressionMethod(void)116 int getCompressionMethod(void) const { return mCompressionMethod; } setCompressionMethod(int val)117 void setCompressionMethod(int val) { mCompressionMethod = val; } getJunkPath(void)118 bool getJunkPath(void) const { return mJunkPath; } setJunkPath(bool val)119 void setJunkPath(bool val) { mJunkPath = val; } getOutputAPKFile()120 const char* getOutputAPKFile() const { return mOutputAPKFile; } setOutputAPKFile(const char * val)121 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; } getManifestPackageNameOverride()122 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; } setManifestPackageNameOverride(const char * val)123 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } getInstrumentationPackageNameOverride()124 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; } setInstrumentationPackageNameOverride(const char * val)125 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; } getAutoAddOverlay()126 bool getAutoAddOverlay() { return mAutoAddOverlay; } setAutoAddOverlay(bool val)127 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; } getGenDependencies()128 bool getGenDependencies() { return mGenDependencies; } setGenDependencies(bool val)129 void setGenDependencies(bool val) { mGenDependencies = val; } getErrorOnFailedInsert()130 bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; } setErrorOnFailedInsert(bool val)131 void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; } getErrorOnMissingConfigEntry()132 bool getErrorOnMissingConfigEntry() { return mErrorOnMissingConfigEntry; } setErrorOnMissingConfigEntry(bool val)133 void setErrorOnMissingConfigEntry(bool val) { mErrorOnMissingConfigEntry = val; } getPlatformBuildVersionCode()134 const android::String8& getPlatformBuildVersionCode() { return mPlatformVersionCode; } setPlatformBuildVersionCode(const android::String8 & code)135 void setPlatformBuildVersionCode(const android::String8& code) { mPlatformVersionCode = code; } getPlatformBuildVersionName()136 const android::String8& getPlatformBuildVersionName() { return mPlatformVersionName; } setPlatformBuildVersionName(const android::String8 & name)137 void setPlatformBuildVersionName(const android::String8& name) { mPlatformVersionName = name; } 138 getUTF16StringsOption()139 bool getUTF16StringsOption() { 140 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO); 141 } 142 143 /* 144 * Input options. 145 */ getAssetSourceDirs()146 const android::Vector<const char*>& getAssetSourceDirs() const { return mAssetSourceDirs; } addAssetSourceDir(const char * dir)147 void addAssetSourceDir(const char* dir) { mAssetSourceDirs.insertAt(dir,0); } getCrunchedOutputDir()148 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; } setCrunchedOutputDir(const char * dir)149 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; } getProguardFile()150 const char* getProguardFile() const { return mProguardFile; } setProguardFile(const char * file)151 void setProguardFile(const char* file) { mProguardFile = file; } getResourceSourceDirs()152 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; } addResourceSourceDir(const char * dir)153 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); } getAndroidManifestFile()154 const char* getAndroidManifestFile() const { return mAndroidManifestFile; } setAndroidManifestFile(const char * file)155 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; } getPublicOutputFile()156 const char* getPublicOutputFile() const { return mPublicOutputFile; } setPublicOutputFile(const char * file)157 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; } getRClassDir()158 const char* getRClassDir() const { return mRClassDir; } setRClassDir(const char * dir)159 void setRClassDir(const char* dir) { mRClassDir = dir; } getConfigurations()160 const android::String8& getConfigurations() const { return mConfigurations; } addConfigurations(const char * val)161 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } } getPreferredDensity()162 const android::String8& getPreferredDensity() const { return mPreferredDensity; } setPreferredDensity(const char * val)163 void setPreferredDensity(const char* val) { mPreferredDensity = val; } addSplitConfigurations(const char * val)164 void addSplitConfigurations(const char* val) { mPartialConfigurations.add(android::String8(val)); } getSplitConfigurations()165 const android::Vector<android::String8>& getSplitConfigurations() const { return mPartialConfigurations; } getResourceIntermediatesDir()166 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; } setResourceIntermediatesDir(const char * dir)167 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; } getPackageIncludes()168 const android::Vector<android::String8>& getPackageIncludes() const { return mPackageIncludes; } addPackageInclude(const char * file)169 void addPackageInclude(const char* file) { mPackageIncludes.add(android::String8(file)); } getJarFiles()170 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; } addJarFile(const char * file)171 void addJarFile(const char* file) { mJarFiles.add(file); } getNoCompressExtensions()172 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; } addNoCompressExtension(const char * ext)173 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); } setFeatureOfPackage(const char * str)174 void setFeatureOfPackage(const char* str) { mFeatureOfPackage = str; } getFeatureOfPackage()175 const android::String8& getFeatureOfPackage() const { return mFeatureOfPackage; } setFeatureAfterPackage(const char * str)176 void setFeatureAfterPackage(const char* str) { mFeatureAfterPackage = str; } getFeatureAfterPackage()177 const android::String8& getFeatureAfterPackage() const { return mFeatureAfterPackage; } 178 getManifestMinSdkVersion()179 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; } setManifestMinSdkVersion(const char * val)180 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; } getMinSdkVersion()181 const char* getMinSdkVersion() const { return mMinSdkVersion; } setMinSdkVersion(const char * val)182 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; } getTargetSdkVersion()183 const char* getTargetSdkVersion() const { return mTargetSdkVersion; } setTargetSdkVersion(const char * val)184 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; } getMaxSdkVersion()185 const char* getMaxSdkVersion() const { return mMaxSdkVersion; } setMaxSdkVersion(const char * val)186 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; } getVersionCode()187 const char* getVersionCode() const { return mVersionCode; } setVersionCode(const char * val)188 void setVersionCode(const char* val) { mVersionCode = val; } getVersionName()189 const char* getVersionName() const { return mVersionName; } setVersionName(const char * val)190 void setVersionName(const char* val) { mVersionName = val; } getReplaceVersion()191 bool getReplaceVersion() { return mReplaceVersion; } setReplaceVersion(bool val)192 void setReplaceVersion(bool val) { mReplaceVersion = val; } getCustomPackage()193 const char* getCustomPackage() const { return mCustomPackage; } setCustomPackage(const char * val)194 void setCustomPackage(const char* val) { mCustomPackage = val; } getExtraPackages()195 const char* getExtraPackages() const { return mExtraPackages; } setExtraPackages(const char * val)196 void setExtraPackages(const char* val) { mExtraPackages = val; } getMaxResVersion()197 const char* getMaxResVersion() const { return mMaxResVersion; } setMaxResVersion(const char * val)198 void setMaxResVersion(const char * val) { mMaxResVersion = val; } getDebugMode()199 bool getDebugMode() const { return mDebugMode; } setDebugMode(bool val)200 void setDebugMode(bool val) { mDebugMode = val; } getNonConstantId()201 bool getNonConstantId() const { return mNonConstantId; } setNonConstantId(bool val)202 void setNonConstantId(bool val) { mNonConstantId = val; } getProduct()203 const char* getProduct() const { return mProduct; } setProduct(const char * val)204 void setProduct(const char * val) { mProduct = val; } setUseCrunchCache(bool val)205 void setUseCrunchCache(bool val) { mUseCrunchCache = val; } getUseCrunchCache()206 bool getUseCrunchCache() const { return mUseCrunchCache; } getOutputTextSymbols()207 const char* getOutputTextSymbols() const { return mOutputTextSymbols; } setOutputTextSymbols(const char * val)208 void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; } getSingleCrunchInputFile()209 const char* getSingleCrunchInputFile() const { return mSingleCrunchInputFile; } setSingleCrunchInputFile(const char * val)210 void setSingleCrunchInputFile(const char* val) { mSingleCrunchInputFile = val; } getSingleCrunchOutputFile()211 const char* getSingleCrunchOutputFile() const { return mSingleCrunchOutputFile; } setSingleCrunchOutputFile(const char * val)212 void setSingleCrunchOutputFile(const char* val) { mSingleCrunchOutputFile = val; } getBuildSharedLibrary()213 bool getBuildSharedLibrary() const { return mBuildSharedLibrary; } setBuildSharedLibrary(bool val)214 void setBuildSharedLibrary(bool val) { mBuildSharedLibrary = val; } 215 216 /* 217 * Set and get the file specification. 218 * 219 * Note this does NOT make a copy of argv. 220 */ setFileSpec(char * const argv[],int argc)221 void setFileSpec(char* const argv[], int argc) { 222 mArgc = argc; 223 mArgv = argv; 224 } getFileSpecCount(void)225 int getFileSpecCount(void) const { return mArgc; } getFileSpecEntry(int idx)226 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; } eatArgs(int n)227 void eatArgs(int n) { 228 if (n > mArgc) n = mArgc; 229 mArgv += n; 230 mArgc -= n; 231 } 232 233 #if 0 234 /* 235 * Package count. Nothing to do with anything else here; this is 236 * just a convenient place to stuff it so we don't have to pass it 237 * around everywhere. 238 */ 239 int getPackageCount(void) const { return mPackageCount; } 240 void setPackageCount(int val) { mPackageCount = val; } 241 #endif 242 243 /* Certain features may only be available on a specific SDK level or 244 * above. SDK levels that have a non-numeric identifier are assumed 245 * to be newer than any SDK level that has a number designated. 246 */ isMinSdkAtLeast(int desired)247 bool isMinSdkAtLeast(int desired) { 248 /* If the application specifies a minSdkVersion in the manifest 249 * then use that. Otherwise, check what the user specified on 250 * the command line. If neither, it's not available since 251 * the minimum SDK version is assumed to be 1. 252 */ 253 const char *minVer; 254 if (mManifestMinSdkVersion != NULL) { 255 minVer = mManifestMinSdkVersion; 256 } else if (mMinSdkVersion != NULL) { 257 minVer = mMinSdkVersion; 258 } else { 259 return false; 260 } 261 262 char *end; 263 int minSdkNum = (int)strtol(minVer, &end, 0); 264 if (*end == '\0') { 265 if (minSdkNum < desired) { 266 return false; 267 } 268 } 269 return true; 270 } 271 272 private: 273 /* commands & modifiers */ 274 Command mCmd; 275 bool mVerbose; 276 bool mAndroidList; 277 bool mForce; 278 int mGrayscaleTolerance; 279 bool mMakePackageDirs; 280 bool mUpdate; 281 bool mExtending; 282 bool mRequireLocalization; 283 short mPseudolocalize; 284 bool mWantUTF16; 285 bool mValues; 286 bool mIncludeMetaData; 287 int mCompressionMethod; 288 bool mJunkPath; 289 const char* mOutputAPKFile; 290 const char* mManifestPackageNameOverride; 291 const char* mInstrumentationPackageNameOverride; 292 bool mAutoAddOverlay; 293 bool mGenDependencies; 294 const char* mCrunchedOutputDir; 295 const char* mProguardFile; 296 const char* mAndroidManifestFile; 297 const char* mPublicOutputFile; 298 const char* mRClassDir; 299 const char* mResourceIntermediatesDir; 300 android::String8 mConfigurations; 301 android::String8 mPreferredDensity; 302 android::Vector<android::String8> mPartialConfigurations; 303 android::Vector<android::String8> mPackageIncludes; 304 android::Vector<const char*> mJarFiles; 305 android::Vector<const char*> mNoCompressExtensions; 306 android::Vector<const char*> mAssetSourceDirs; 307 android::Vector<const char*> mResourceSourceDirs; 308 309 android::String8 mFeatureOfPackage; 310 android::String8 mFeatureAfterPackage; 311 const char* mManifestMinSdkVersion; 312 const char* mMinSdkVersion; 313 const char* mTargetSdkVersion; 314 const char* mMaxSdkVersion; 315 const char* mVersionCode; 316 const char* mVersionName; 317 bool mReplaceVersion; 318 const char* mCustomPackage; 319 const char* mExtraPackages; 320 const char* mMaxResVersion; 321 bool mDebugMode; 322 bool mNonConstantId; 323 const char* mProduct; 324 bool mUseCrunchCache; 325 bool mErrorOnFailedInsert; 326 bool mErrorOnMissingConfigEntry; 327 const char* mOutputTextSymbols; 328 const char* mSingleCrunchInputFile; 329 const char* mSingleCrunchOutputFile; 330 bool mBuildSharedLibrary; 331 android::String8 mPlatformVersionCode; 332 android::String8 mPlatformVersionName; 333 334 /* file specification */ 335 int mArgc; 336 char* const* mArgv; 337 338 #if 0 339 /* misc stuff */ 340 int mPackageCount; 341 #endif 342 343 }; 344 345 #endif // __BUNDLE_H 346