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