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