]> git.saurik.com Git - android/aapt.git/blame - Bundle.h
am e92b9706: am 816fd074: (-s ours) am afa4d8bf: (-s ours) am 22d7cf23: Add single...
[android/aapt.git] / Bundle.h
CommitLineData
a534180c
TAOSP
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>
79e5d372
MA
10#include <utils/Log.h>
11#include <utils/threads.h>
12#include <utils/List.h>
13#include <utils/Errors.h>
a534180c
TAOSP
14#include <utils/String8.h>
15#include <utils/Vector.h>
16
4f41c7f7
DH
17enum {
18 SDK_CUPCAKE = 3,
19 SDK_DONUT = 4,
20 SDK_ECLAIR = 5,
21 SDK_ECLAIR_0_1 = 6,
22 SDK_MR1 = 7,
23 SDK_FROYO = 8,
24 SDK_HONEYCOMB_MR2 = 13,
25 SDK_ICE_CREAM_SANDWICH = 14,
26 SDK_ICE_CREAM_SANDWICH_MR1 = 15,
27};
28
a534180c
TAOSP
29/*
30 * Things we can do.
31 */
32typedef enum Command {
33 kCommandUnknown = 0,
34 kCommandVersion,
35 kCommandList,
36 kCommandDump,
37 kCommandAdd,
38 kCommandRemove,
39 kCommandPackage,
dddb1fc7 40 kCommandCrunch,
a534180c
TAOSP
41} Command;
42
43/*
44 * Bundle of goodies, including everything specified on the command line.
45 */
46class Bundle {
47public:
48 Bundle(void)
49 : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false),
50 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
51 mUpdate(false), mExtending(false),
52 mRequireLocalization(false), mPseudolocalize(false),
5af43148 53 mWantUTF16(false), mValues(false),
e64a6a7a 54 mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
af945cf3 55 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
52ffc169 56 mAutoAddOverlay(false), mGenDependencies(false),
dddb1fc7
JG
57 mAssetSourceDir(NULL),
58 mCrunchedOutputDir(NULL), mProguardFile(NULL),
a534180c 59 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
5af43148 60 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
53288885 61 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
bc7b4f40 62 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
54f200b0 63 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
232580c6
XD
64 mUseCrunchCache(false), mErrorOnFailedInsert(false), mOutputTextSymbols(NULL),
65 mArgc(0), mArgv(NULL)
a534180c
TAOSP
66 {}
67 ~Bundle(void) {}
68
69 /*
70 * Set the command value. Returns "false" if it was previously set.
71 */
72 Command getCommand(void) const { return mCmd; }
73 void setCommand(Command cmd) { mCmd = cmd; }
74
75 /*
76 * Command modifiers. Not all modifiers are appropriate for all
77 * commands.
78 */
79 bool getVerbose(void) const { return mVerbose; }
80 void setVerbose(bool val) { mVerbose = val; }
81 bool getAndroidList(void) const { return mAndroidList; }
82 void setAndroidList(bool val) { mAndroidList = val; }
83 bool getForce(void) const { return mForce; }
84 void setForce(bool val) { mForce = val; }
85 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
c5d0eefd 86 int getGrayscaleTolerance() const { return mGrayscaleTolerance; }
a534180c
TAOSP
87 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
88 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
89 bool getUpdate(void) const { return mUpdate; }
90 void setUpdate(bool val) { mUpdate = val; }
91 bool getExtending(void) const { return mExtending; }
92 void setExtending(bool val) { mExtending = val; }
93 bool getRequireLocalization(void) const { return mRequireLocalization; }
94 void setRequireLocalization(bool val) { mRequireLocalization = val; }
95 bool getPseudolocalize(void) const { return mPseudolocalize; }
96 void setPseudolocalize(bool val) { mPseudolocalize = val; }
5af43148 97 void setWantUTF16(bool val) { mWantUTF16 = val; }
7751daa4
DH
98 bool getValues(void) const { return mValues; }
99 void setValues(bool val) { mValues = val; }
a534180c
TAOSP
100 int getCompressionMethod(void) const { return mCompressionMethod; }
101 void setCompressionMethod(int val) { mCompressionMethod = val; }
1e8883fc
DZ
102 bool getJunkPath(void) const { return mJunkPath; }
103 void setJunkPath(bool val) { mJunkPath = val; }
a534180c
TAOSP
104 const char* getOutputAPKFile() const { return mOutputAPKFile; }
105 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
094e8965
JH
106 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
107 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
af945cf3
DH
108 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
109 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
636d3b70
XD
110 bool getAutoAddOverlay() { return mAutoAddOverlay; }
111 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
52ffc169
JG
112 bool getGenDependencies() { return mGenDependencies; }
113 void setGenDependencies(bool val) { mGenDependencies = val; }
3b8c05ce
XD
114 bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
115 void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
a534180c 116
4f41c7f7
DH
117 bool getUTF16StringsOption() {
118 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
119 }
120
1e8883fc
DZ
121 /*
122 * Input options.
a534180c
TAOSP
123 */
124 const char* getAssetSourceDir() const { return mAssetSourceDir; }
125 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
dddb1fc7
JG
126 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
127 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
6648ff78
JO
128 const char* getProguardFile() const { return mProguardFile; }
129 void setProguardFile(const char* file) { mProguardFile = file; }
a534180c
TAOSP
130 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
131 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
132 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
133 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
134 const char* getPublicOutputFile() const { return mPublicOutputFile; }
135 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
136 const char* getRClassDir() const { return mRClassDir; }
137 void setRClassDir(const char* dir) { mRClassDir = dir; }
138 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
139 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
e29f4ada
DH
140 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; }
141 void addPreferredConfigurations(const char* val) { if (mPreferredConfigurations.size() > 0) { mPreferredConfigurations.append(","); mPreferredConfigurations.append(val); } else { mPreferredConfigurations = val; } }
a534180c
TAOSP
142 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
143 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
144 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
145 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
146 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
147 void addJarFile(const char* file) { mJarFiles.add(file); }
148 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
149 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
150
5af43148
KR
151 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
152 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
7e486e33 153 const char* getMinSdkVersion() const { return mMinSdkVersion; }
5af43148 154 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
7e486e33
DH
155 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
156 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
157 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
158 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
159 const char* getVersionCode() const { return mVersionCode; }
160 void setVersionCode(const char* val) { mVersionCode = val; }
161 const char* getVersionName() const { return mVersionName; }
162 void setVersionName(const char* val) { mVersionName = val; }
fa19db5e
XD
163 const char* getCustomPackage() const { return mCustomPackage; }
164 void setCustomPackage(const char* val) { mCustomPackage = val; }
bc7b4f40
JG
165 const char* getExtraPackages() const { return mExtraPackages; }
166 void setExtraPackages(const char* val) { mExtraPackages = val; }
73412e58
FK
167 const char* getMaxResVersion() const { return mMaxResVersion; }
168 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
c5d0eefd 169 bool getDebugMode() const { return mDebugMode; }
f04c74b7 170 void setDebugMode(bool val) { mDebugMode = val; }
c5d0eefd 171 bool getNonConstantId() const { return mNonConstantId; }
54f200b0 172 void setNonConstantId(bool val) { mNonConstantId = val; }
b8ea3a3f
EF
173 const char* getProduct() const { return mProduct; }
174 void setProduct(const char * val) { mProduct = val; }
dddb1fc7 175 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
c5d0eefd 176 bool getUseCrunchCache() const { return mUseCrunchCache; }
232580c6
XD
177 const char* getOutputTextSymbols() const { return mOutputTextSymbols; }
178 void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; }
1e8883fc 179
a534180c
TAOSP
180 /*
181 * Set and get the file specification.
182 *
183 * Note this does NOT make a copy of argv.
184 */
185 void setFileSpec(char* const argv[], int argc) {
186 mArgc = argc;
187 mArgv = argv;
188 }
189 int getFileSpecCount(void) const { return mArgc; }
190 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
191 void eatArgs(int n) {
192 if (n > mArgc) n = mArgc;
193 mArgv += n;
194 mArgc -= n;
195 }
196
197#if 0
198 /*
199 * Package count. Nothing to do with anything else here; this is
200 * just a convenient place to stuff it so we don't have to pass it
201 * around everywhere.
202 */
203 int getPackageCount(void) const { return mPackageCount; }
204 void setPackageCount(int val) { mPackageCount = val; }
205#endif
206
1bad9d29
KR
207 /* Certain features may only be available on a specific SDK level or
208 * above. SDK levels that have a non-numeric identifier are assumed
209 * to be newer than any SDK level that has a number designated.
5af43148 210 */
1bad9d29 211 bool isMinSdkAtLeast(int desired) {
5af43148
KR
212 /* If the application specifies a minSdkVersion in the manifest
213 * then use that. Otherwise, check what the user specified on
214 * the command line. If neither, it's not available since
215 * the minimum SDK version is assumed to be 1.
216 */
217 const char *minVer;
218 if (mManifestMinSdkVersion != NULL) {
219 minVer = mManifestMinSdkVersion;
220 } else if (mMinSdkVersion != NULL) {
221 minVer = mMinSdkVersion;
222 } else {
223 return false;
224 }
225
226 char *end;
227 int minSdkNum = (int)strtol(minVer, &end, 0);
228 if (*end == '\0') {
1bad9d29 229 if (minSdkNum < desired) {
5af43148
KR
230 return false;
231 }
232 }
233 return true;
234 }
235
a534180c
TAOSP
236private:
237 /* commands & modifiers */
238 Command mCmd;
239 bool mVerbose;
240 bool mAndroidList;
241 bool mForce;
242 int mGrayscaleTolerance;
243 bool mMakePackageDirs;
244 bool mUpdate;
245 bool mExtending;
246 bool mRequireLocalization;
247 bool mPseudolocalize;
5af43148 248 bool mWantUTF16;
7751daa4 249 bool mValues;
a534180c 250 int mCompressionMethod;
1e8883fc 251 bool mJunkPath;
a534180c 252 const char* mOutputAPKFile;
094e8965 253 const char* mManifestPackageNameOverride;
af945cf3 254 const char* mInstrumentationPackageNameOverride;
636d3b70 255 bool mAutoAddOverlay;
52ffc169 256 bool mGenDependencies;
a534180c 257 const char* mAssetSourceDir;
dddb1fc7 258 const char* mCrunchedOutputDir;
6648ff78 259 const char* mProguardFile;
a534180c
TAOSP
260 const char* mAndroidManifestFile;
261 const char* mPublicOutputFile;
262 const char* mRClassDir;
263 const char* mResourceIntermediatesDir;
264 android::String8 mConfigurations;
e29f4ada 265 android::String8 mPreferredConfigurations;
a534180c
TAOSP
266 android::Vector<const char*> mPackageIncludes;
267 android::Vector<const char*> mJarFiles;
268 android::Vector<const char*> mNoCompressExtensions;
269 android::Vector<const char*> mResourceSourceDirs;
1e8883fc 270
5af43148 271 const char* mManifestMinSdkVersion;
7e486e33
DH
272 const char* mMinSdkVersion;
273 const char* mTargetSdkVersion;
274 const char* mMaxSdkVersion;
275 const char* mVersionCode;
276 const char* mVersionName;
fa19db5e 277 const char* mCustomPackage;
bc7b4f40 278 const char* mExtraPackages;
73412e58 279 const char* mMaxResVersion;
f04c74b7 280 bool mDebugMode;
54f200b0 281 bool mNonConstantId;
b8ea3a3f 282 const char* mProduct;
dddb1fc7 283 bool mUseCrunchCache;
3b8c05ce 284 bool mErrorOnFailedInsert;
232580c6 285 const char* mOutputTextSymbols;
1e8883fc 286
a534180c
TAOSP
287 /* file specification */
288 int mArgc;
289 char* const* mArgv;
290
291#if 0
292 /* misc stuff */
293 int mPackageCount;
294#endif
7dc0cd41 295
a534180c
TAOSP
296};
297
298#endif // __BUNDLE_H