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 mArgc(0), mArgv(NULL) 72 {} ~Bundle(void)73 ~Bundle(void) {} 74 75 /* 76 * Set the command value. Returns "false" if it was previously set. 77 */ getCommand(void)78 Command getCommand(void) const { return mCmd; } setCommand(Command cmd)79 void setCommand(Command cmd) { mCmd = cmd; } 80 81 /* 82 * Command modifiers. Not all modifiers are appropriate for all 83 * commands. 84 */ getVerbose(void)85 bool getVerbose(void) const { return mVerbose; } setVerbose(bool val)86 void setVerbose(bool val) { mVerbose = val; } getAndroidList(void)87 bool getAndroidList(void) const { return mAndroidList; } setAndroidList(bool val)88 void setAndroidList(bool val) { mAndroidList = val; } getForce(void)89 bool getForce(void) const { return mForce; } setForce(bool val)90 void setForce(bool val) { mForce = val; } setGrayscaleTolerance(int val)91 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; } getGrayscaleTolerance()92 int getGrayscaleTolerance() const { return mGrayscaleTolerance; } getMakePackageDirs(void)93 bool getMakePackageDirs(void) const { return mMakePackageDirs; } setMakePackageDirs(bool val)94 void setMakePackageDirs(bool val) { mMakePackageDirs = val; } getUpdate(void)95 bool getUpdate(void) const { return mUpdate; } setUpdate(bool val)96 void setUpdate(bool val) { mUpdate = val; } getExtending(void)97 bool getExtending(void) const { return mExtending; } setExtending(bool val)98 void setExtending(bool val) { mExtending = val; } getRequireLocalization(void)99 bool getRequireLocalization(void) const { return mRequireLocalization; } setRequireLocalization(bool val)100 void setRequireLocalization(bool val) { mRequireLocalization = val; } getPseudolocalize(void)101 short getPseudolocalize(void) const { return mPseudolocalize; } setPseudolocalize(short val)102 void setPseudolocalize(short val) { mPseudolocalize = val; } setWantUTF16(bool val)103 void setWantUTF16(bool val) { mWantUTF16 = val; } getValues(void)104 bool getValues(void) const { return mValues; } setValues(bool val)105 void setValues(bool val) { mValues = val; } getIncludeMetaData(void)106 bool getIncludeMetaData(void) const { return mIncludeMetaData; } setIncludeMetaData(bool val)107 void setIncludeMetaData(bool val) { mIncludeMetaData = val; } getCompressionMethod(void)108 int getCompressionMethod(void) const { return mCompressionMethod; } setCompressionMethod(int val)109 void setCompressionMethod(int val) { mCompressionMethod = val; } getJunkPath(void)110 bool getJunkPath(void) const { return mJunkPath; } setJunkPath(bool val)111 void setJunkPath(bool val) { mJunkPath = val; } getOutputAPKFile()112 const char* getOutputAPKFile() const { return mOutputAPKFile; } setOutputAPKFile(const char * val)113 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; } getManifestPackageNameOverride()114 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; } setManifestPackageNameOverride(const char * val)115 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } getInstrumentationPackageNameOverride()116 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; } setInstrumentationPackageNameOverride(const char * val)117 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; } getAutoAddOverlay()118 bool getAutoAddOverlay() { return mAutoAddOverlay; } setAutoAddOverlay(bool val)119 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; } getGenDependencies()120 bool getGenDependencies() { return mGenDependencies; } setGenDependencies(bool val)121 void setGenDependencies(bool val) { mGenDependencies = val; } getErrorOnFailedInsert()122 bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; } setErrorOnFailedInsert(bool val)123 void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; } getErrorOnMissingConfigEntry()124 bool getErrorOnMissingConfigEntry() { return mErrorOnMissingConfigEntry; } setErrorOnMissingConfigEntry(bool val)125 void setErrorOnMissingConfigEntry(bool val) { mErrorOnMissingConfigEntry = val; } getPlatformBuildVersionCode()126 const android::String8& getPlatformBuildVersionCode() { return mPlatformVersionCode; } setPlatformBuildVersionCode(const android::String8 & code)127 void setPlatformBuildVersionCode(const android::String8& code) { mPlatformVersionCode = code; } getPlatformBuildVersionName()128 const android::String8& getPlatformBuildVersionName() { return mPlatformVersionName; } setPlatformBuildVersionName(const android::String8 & name)129 void setPlatformBuildVersionName(const android::String8& name) { mPlatformVersionName = name; } 130 getPrivateSymbolsPackage()131 const android::String8& getPrivateSymbolsPackage() const { return mPrivateSymbolsPackage; } 132 setPrivateSymbolsPackage(const android::String8 & package)133 void setPrivateSymbolsPackage(const android::String8& package) { 134 mPrivateSymbolsPackage = package; 135 } 136 getUTF16StringsOption()137 bool getUTF16StringsOption() { 138 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO); 139 } 140 141 /* 142 * Input options. 143 */ getAssetSourceDirs()144 const android::Vector<const char*>& getAssetSourceDirs() const { return mAssetSourceDirs; } addAssetSourceDir(const char * dir)145 void addAssetSourceDir(const char* dir) { mAssetSourceDirs.insertAt(dir,0); } getCrunchedOutputDir()146 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; } setCrunchedOutputDir(const char * dir)147 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; } getProguardFile()148 const char* getProguardFile() const { return mProguardFile; } setProguardFile(const char * file)149 void setProguardFile(const char* file) { mProguardFile = file; } getMainDexProguardFile()150 const char* getMainDexProguardFile() const { return mMainDexProguardFile; } setMainDexProguardFile(const char * file)151 void setMainDexProguardFile(const char* file) { mMainDexProguardFile = 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; } getRevisionCode()193 const android::String8& getRevisionCode() { return mRevisionCode; } setRevisionCode(const char * val)194 void setRevisionCode(const char* val) { mRevisionCode = android::String8(val); } getCustomPackage()195 const char* getCustomPackage() const { return mCustomPackage; } setCustomPackage(const char * val)196 void setCustomPackage(const char* val) { mCustomPackage = val; } getExtraPackages()197 const char* getExtraPackages() const { return mExtraPackages; } setExtraPackages(const char * val)198 void setExtraPackages(const char* val) { mExtraPackages = val; } getMaxResVersion()199 const char* getMaxResVersion() const { return mMaxResVersion; } setMaxResVersion(const char * val)200 void setMaxResVersion(const char * val) { mMaxResVersion = val; } getDebugMode()201 bool getDebugMode() const { return mDebugMode; } setDebugMode(bool val)202 void setDebugMode(bool val) { mDebugMode = val; } getNonConstantId()203 bool getNonConstantId() const { return mNonConstantId; } setNonConstantId(bool val)204 void setNonConstantId(bool val) { mNonConstantId = val; } getSkipSymbolsWithoutDefaultLocalization()205 bool getSkipSymbolsWithoutDefaultLocalization() const { return mSkipSymbolsWithoutDefaultLocalization; } setSkipSymbolsWithoutDefaultLocalization(bool val)206 void setSkipSymbolsWithoutDefaultLocalization(bool val) { mSkipSymbolsWithoutDefaultLocalization = val; } getProduct()207 const char* getProduct() const { return mProduct; } setProduct(const char * val)208 void setProduct(const char * val) { mProduct = val; } setUseCrunchCache(bool val)209 void setUseCrunchCache(bool val) { mUseCrunchCache = val; } getUseCrunchCache()210 bool getUseCrunchCache() const { return mUseCrunchCache; } getOutputTextSymbols()211 const char* getOutputTextSymbols() const { return mOutputTextSymbols; } setOutputTextSymbols(const char * val)212 void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; } getSingleCrunchInputFile()213 const char* getSingleCrunchInputFile() const { return mSingleCrunchInputFile; } setSingleCrunchInputFile(const char * val)214 void setSingleCrunchInputFile(const char* val) { mSingleCrunchInputFile = val; } getSingleCrunchOutputFile()215 const char* getSingleCrunchOutputFile() const { return mSingleCrunchOutputFile; } setSingleCrunchOutputFile(const char * val)216 void setSingleCrunchOutputFile(const char* val) { mSingleCrunchOutputFile = val; } getBuildSharedLibrary()217 bool getBuildSharedLibrary() const { return mBuildSharedLibrary; } setBuildSharedLibrary(bool val)218 void setBuildSharedLibrary(bool val) { mBuildSharedLibrary = val; } getBuildAppAsSharedLibrary()219 bool getBuildAppAsSharedLibrary() const { return mBuildAppAsSharedLibrary; } setBuildAppAsSharedLibrary(bool val)220 void setBuildAppAsSharedLibrary(bool val) { mBuildAppAsSharedLibrary = val; } setNoVersionVectors(bool val)221 void setNoVersionVectors(bool val) { mNoVersionVectors = val; } getNoVersionVectors()222 bool getNoVersionVectors() const { return mNoVersionVectors; } setNoVersionTransitions(bool val)223 void setNoVersionTransitions(bool val) { mNoVersionTransitions = val; } getNoVersionTransitions()224 bool getNoVersionTransitions() const { return mNoVersionTransitions; } 225 226 /* 227 * Set and get the file specification. 228 * 229 * Note this does NOT make a copy of argv. 230 */ setFileSpec(char * const argv[],int argc)231 void setFileSpec(char* const argv[], int argc) { 232 mArgc = argc; 233 mArgv = argv; 234 } getFileSpecCount(void)235 int getFileSpecCount(void) const { return mArgc; } getFileSpecEntry(int idx)236 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; } eatArgs(int n)237 void eatArgs(int n) { 238 if (n > mArgc) n = mArgc; 239 mArgv += n; 240 mArgc -= n; 241 } 242 243 #if 0 244 /* 245 * Package count. Nothing to do with anything else here; this is 246 * just a convenient place to stuff it so we don't have to pass it 247 * around everywhere. 248 */ 249 int getPackageCount(void) const { return mPackageCount; } 250 void setPackageCount(int val) { mPackageCount = val; } 251 #endif 252 253 /* Certain features may only be available on a specific SDK level or 254 * above. SDK levels that have a non-numeric identifier are assumed 255 * to be newer than any SDK level that has a number designated. 256 */ isMinSdkAtLeast(int desired)257 bool isMinSdkAtLeast(int desired) const { 258 /* If the application specifies a minSdkVersion in the manifest 259 * then use that. Otherwise, check what the user specified on 260 * the command line. If neither, it's not available since 261 * the minimum SDK version is assumed to be 1. 262 */ 263 const char *minVer; 264 if (mManifestMinSdkVersion != NULL) { 265 minVer = mManifestMinSdkVersion; 266 } else if (mMinSdkVersion != NULL) { 267 minVer = mMinSdkVersion; 268 } else { 269 return false; 270 } 271 272 char *end; 273 int minSdkNum = (int)strtol(minVer, &end, 0); 274 if (*end == '\0') { 275 if (minSdkNum < desired) { 276 return false; 277 } 278 } 279 return true; 280 } 281 282 private: 283 /* commands & modifiers */ 284 Command mCmd; 285 bool mVerbose; 286 bool mAndroidList; 287 bool mForce; 288 int mGrayscaleTolerance; 289 bool mMakePackageDirs; 290 bool mUpdate; 291 bool mExtending; 292 bool mRequireLocalization; 293 short mPseudolocalize; 294 bool mWantUTF16; 295 bool mValues; 296 bool mIncludeMetaData; 297 int mCompressionMethod; 298 bool mJunkPath; 299 const char* mOutputAPKFile; 300 const char* mManifestPackageNameOverride; 301 const char* mInstrumentationPackageNameOverride; 302 bool mAutoAddOverlay; 303 bool mGenDependencies; 304 bool mNoVersionVectors; 305 bool mNoVersionTransitions; 306 const char* mCrunchedOutputDir; 307 const char* mProguardFile; 308 const char* mMainDexProguardFile; 309 const char* mAndroidManifestFile; 310 const char* mPublicOutputFile; 311 const char* mRClassDir; 312 const char* mResourceIntermediatesDir; 313 android::String8 mConfigurations; 314 android::String8 mPreferredDensity; 315 android::Vector<android::String8> mPartialConfigurations; 316 android::Vector<android::String8> mPackageIncludes; 317 android::Vector<const char*> mJarFiles; 318 android::Vector<const char*> mNoCompressExtensions; 319 android::Vector<const char*> mAssetSourceDirs; 320 android::Vector<const char*> mResourceSourceDirs; 321 322 android::String8 mFeatureOfPackage; 323 android::String8 mFeatureAfterPackage; 324 android::String8 mRevisionCode; 325 const char* mManifestMinSdkVersion; 326 const char* mMinSdkVersion; 327 const char* mTargetSdkVersion; 328 const char* mMaxSdkVersion; 329 const char* mVersionCode; 330 const char* mVersionName; 331 bool mReplaceVersion; 332 const char* mCustomPackage; 333 const char* mExtraPackages; 334 const char* mMaxResVersion; 335 bool mDebugMode; 336 bool mNonConstantId; 337 bool mSkipSymbolsWithoutDefaultLocalization; 338 const char* mProduct; 339 bool mUseCrunchCache; 340 bool mErrorOnFailedInsert; 341 bool mErrorOnMissingConfigEntry; 342 const char* mOutputTextSymbols; 343 const char* mSingleCrunchInputFile; 344 const char* mSingleCrunchOutputFile; 345 bool mBuildSharedLibrary; 346 bool mBuildAppAsSharedLibrary; 347 android::String8 mPlatformVersionCode; 348 android::String8 mPlatformVersionName; 349 android::String8 mPrivateSymbolsPackage; 350 351 /* file specification */ 352 int mArgc; 353 char* const* mArgv; 354 355 #if 0 356 /* misc stuff */ 357 int mPackageCount; 358 #endif 359 360 }; 361 362 #endif // __BUNDLE_H 363