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