Bundle.h revision 745e17a07c77aa6b347d9e75c99eb3fcb381bc5d
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 */
20typedef 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 */
33class Bundle {
34public:
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          mUTF8(false), mEncodingSpecified(false), mValues(false),
41          mCompressionMethod(0), mOutputAPKFile(NULL),
42          mAssetSourceDir(NULL), mProguardFile(NULL),
43          mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
44          mRClassDir(NULL), mResourceIntermediatesDir(NULL),
45          mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
46          mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL),
47          mArgc(0), mArgv(NULL)
48        {}
49    ~Bundle(void) {}
50
51    /*
52     * Set the command value.  Returns "false" if it was previously set.
53     */
54    Command getCommand(void) const { return mCmd; }
55    void setCommand(Command cmd) { mCmd = cmd; }
56
57    /*
58     * Command modifiers.  Not all modifiers are appropriate for all
59     * commands.
60     */
61    bool getVerbose(void) const { return mVerbose; }
62    void setVerbose(bool val) { mVerbose = val; }
63    bool getAndroidList(void) const { return mAndroidList; }
64    void setAndroidList(bool val) { mAndroidList = val; }
65    bool getForce(void) const { return mForce; }
66    void setForce(bool val) { mForce = val; }
67    void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
68    int  getGrayscaleTolerance() { return mGrayscaleTolerance; }
69    bool getMakePackageDirs(void) const { return mMakePackageDirs; }
70    void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
71    bool getUpdate(void) const { return mUpdate; }
72    void setUpdate(bool val) { mUpdate = val; }
73    bool getExtending(void) const { return mExtending; }
74    void setExtending(bool val) { mExtending = val; }
75    bool getRequireLocalization(void) const { return mRequireLocalization; }
76    void setRequireLocalization(bool val) { mRequireLocalization = val; }
77    bool getPseudolocalize(void) const { return mPseudolocalize; }
78    void setPseudolocalize(bool val) { mPseudolocalize = val; }
79    bool getUTF8(void) const { return mUTF8; }
80    void setUTF8(bool val) { mUTF8 = val; }
81    bool getEncodingSpecified(void) const { return mEncodingSpecified; }
82    void setEncodingSpecified(bool val) { mEncodingSpecified = 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
92    /*
93     * Input options.
94     */
95    const char* getAssetSourceDir() const { return mAssetSourceDir; }
96    void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
97    const char* getProguardFile() const { return mProguardFile; }
98    void setProguardFile(const char* file) { mProguardFile = file; }
99    const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
100    void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
101    const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
102    void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
103    const char* getPublicOutputFile() const { return mPublicOutputFile; }
104    void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
105    const char* getRClassDir() const { return mRClassDir; }
106    void setRClassDir(const char* dir) { mRClassDir = dir; }
107    const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
108    void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
109    const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
110    void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
111    const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
112    void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
113    const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
114    void addJarFile(const char* file) { mJarFiles.add(file); }
115    const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
116    void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
117
118    const char*  getMinSdkVersion() const { return mMinSdkVersion; }
119    void setMinSdkVersion(const char*  val) {
120        mMinSdkVersion = val;
121        if (!mEncodingSpecified) {
122            setUTF8(isUTF8Available());
123        }
124    }
125    const char*  getTargetSdkVersion() const { return mTargetSdkVersion; }
126    void setTargetSdkVersion(const char*  val) { mTargetSdkVersion = val; }
127    const char*  getMaxSdkVersion() const { return mMaxSdkVersion; }
128    void setMaxSdkVersion(const char*  val) { mMaxSdkVersion = val; }
129    const char*  getVersionCode() const { return mVersionCode; }
130    void setVersionCode(const char*  val) { mVersionCode = val; }
131    const char* getVersionName() const { return mVersionName; }
132    void setVersionName(const char* val) { mVersionName = val; }
133    const char* getCustomPackage() const { return mCustomPackage; }
134    void setCustomPackage(const char* val) { mCustomPackage = val; }
135
136    /*
137     * Set and get the file specification.
138     *
139     * Note this does NOT make a copy of argv.
140     */
141    void setFileSpec(char* const argv[], int argc) {
142        mArgc = argc;
143        mArgv = argv;
144    }
145    int getFileSpecCount(void) const { return mArgc; }
146    const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
147    void eatArgs(int n) {
148        if (n > mArgc) n = mArgc;
149        mArgv += n;
150        mArgc -= n;
151    }
152
153#if 0
154    /*
155     * Package count.  Nothing to do with anything else here; this is
156     * just a convenient place to stuff it so we don't have to pass it
157     * around everywhere.
158     */
159    int getPackageCount(void) const { return mPackageCount; }
160    void setPackageCount(int val) { mPackageCount = val; }
161#endif
162
163private:
164    /* commands & modifiers */
165    Command     mCmd;
166    bool        mVerbose;
167    bool        mAndroidList;
168    bool        mForce;
169    int         mGrayscaleTolerance;
170    bool        mMakePackageDirs;
171    bool        mUpdate;
172    bool        mExtending;
173    bool        mRequireLocalization;
174    bool        mPseudolocalize;
175    bool        mUTF8;
176    bool        mEncodingSpecified;
177    bool        mValues;
178    int         mCompressionMethod;
179    bool        mJunkPath;
180    const char* mOutputAPKFile;
181    const char* mAssetSourceDir;
182    const char* mProguardFile;
183    const char* mAndroidManifestFile;
184    const char* mPublicOutputFile;
185    const char* mRClassDir;
186    const char* mResourceIntermediatesDir;
187    android::String8 mConfigurations;
188    android::Vector<const char*> mPackageIncludes;
189    android::Vector<const char*> mJarFiles;
190    android::Vector<const char*> mNoCompressExtensions;
191    android::Vector<const char*> mResourceSourceDirs;
192
193    const char* mMinSdkVersion;
194    const char* mTargetSdkVersion;
195    const char* mMaxSdkVersion;
196    const char* mVersionCode;
197    const char* mVersionName;
198    const char* mCustomPackage;
199
200    /* file specification */
201    int         mArgc;
202    char* const* mArgv;
203
204#if 0
205    /* misc stuff */
206    int         mPackageCount;
207#endif
208
209    /* UTF-8 is only available on APIs 7 or above or
210     * SDK levels that have code names.
211     */
212    bool isUTF8Available() {
213        char *end;
214        int minSdkNum = (int)strtol(mMinSdkVersion, &end, 0);
215        if (*end == '\0') {
216            if (minSdkNum < 7) {
217                return false;
218            }
219        }
220        return true;
221    }
222};
223
224#endif // __BUNDLE_H
225