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