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