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