Bundle.h revision 1553c82e084ac5763fb393857224145506771b99
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          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),
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 getValues(void) const { return mValues; }
80    void setValues(bool val) { mValues = val; }
81    int getCompressionMethod(void) const { return mCompressionMethod; }
82    void setCompressionMethod(int val) { mCompressionMethod = val; }
83    const char* getOutputAPKFile() const { return mOutputAPKFile; }
84    void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
85
86    /*
87     * Input options.
88     */
89    const char* getAssetSourceDir() const { return mAssetSourceDir; }
90    void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
91    const char* getProguardFile() const { return mProguardFile; }
92    void setProguardFile(const char* file) { mProguardFile = file; }
93    const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
94    void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
95    const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
96    void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
97    const char* getPublicOutputFile() const { return mPublicOutputFile; }
98    void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
99    const char* getRClassDir() const { return mRClassDir; }
100    void setRClassDir(const char* dir) { mRClassDir = dir; }
101    const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
102    void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
103    const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
104    void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
105    const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
106    void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
107    const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
108    void addJarFile(const char* file) { mJarFiles.add(file); }
109    const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
110    void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
111
112    const char*  getMinSdkVersion() const { return mMinSdkVersion; }
113    void setMinSdkVersion(const char*  val) { mMinSdkVersion = val; }
114    const char*  getTargetSdkVersion() const { return mTargetSdkVersion; }
115    void setTargetSdkVersion(const char*  val) { mTargetSdkVersion = val; }
116    const char*  getMaxSdkVersion() const { return mMaxSdkVersion; }
117    void setMaxSdkVersion(const char*  val) { mMaxSdkVersion = val; }
118    const char*  getVersionCode() const { return mVersionCode; }
119    void setVersionCode(const char*  val) { mVersionCode = val; }
120    const char* getVersionName() const { return mVersionName; }
121    void setVersionName(const char* val) { mVersionName = val; }
122
123    /*
124     * Set and get the file specification.
125     *
126     * Note this does NOT make a copy of argv.
127     */
128    void setFileSpec(char* const argv[], int argc) {
129        mArgc = argc;
130        mArgv = argv;
131    }
132    int getFileSpecCount(void) const { return mArgc; }
133    const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
134    void eatArgs(int n) {
135        if (n > mArgc) n = mArgc;
136        mArgv += n;
137        mArgc -= n;
138    }
139
140#if 0
141    /*
142     * Package count.  Nothing to do with anything else here; this is
143     * just a convenient place to stuff it so we don't have to pass it
144     * around everywhere.
145     */
146    int getPackageCount(void) const { return mPackageCount; }
147    void setPackageCount(int val) { mPackageCount = val; }
148#endif
149
150private:
151    /* commands & modifiers */
152    Command     mCmd;
153    bool        mVerbose;
154    bool        mAndroidList;
155    bool        mForce;
156    int         mGrayscaleTolerance;
157    bool        mMakePackageDirs;
158    bool        mUpdate;
159    bool        mExtending;
160    bool        mRequireLocalization;
161    bool        mPseudolocalize;
162    bool        mValues;
163    int         mCompressionMethod;
164    const char* mOutputAPKFile;
165    const char* mAssetSourceDir;
166    const char* mProguardFile;
167    const char* mAndroidManifestFile;
168    const char* mPublicOutputFile;
169    const char* mRClassDir;
170    const char* mResourceIntermediatesDir;
171    android::String8 mConfigurations;
172    android::Vector<const char*> mPackageIncludes;
173    android::Vector<const char*> mJarFiles;
174    android::Vector<const char*> mNoCompressExtensions;
175    android::Vector<const char*> mResourceSourceDirs;
176
177    const char* mMinSdkVersion;
178    const char* mTargetSdkVersion;
179    const char* mMaxSdkVersion;
180    const char* mVersionCode;
181    const char* mVersionName;
182
183    /* file specification */
184    int         mArgc;
185    char* const* mArgv;
186
187#if 0
188    /* misc stuff */
189    int         mPackageCount;
190#endif
191};
192
193#endif // __BUNDLE_H
194