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