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 /*
     18  * Things we can do.
     19  */
     20 typedef enum Command {
     21     kCommandUnknown = 0,
     22     kCommandVersion,
     23     kCommandList,
     24     kCommandDump,
     25     kCommandAdd,
     26     kCommandRemove,
     27     kCommandPackage,
     28 } Command;
     29 
     30 /*
     31  * Bundle of goodies, including everything specified on the command line.
     32  */
     33 class Bundle {
     34 public:
     35     Bundle(void)
     36         : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false),
     37           mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
     38           mUpdate(false), mExtending(false),
     39           mRequireLocalization(false), mPseudolocalize(false),
     40           mWantUTF16(false), mValues(false),
     41           mCompressionMethod(0), mOutputAPKFile(NULL),
     42           mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
     43           mAutoAddOverlay(false), mAssetSourceDir(NULL), mProguardFile(NULL),
     44           mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
     45           mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
     46           mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
     47           mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL),
     48           mMaxResVersion(NULL), mDebugMode(false), mProduct(NULL),
     49           mArgc(0), mArgv(NULL)
     50         {}
     51     ~Bundle(void) {}
     52 
     53     /*
     54      * Set the command value.  Returns "false" if it was previously set.
     55      */
     56     Command getCommand(void) const { return mCmd; }
     57     void setCommand(Command cmd) { mCmd = cmd; }
     58 
     59     /*
     60      * Command modifiers.  Not all modifiers are appropriate for all
     61      * commands.
     62      */
     63     bool getVerbose(void) const { return mVerbose; }
     64     void setVerbose(bool val) { mVerbose = val; }
     65     bool getAndroidList(void) const { return mAndroidList; }
     66     void setAndroidList(bool val) { mAndroidList = val; }
     67     bool getForce(void) const { return mForce; }
     68     void setForce(bool val) { mForce = val; }
     69     void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
     70     int  getGrayscaleTolerance() { return mGrayscaleTolerance; }
     71     bool getMakePackageDirs(void) const { return mMakePackageDirs; }
     72     void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
     73     bool getUpdate(void) const { return mUpdate; }
     74     void setUpdate(bool val) { mUpdate = val; }
     75     bool getExtending(void) const { return mExtending; }
     76     void setExtending(bool val) { mExtending = val; }
     77     bool getRequireLocalization(void) const { return mRequireLocalization; }
     78     void setRequireLocalization(bool val) { mRequireLocalization = val; }
     79     bool getPseudolocalize(void) const { return mPseudolocalize; }
     80     void setPseudolocalize(bool val) { mPseudolocalize = val; }
     81     bool getWantUTF16(void) const { return mWantUTF16; }
     82     void setWantUTF16(bool val) { mWantUTF16 = val; }
     83     bool getValues(void) const { return mValues; }
     84     void setValues(bool val) { mValues = val; }
     85     int getCompressionMethod(void) const { return mCompressionMethod; }
     86     void setCompressionMethod(int val) { mCompressionMethod = val; }
     87     bool getJunkPath(void) const { return mJunkPath; }
     88     void setJunkPath(bool val) { mJunkPath = val; }
     89     const char* getOutputAPKFile() const { return mOutputAPKFile; }
     90     void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
     91     const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
     92     void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
     93     const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
     94     void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
     95     bool getAutoAddOverlay() { return mAutoAddOverlay; }
     96     void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
     97 
     98     /*
     99      * Input options.
    100      */
    101     const char* getAssetSourceDir() const { return mAssetSourceDir; }
    102     void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
    103     const char* getProguardFile() const { return mProguardFile; }
    104     void setProguardFile(const char* file) { mProguardFile = file; }
    105     const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
    106     void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
    107     const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
    108     void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
    109     const char* getPublicOutputFile() const { return mPublicOutputFile; }
    110     void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
    111     const char* getRClassDir() const { return mRClassDir; }
    112     void setRClassDir(const char* dir) { mRClassDir = dir; }
    113     const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
    114     void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
    115     const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
    116     void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
    117     const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
    118     void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
    119     const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
    120     void addJarFile(const char* file) { mJarFiles.add(file); }
    121     const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
    122     void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
    123 
    124     const char*  getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
    125     void setManifestMinSdkVersion(const char*  val) { mManifestMinSdkVersion = val; }
    126     const char*  getMinSdkVersion() const { return mMinSdkVersion; }
    127     void setMinSdkVersion(const char*  val) { mMinSdkVersion = val; }
    128     const char*  getTargetSdkVersion() const { return mTargetSdkVersion; }
    129     void setTargetSdkVersion(const char*  val) { mTargetSdkVersion = val; }
    130     const char*  getMaxSdkVersion() const { return mMaxSdkVersion; }
    131     void setMaxSdkVersion(const char*  val) { mMaxSdkVersion = val; }
    132     const char*  getVersionCode() const { return mVersionCode; }
    133     void setVersionCode(const char*  val) { mVersionCode = val; }
    134     const char* getVersionName() const { return mVersionName; }
    135     void setVersionName(const char* val) { mVersionName = val; }
    136     const char* getCustomPackage() const { return mCustomPackage; }
    137     void setCustomPackage(const char* val) { mCustomPackage = val; }
    138     const char* getMaxResVersion() const { return mMaxResVersion; }
    139     void setMaxResVersion(const char * val) { mMaxResVersion = val; }
    140     bool getDebugMode() { return mDebugMode; }
    141     void setDebugMode(bool val) { mDebugMode = val; }
    142     const char* getProduct() const { return mProduct; }
    143     void setProduct(const char * val) { mProduct = val; }
    144 
    145     /*
    146      * Set and get the file specification.
    147      *
    148      * Note this does NOT make a copy of argv.
    149      */
    150     void setFileSpec(char* const argv[], int argc) {
    151         mArgc = argc;
    152         mArgv = argv;
    153     }
    154     int getFileSpecCount(void) const { return mArgc; }
    155     const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
    156     void eatArgs(int n) {
    157         if (n > mArgc) n = mArgc;
    158         mArgv += n;
    159         mArgc -= n;
    160     }
    161 
    162 #if 0
    163     /*
    164      * Package count.  Nothing to do with anything else here; this is
    165      * just a convenient place to stuff it so we don't have to pass it
    166      * around everywhere.
    167      */
    168     int getPackageCount(void) const { return mPackageCount; }
    169     void setPackageCount(int val) { mPackageCount = val; }
    170 #endif
    171 
    172     /* Certain features may only be available on a specific SDK level or
    173      * above. SDK levels that have a non-numeric identifier are assumed
    174      * to be newer than any SDK level that has a number designated.
    175      */
    176     bool isMinSdkAtLeast(int desired) {
    177         /* If the application specifies a minSdkVersion in the manifest
    178          * then use that. Otherwise, check what the user specified on
    179          * the command line. If neither, it's not available since
    180          * the minimum SDK version is assumed to be 1.
    181          */
    182         const char *minVer;
    183         if (mManifestMinSdkVersion != NULL) {
    184             minVer = mManifestMinSdkVersion;
    185         } else if (mMinSdkVersion != NULL) {
    186             minVer = mMinSdkVersion;
    187         } else {
    188             return false;
    189         }
    190 
    191         char *end;
    192         int minSdkNum = (int)strtol(minVer, &end, 0);
    193         if (*end == '\0') {
    194             if (minSdkNum < desired) {
    195                 return false;
    196             }
    197         }
    198         return true;
    199     }
    200 
    201 private:
    202     /* commands & modifiers */
    203     Command     mCmd;
    204     bool        mVerbose;
    205     bool        mAndroidList;
    206     bool        mForce;
    207     int         mGrayscaleTolerance;
    208     bool        mMakePackageDirs;
    209     bool        mUpdate;
    210     bool        mExtending;
    211     bool        mRequireLocalization;
    212     bool        mPseudolocalize;
    213     bool        mWantUTF16;
    214     bool        mValues;
    215     int         mCompressionMethod;
    216     bool        mJunkPath;
    217     const char* mOutputAPKFile;
    218     const char* mManifestPackageNameOverride;
    219     const char* mInstrumentationPackageNameOverride;
    220     bool        mAutoAddOverlay;
    221     const char* mAssetSourceDir;
    222     const char* mProguardFile;
    223     const char* mAndroidManifestFile;
    224     const char* mPublicOutputFile;
    225     const char* mRClassDir;
    226     const char* mResourceIntermediatesDir;
    227     android::String8 mConfigurations;
    228     android::Vector<const char*> mPackageIncludes;
    229     android::Vector<const char*> mJarFiles;
    230     android::Vector<const char*> mNoCompressExtensions;
    231     android::Vector<const char*> mResourceSourceDirs;
    232 
    233     const char* mManifestMinSdkVersion;
    234     const char* mMinSdkVersion;
    235     const char* mTargetSdkVersion;
    236     const char* mMaxSdkVersion;
    237     const char* mVersionCode;
    238     const char* mVersionName;
    239     const char* mCustomPackage;
    240     const char* mMaxResVersion;
    241     bool        mDebugMode;
    242     const char* mProduct;
    243 
    244     /* file specification */
    245     int         mArgc;
    246     char* const* mArgv;
    247 
    248 #if 0
    249     /* misc stuff */
    250     int         mPackageCount;
    251 #endif
    252 
    253 };
    254 
    255 #endif // __BUNDLE_H
    256