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