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           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         {}
     72     ~Bundle(void) {}
     73 
     74     /*
     75      * Set the command value.  Returns "false" if it was previously set.
     76      */
     77     Command getCommand(void) const { return mCmd; }
     78     void setCommand(Command cmd) { mCmd = cmd; }
     79 
     80     /*
     81      * Command modifiers.  Not all modifiers are appropriate for all
     82      * commands.
     83      */
     84     bool getVerbose(void) const { return mVerbose; }
     85     void setVerbose(bool val) { mVerbose = val; }
     86     bool getAndroidList(void) const { return mAndroidList; }
     87     void setAndroidList(bool val) { mAndroidList = val; }
     88     bool getForce(void) const { return mForce; }
     89     void setForce(bool val) { mForce = val; }
     90     void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
     91     int  getGrayscaleTolerance() const { return mGrayscaleTolerance; }
     92     bool getMakePackageDirs(void) const { return mMakePackageDirs; }
     93     void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
     94     bool getUpdate(void) const { return mUpdate; }
     95     void setUpdate(bool val) { mUpdate = val; }
     96     bool getExtending(void) const { return mExtending; }
     97     void setExtending(bool val) { mExtending = val; }
     98     bool getRequireLocalization(void) const { return mRequireLocalization; }
     99     void setRequireLocalization(bool val) { mRequireLocalization = val; }
    100     short getPseudolocalize(void) const { return mPseudolocalize; }
    101     void setPseudolocalize(short val) { mPseudolocalize = val; }
    102     void setWantUTF16(bool val) { mWantUTF16 = val; }
    103     bool getValues(void) const { return mValues; }
    104     void setValues(bool val) { mValues = val; }
    105     bool getIncludeMetaData(void) const { return mIncludeMetaData; }
    106     void setIncludeMetaData(bool val) { mIncludeMetaData = val; }
    107     int getCompressionMethod(void) const { return mCompressionMethod; }
    108     void setCompressionMethod(int val) { mCompressionMethod = val; }
    109     bool getJunkPath(void) const { return mJunkPath; }
    110     void setJunkPath(bool val) { mJunkPath = val; }
    111     const char* getOutputAPKFile() const { return mOutputAPKFile; }
    112     void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
    113     const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
    114     void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
    115     const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
    116     void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
    117     bool getAutoAddOverlay() { return mAutoAddOverlay; }
    118     void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
    119     bool getGenDependencies() { return mGenDependencies; }
    120     void setGenDependencies(bool val) { mGenDependencies = val; }
    121     bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
    122     void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
    123     bool getErrorOnMissingConfigEntry() { return mErrorOnMissingConfigEntry; }
    124     void setErrorOnMissingConfigEntry(bool val) { mErrorOnMissingConfigEntry = val; }
    125     const android::String8& getPlatformBuildVersionCode() { return mPlatformVersionCode; }
    126     void setPlatformBuildVersionCode(const android::String8& code) { mPlatformVersionCode = code; }
    127     const android::String8& getPlatformBuildVersionName() { return mPlatformVersionName; }
    128     void setPlatformBuildVersionName(const android::String8& name) { mPlatformVersionName = name; }
    129 
    130     const android::String8& getPrivateSymbolsPackage() const { return mPrivateSymbolsPackage; }
    131 
    132     void setPrivateSymbolsPackage(const android::String8& package) {
    133         mPrivateSymbolsPackage = package;
    134     }
    135 
    136     bool getUTF16StringsOption() {
    137         return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
    138     }
    139 
    140     /*
    141      * Input options.
    142      */
    143     const android::Vector<const char*>& getAssetSourceDirs() const { return mAssetSourceDirs; }
    144     void addAssetSourceDir(const char* dir) { mAssetSourceDirs.insertAt(dir,0); }
    145     const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
    146     void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
    147     const char* getProguardFile() const { return mProguardFile; }
    148     void setProguardFile(const char* file) { mProguardFile = file; }
    149     const char* getMainDexProguardFile() const { return mMainDexProguardFile; }
    150     void setMainDexProguardFile(const char* file) { mMainDexProguardFile = file; }
    151     const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
    152     void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
    153     const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
    154     void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
    155     const char* getPublicOutputFile() const { return mPublicOutputFile; }
    156     void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
    157     const char* getRClassDir() const { return mRClassDir; }
    158     void setRClassDir(const char* dir) { mRClassDir = dir; }
    159     const android::String8& getConfigurations() const { return mConfigurations; }
    160     void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
    161     const android::String8& getPreferredDensity() const { return mPreferredDensity; }
    162     void setPreferredDensity(const char* val) { mPreferredDensity = val; }
    163     void addSplitConfigurations(const char* val) { mPartialConfigurations.add(android::String8(val)); }
    164     const android::Vector<android::String8>& getSplitConfigurations() const { return mPartialConfigurations; }
    165     const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
    166     void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
    167     const android::Vector<android::String8>& getPackageIncludes() const { return mPackageIncludes; }
    168     void addPackageInclude(const char* file) { mPackageIncludes.add(android::String8(file)); }
    169     const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
    170     void addJarFile(const char* file) { mJarFiles.add(file); }
    171     const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
    172     void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
    173     void setFeatureOfPackage(const char* str) { mFeatureOfPackage = str; }
    174     const android::String8& getFeatureOfPackage() const { return mFeatureOfPackage; }
    175     void setFeatureAfterPackage(const char* str) { mFeatureAfterPackage = str; }
    176     const android::String8& getFeatureAfterPackage() const { return mFeatureAfterPackage; }
    177 
    178     const char*  getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
    179     void setManifestMinSdkVersion(const char*  val) { mManifestMinSdkVersion = val; }
    180     const char*  getMinSdkVersion() const { return mMinSdkVersion; }
    181     void setMinSdkVersion(const char*  val) { mMinSdkVersion = val; }
    182     const char*  getTargetSdkVersion() const { return mTargetSdkVersion; }
    183     void setTargetSdkVersion(const char*  val) { mTargetSdkVersion = val; }
    184     const char*  getMaxSdkVersion() const { return mMaxSdkVersion; }
    185     void setMaxSdkVersion(const char*  val) { mMaxSdkVersion = val; }
    186     const char*  getVersionCode() const { return mVersionCode; }
    187     void setVersionCode(const char*  val) { mVersionCode = val; }
    188     const char* getVersionName() const { return mVersionName; }
    189     void setVersionName(const char* val) { mVersionName = val; }
    190     bool getReplaceVersion() { return mReplaceVersion; }
    191     void setReplaceVersion(bool val) { mReplaceVersion = val; }
    192     const android::String8& getRevisionCode() { return mRevisionCode; }
    193     void setRevisionCode(const char* val) { mRevisionCode = android::String8(val); }
    194     const char* getCustomPackage() const { return mCustomPackage; }
    195     void setCustomPackage(const char* val) { mCustomPackage = val; }
    196     const char* getExtraPackages() const { return mExtraPackages; }
    197     void setExtraPackages(const char* val) { mExtraPackages = val; }
    198     const char* getMaxResVersion() const { return mMaxResVersion; }
    199     void setMaxResVersion(const char * val) { mMaxResVersion = val; }
    200     bool getDebugMode() const { return mDebugMode; }
    201     void setDebugMode(bool val) { mDebugMode = val; }
    202     bool getNonConstantId() const { return mNonConstantId; }
    203     void setNonConstantId(bool val) { mNonConstantId = val; }
    204     bool getSkipSymbolsWithoutDefaultLocalization() const { return mSkipSymbolsWithoutDefaultLocalization; }
    205     void setSkipSymbolsWithoutDefaultLocalization(bool val) { mSkipSymbolsWithoutDefaultLocalization = val; }
    206     const char* getProduct() const { return mProduct; }
    207     void setProduct(const char * val) { mProduct = val; }
    208     void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
    209     bool getUseCrunchCache() const { return mUseCrunchCache; }
    210     const char* getOutputTextSymbols() const { return mOutputTextSymbols; }
    211     void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; }
    212     const char* getSingleCrunchInputFile() const { return mSingleCrunchInputFile; }
    213     void setSingleCrunchInputFile(const char* val) { mSingleCrunchInputFile = val; }
    214     const char* getSingleCrunchOutputFile() const { return mSingleCrunchOutputFile; }
    215     void setSingleCrunchOutputFile(const char* val) { mSingleCrunchOutputFile = val; }
    216     bool getBuildSharedLibrary() const { return mBuildSharedLibrary; }
    217     void setBuildSharedLibrary(bool val) { mBuildSharedLibrary = val; }
    218     bool getBuildAppAsSharedLibrary() const { return mBuildAppAsSharedLibrary; }
    219     void setBuildAppAsSharedLibrary(bool val) { mBuildAppAsSharedLibrary = val; }
    220     void setNoVersionVectors(bool val) { mNoVersionVectors = val; }
    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      */
    228     void setFileSpec(char* const argv[], int argc) {
    229         mArgc = argc;
    230         mArgv = argv;
    231     }
    232     int getFileSpecCount(void) const { return mArgc; }
    233     const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
    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      */
    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