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