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 }; 28 29 /* 30 * Things we can do. 31 */ 32 typedef enum Command { 33 kCommandUnknown = 0, 34 kCommandVersion, 35 kCommandList, 36 kCommandDump, 37 kCommandAdd, 38 kCommandRemove, 39 kCommandPackage, 40 kCommandCrunch, 41 } Command; 42 43 /* 44 * Bundle of goodies, including everything specified on the command line. 45 */ 46 class Bundle { 47 public: Bundle(void)48 Bundle(void) 49 : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false), 50 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false), 51 mUpdate(false), mExtending(false), 52 mRequireLocalization(false), mPseudolocalize(false), 53 mWantUTF16(false), mValues(false), 54 mCompressionMethod(0), mOutputAPKFile(NULL), 55 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL), 56 mIsOverlayPackage(false), 57 mAutoAddOverlay(false), mGenDependencies(false), 58 mAssetSourceDir(NULL), 59 mCrunchedOutputDir(NULL), mProguardFile(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), mCustomPackage(NULL), mExtraPackages(NULL), 64 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL), 65 mUseCrunchCache(false), mArgc(0), mArgv(NULL) 66 {} ~Bundle(void)67 ~Bundle(void) {} 68 69 /* 70 * Set the command value. Returns "false" if it was previously set. 71 */ getCommand(void)72 Command getCommand(void) const { return mCmd; } setCommand(Command cmd)73 void setCommand(Command cmd) { mCmd = cmd; } 74 75 /* 76 * Command modifiers. Not all modifiers are appropriate for all 77 * commands. 78 */ getVerbose(void)79 bool getVerbose(void) const { return mVerbose; } setVerbose(bool val)80 void setVerbose(bool val) { mVerbose = val; } getAndroidList(void)81 bool getAndroidList(void) const { return mAndroidList; } setAndroidList(bool val)82 void setAndroidList(bool val) { mAndroidList = val; } getForce(void)83 bool getForce(void) const { return mForce; } setForce(bool val)84 void setForce(bool val) { mForce = val; } setGrayscaleTolerance(int val)85 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; } getGrayscaleTolerance()86 int getGrayscaleTolerance() const { return mGrayscaleTolerance; } getMakePackageDirs(void)87 bool getMakePackageDirs(void) const { return mMakePackageDirs; } setMakePackageDirs(bool val)88 void setMakePackageDirs(bool val) { mMakePackageDirs = val; } getUpdate(void)89 bool getUpdate(void) const { return mUpdate; } setUpdate(bool val)90 void setUpdate(bool val) { mUpdate = val; } getExtending(void)91 bool getExtending(void) const { return mExtending; } setExtending(bool val)92 void setExtending(bool val) { mExtending = val; } getRequireLocalization(void)93 bool getRequireLocalization(void) const { return mRequireLocalization; } setRequireLocalization(bool val)94 void setRequireLocalization(bool val) { mRequireLocalization = val; } getPseudolocalize(void)95 bool getPseudolocalize(void) const { return mPseudolocalize; } setPseudolocalize(bool val)96 void setPseudolocalize(bool val) { mPseudolocalize = val; } setWantUTF16(bool val)97 void setWantUTF16(bool val) { mWantUTF16 = val; } getValues(void)98 bool getValues(void) const { return mValues; } setValues(bool val)99 void setValues(bool val) { mValues = val; } getCompressionMethod(void)100 int getCompressionMethod(void) const { return mCompressionMethod; } setCompressionMethod(int val)101 void setCompressionMethod(int val) { mCompressionMethod = val; } getJunkPath(void)102 bool getJunkPath(void) const { return mJunkPath; } setJunkPath(bool val)103 void setJunkPath(bool val) { mJunkPath = val; } getOutputAPKFile()104 const char* getOutputAPKFile() const { return mOutputAPKFile; } setOutputAPKFile(const char * val)105 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; } getManifestPackageNameOverride()106 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; } setManifestPackageNameOverride(const char * val)107 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } getInstrumentationPackageNameOverride()108 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; } setInstrumentationPackageNameOverride(const char * val)109 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; } getIsOverlayPackage()110 bool getIsOverlayPackage() const { return mIsOverlayPackage; } setIsOverlayPackage(bool val)111 void setIsOverlayPackage(bool val) { mIsOverlayPackage = val; } getAutoAddOverlay()112 bool getAutoAddOverlay() { return mAutoAddOverlay; } setAutoAddOverlay(bool val)113 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; } getGenDependencies()114 bool getGenDependencies() { return mGenDependencies; } setGenDependencies(bool val)115 void setGenDependencies(bool val) { mGenDependencies = val; } 116 getUTF16StringsOption()117 bool getUTF16StringsOption() { 118 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO); 119 } 120 121 /* 122 * Input options. 123 */ getAssetSourceDir()124 const char* getAssetSourceDir() const { return mAssetSourceDir; } setAssetSourceDir(const char * dir)125 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; } getCrunchedOutputDir()126 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; } setCrunchedOutputDir(const char * dir)127 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; } getProguardFile()128 const char* getProguardFile() const { return mProguardFile; } setProguardFile(const char * file)129 void setProguardFile(const char* file) { mProguardFile = file; } getResourceSourceDirs()130 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; } addResourceSourceDir(const char * dir)131 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); } getAndroidManifestFile()132 const char* getAndroidManifestFile() const { return mAndroidManifestFile; } setAndroidManifestFile(const char * file)133 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; } getPublicOutputFile()134 const char* getPublicOutputFile() const { return mPublicOutputFile; } setPublicOutputFile(const char * file)135 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; } getRClassDir()136 const char* getRClassDir() const { return mRClassDir; } setRClassDir(const char * dir)137 void setRClassDir(const char* dir) { mRClassDir = dir; } getConfigurations()138 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; } addConfigurations(const char * val)139 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } } getPreferredConfigurations()140 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; } addPreferredConfigurations(const char * val)141 void addPreferredConfigurations(const char* val) { if (mPreferredConfigurations.size() > 0) { mPreferredConfigurations.append(","); mPreferredConfigurations.append(val); } else { mPreferredConfigurations = val; } } getResourceIntermediatesDir()142 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; } setResourceIntermediatesDir(const char * dir)143 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; } getPackageIncludes()144 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; } addPackageInclude(const char * file)145 void addPackageInclude(const char* file) { mPackageIncludes.add(file); } getJarFiles()146 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; } addJarFile(const char * file)147 void addJarFile(const char* file) { mJarFiles.add(file); } getNoCompressExtensions()148 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; } addNoCompressExtension(const char * ext)149 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); } 150 getManifestMinSdkVersion()151 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; } setManifestMinSdkVersion(const char * val)152 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; } getMinSdkVersion()153 const char* getMinSdkVersion() const { return mMinSdkVersion; } setMinSdkVersion(const char * val)154 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; } getTargetSdkVersion()155 const char* getTargetSdkVersion() const { return mTargetSdkVersion; } setTargetSdkVersion(const char * val)156 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; } getMaxSdkVersion()157 const char* getMaxSdkVersion() const { return mMaxSdkVersion; } setMaxSdkVersion(const char * val)158 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; } getVersionCode()159 const char* getVersionCode() const { return mVersionCode; } setVersionCode(const char * val)160 void setVersionCode(const char* val) { mVersionCode = val; } getVersionName()161 const char* getVersionName() const { return mVersionName; } setVersionName(const char * val)162 void setVersionName(const char* val) { mVersionName = val; } getCustomPackage()163 const char* getCustomPackage() const { return mCustomPackage; } setCustomPackage(const char * val)164 void setCustomPackage(const char* val) { mCustomPackage = val; } getExtraPackages()165 const char* getExtraPackages() const { return mExtraPackages; } setExtraPackages(const char * val)166 void setExtraPackages(const char* val) { mExtraPackages = val; } getMaxResVersion()167 const char* getMaxResVersion() const { return mMaxResVersion; } setMaxResVersion(const char * val)168 void setMaxResVersion(const char * val) { mMaxResVersion = val; } getDebugMode()169 bool getDebugMode() const { return mDebugMode; } setDebugMode(bool val)170 void setDebugMode(bool val) { mDebugMode = val; } getNonConstantId()171 bool getNonConstantId() const { return mNonConstantId; } setNonConstantId(bool val)172 void setNonConstantId(bool val) { mNonConstantId = val; } getProduct()173 const char* getProduct() const { return mProduct; } setProduct(const char * val)174 void setProduct(const char * val) { mProduct = val; } setUseCrunchCache(bool val)175 void setUseCrunchCache(bool val) { mUseCrunchCache = val; } getUseCrunchCache()176 bool getUseCrunchCache() const { return mUseCrunchCache; } 177 178 /* 179 * Set and get the file specification. 180 * 181 * Note this does NOT make a copy of argv. 182 */ setFileSpec(char * const argv[],int argc)183 void setFileSpec(char* const argv[], int argc) { 184 mArgc = argc; 185 mArgv = argv; 186 } getFileSpecCount(void)187 int getFileSpecCount(void) const { return mArgc; } getFileSpecEntry(int idx)188 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; } eatArgs(int n)189 void eatArgs(int n) { 190 if (n > mArgc) n = mArgc; 191 mArgv += n; 192 mArgc -= n; 193 } 194 195 #if 0 196 /* 197 * Package count. Nothing to do with anything else here; this is 198 * just a convenient place to stuff it so we don't have to pass it 199 * around everywhere. 200 */ 201 int getPackageCount(void) const { return mPackageCount; } 202 void setPackageCount(int val) { mPackageCount = val; } 203 #endif 204 205 /* Certain features may only be available on a specific SDK level or 206 * above. SDK levels that have a non-numeric identifier are assumed 207 * to be newer than any SDK level that has a number designated. 208 */ isMinSdkAtLeast(int desired)209 bool isMinSdkAtLeast(int desired) { 210 /* If the application specifies a minSdkVersion in the manifest 211 * then use that. Otherwise, check what the user specified on 212 * the command line. If neither, it's not available since 213 * the minimum SDK version is assumed to be 1. 214 */ 215 const char *minVer; 216 if (mManifestMinSdkVersion != NULL) { 217 minVer = mManifestMinSdkVersion; 218 } else if (mMinSdkVersion != NULL) { 219 minVer = mMinSdkVersion; 220 } else { 221 return false; 222 } 223 224 char *end; 225 int minSdkNum = (int)strtol(minVer, &end, 0); 226 if (*end == '\0') { 227 if (minSdkNum < desired) { 228 return false; 229 } 230 } 231 return true; 232 } 233 234 private: 235 /* commands & modifiers */ 236 Command mCmd; 237 bool mVerbose; 238 bool mAndroidList; 239 bool mForce; 240 int mGrayscaleTolerance; 241 bool mMakePackageDirs; 242 bool mUpdate; 243 bool mExtending; 244 bool mRequireLocalization; 245 bool mPseudolocalize; 246 bool mWantUTF16; 247 bool mValues; 248 int mCompressionMethod; 249 bool mJunkPath; 250 const char* mOutputAPKFile; 251 const char* mManifestPackageNameOverride; 252 const char* mInstrumentationPackageNameOverride; 253 bool mIsOverlayPackage; 254 bool mAutoAddOverlay; 255 bool mGenDependencies; 256 const char* mAssetSourceDir; 257 const char* mCrunchedOutputDir; 258 const char* mProguardFile; 259 const char* mAndroidManifestFile; 260 const char* mPublicOutputFile; 261 const char* mRClassDir; 262 const char* mResourceIntermediatesDir; 263 android::String8 mConfigurations; 264 android::String8 mPreferredConfigurations; 265 android::Vector<const char*> mPackageIncludes; 266 android::Vector<const char*> mJarFiles; 267 android::Vector<const char*> mNoCompressExtensions; 268 android::Vector<const char*> mResourceSourceDirs; 269 270 const char* mManifestMinSdkVersion; 271 const char* mMinSdkVersion; 272 const char* mTargetSdkVersion; 273 const char* mMaxSdkVersion; 274 const char* mVersionCode; 275 const char* mVersionName; 276 const char* mCustomPackage; 277 const char* mExtraPackages; 278 const char* mMaxResVersion; 279 bool mDebugMode; 280 bool mNonConstantId; 281 const char* mProduct; 282 bool mUseCrunchCache; 283 284 /* file specification */ 285 int mArgc; 286 char* const* mArgv; 287 288 #if 0 289 /* misc stuff */ 290 int mPackageCount; 291 #endif 292 293 }; 294 295 #endif // __BUNDLE_H 296