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