blob: be0829185897bc2a5308f34b4df8798782cfc358 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001//
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>
Mathias Agopian3b4062e2009-05-31 19:13:00 -070010#include <utils/Log.h>
11#include <utils/threads.h>
12#include <utils/List.h>
13#include <utils/Errors.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080014#include <utils/String8.h>
15#include <utils/Vector.h>
16
Dianne Hackborn6c997a92012-01-31 11:27:43 -080017enum {
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029/*
30 * Things we can do.
31 */
32typedef enum Command {
33 kCommandUnknown = 0,
34 kCommandVersion,
35 kCommandList,
36 kCommandDump,
37 kCommandAdd,
38 kCommandRemove,
39 kCommandPackage,
Josiah Gaskin8a39da82011-06-06 17:00:35 -070040 kCommandCrunch,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041} 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),
Kenny Root1741cd42010-03-18 12:12:11 -070053 mWantUTF16(false), mValues(false),
Haitao Fengdbcfed92012-06-22 09:20:26 +080054 mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
Dianne Hackbornef05e072010-03-01 17:43:39 -080055 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -070056 mAutoAddOverlay(false), mGenDependencies(false),
Josiah Gaskin8a39da82011-06-06 17:00:35 -070057 mAssetSourceDir(NULL),
58 mCrunchedOutputDir(NULL), mProguardFile(NULL),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
Kenny Root1741cd42010-03-18 12:12:11 -070060 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
Dianne Hackbornfa6baa22009-05-15 18:45:15 -070061 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
Josiah Gaskince89f152011-06-08 19:31:40 -070062 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -080063 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
Xavier Ducrohet7714a242012-09-05 17:49:21 -070064 mUseCrunchCache(false), mErrorOnFailedInsert(false), mArgc(0), mArgv(NULL)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 {}
66 ~Bundle(void) {}
67
68 /*
69 * Set the command value. Returns "false" if it was previously set.
70 */
71 Command getCommand(void) const { return mCmd; }
72 void setCommand(Command cmd) { mCmd = cmd; }
73
74 /*
75 * Command modifiers. Not all modifiers are appropriate for all
76 * commands.
77 */
78 bool getVerbose(void) const { return mVerbose; }
79 void setVerbose(bool val) { mVerbose = val; }
80 bool getAndroidList(void) const { return mAndroidList; }
81 void setAndroidList(bool val) { mAndroidList = val; }
82 bool getForce(void) const { return mForce; }
83 void setForce(bool val) { mForce = val; }
84 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
Jeff Brownc0f73662012-03-16 22:17:41 -070085 int getGrayscaleTolerance() const { return mGrayscaleTolerance; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
87 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
88 bool getUpdate(void) const { return mUpdate; }
89 void setUpdate(bool val) { mUpdate = val; }
90 bool getExtending(void) const { return mExtending; }
91 void setExtending(bool val) { mExtending = val; }
92 bool getRequireLocalization(void) const { return mRequireLocalization; }
93 void setRequireLocalization(bool val) { mRequireLocalization = val; }
94 bool getPseudolocalize(void) const { return mPseudolocalize; }
95 void setPseudolocalize(bool val) { mPseudolocalize = val; }
Kenny Root1741cd42010-03-18 12:12:11 -070096 void setWantUTF16(bool val) { mWantUTF16 = val; }
Dianne Hackborne17086b2009-06-19 15:13:28 -070097 bool getValues(void) const { return mValues; }
98 void setValues(bool val) { mValues = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 int getCompressionMethod(void) const { return mCompressionMethod; }
100 void setCompressionMethod(int val) { mCompressionMethod = val; }
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700101 bool getJunkPath(void) const { return mJunkPath; }
102 void setJunkPath(bool val) { mJunkPath = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 const char* getOutputAPKFile() const { return mOutputAPKFile; }
104 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -0600105 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
106 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
Dianne Hackbornef05e072010-03-01 17:43:39 -0800107 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
108 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800109 bool getAutoAddOverlay() { return mAutoAddOverlay; }
110 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700111 bool getGenDependencies() { return mGenDependencies; }
112 void setGenDependencies(bool val) { mGenDependencies = val; }
Xavier Ducrohet7714a242012-09-05 17:49:21 -0700113 bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
114 void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115
Dianne Hackborn6c997a92012-01-31 11:27:43 -0800116 bool getUTF16StringsOption() {
117 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
118 }
119
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700120 /*
121 * Input options.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 */
123 const char* getAssetSourceDir() const { return mAssetSourceDir; }
124 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700125 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
126 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
Joe Onorato1553c822009-08-30 13:36:22 -0700127 const char* getProguardFile() const { return mProguardFile; }
128 void setProguardFile(const char* file) { mProguardFile = file; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
130 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
131 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
132 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
133 const char* getPublicOutputFile() const { return mPublicOutputFile; }
134 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
135 const char* getRClassDir() const { return mRClassDir; }
136 void setRClassDir(const char* dir) { mRClassDir = dir; }
137 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
138 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
Dianne Hackborne6b68032011-10-13 16:26:02 -0700139 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; }
140 void addPreferredConfigurations(const char* val) { if (mPreferredConfigurations.size() > 0) { mPreferredConfigurations.append(","); mPreferredConfigurations.append(val); } else { mPreferredConfigurations = val; } }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
142 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
143 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
144 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
145 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
146 void addJarFile(const char* file) { mJarFiles.add(file); }
147 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
148 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
149
Kenny Root1741cd42010-03-18 12:12:11 -0700150 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
151 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700152 const char* getMinSdkVersion() const { return mMinSdkVersion; }
Kenny Root1741cd42010-03-18 12:12:11 -0700153 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700154 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
155 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
156 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
157 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
158 const char* getVersionCode() const { return mVersionCode; }
159 void setVersionCode(const char* val) { mVersionCode = val; }
160 const char* getVersionName() const { return mVersionName; }
161 void setVersionName(const char* val) { mVersionName = val; }
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800162 const char* getCustomPackage() const { return mCustomPackage; }
163 void setCustomPackage(const char* val) { mCustomPackage = val; }
Josiah Gaskince89f152011-06-08 19:31:40 -0700164 const char* getExtraPackages() const { return mExtraPackages; }
165 void setExtraPackages(const char* val) { mExtraPackages = val; }
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700166 const char* getMaxResVersion() const { return mMaxResVersion; }
167 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
Jeff Brownc0f73662012-03-16 22:17:41 -0700168 bool getDebugMode() const { return mDebugMode; }
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700169 void setDebugMode(bool val) { mDebugMode = val; }
Jeff Brownc0f73662012-03-16 22:17:41 -0700170 bool getNonConstantId() const { return mNonConstantId; }
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800171 void setNonConstantId(bool val) { mNonConstantId = val; }
Eric Fischer90964042010-09-15 15:59:21 -0700172 const char* getProduct() const { return mProduct; }
173 void setProduct(const char * val) { mProduct = val; }
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700174 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
Jeff Brownc0f73662012-03-16 22:17:41 -0700175 bool getUseCrunchCache() const { return mUseCrunchCache; }
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /*
178 * Set and get the file specification.
179 *
180 * Note this does NOT make a copy of argv.
181 */
182 void setFileSpec(char* const argv[], int argc) {
183 mArgc = argc;
184 mArgv = argv;
185 }
186 int getFileSpecCount(void) const { return mArgc; }
187 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
188 void eatArgs(int n) {
189 if (n > mArgc) n = mArgc;
190 mArgv += n;
191 mArgc -= n;
192 }
193
194#if 0
195 /*
196 * Package count. Nothing to do with anything else here; this is
197 * just a convenient place to stuff it so we don't have to pass it
198 * around everywhere.
199 */
200 int getPackageCount(void) const { return mPackageCount; }
201 void setPackageCount(int val) { mPackageCount = val; }
202#endif
203
Kenny Rootc9f30882010-03-24 11:55:16 -0700204 /* Certain features may only be available on a specific SDK level or
205 * above. SDK levels that have a non-numeric identifier are assumed
206 * to be newer than any SDK level that has a number designated.
Kenny Root1741cd42010-03-18 12:12:11 -0700207 */
Kenny Rootc9f30882010-03-24 11:55:16 -0700208 bool isMinSdkAtLeast(int desired) {
Kenny Root1741cd42010-03-18 12:12:11 -0700209 /* If the application specifies a minSdkVersion in the manifest
210 * then use that. Otherwise, check what the user specified on
211 * the command line. If neither, it's not available since
212 * the minimum SDK version is assumed to be 1.
213 */
214 const char *minVer;
215 if (mManifestMinSdkVersion != NULL) {
216 minVer = mManifestMinSdkVersion;
217 } else if (mMinSdkVersion != NULL) {
218 minVer = mMinSdkVersion;
219 } else {
220 return false;
221 }
222
223 char *end;
224 int minSdkNum = (int)strtol(minVer, &end, 0);
225 if (*end == '\0') {
Kenny Rootc9f30882010-03-24 11:55:16 -0700226 if (minSdkNum < desired) {
Kenny Root1741cd42010-03-18 12:12:11 -0700227 return false;
228 }
229 }
230 return true;
231 }
232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233private:
234 /* commands & modifiers */
235 Command mCmd;
236 bool mVerbose;
237 bool mAndroidList;
238 bool mForce;
239 int mGrayscaleTolerance;
240 bool mMakePackageDirs;
241 bool mUpdate;
242 bool mExtending;
243 bool mRequireLocalization;
244 bool mPseudolocalize;
Kenny Root1741cd42010-03-18 12:12:11 -0700245 bool mWantUTF16;
Dianne Hackborne17086b2009-06-19 15:13:28 -0700246 bool mValues;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 int mCompressionMethod;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700248 bool mJunkPath;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 const char* mOutputAPKFile;
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -0600250 const char* mManifestPackageNameOverride;
Dianne Hackbornef05e072010-03-01 17:43:39 -0800251 const char* mInstrumentationPackageNameOverride;
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800252 bool mAutoAddOverlay;
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700253 bool mGenDependencies;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 const char* mAssetSourceDir;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700255 const char* mCrunchedOutputDir;
Joe Onorato1553c822009-08-30 13:36:22 -0700256 const char* mProguardFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 const char* mAndroidManifestFile;
258 const char* mPublicOutputFile;
259 const char* mRClassDir;
260 const char* mResourceIntermediatesDir;
261 android::String8 mConfigurations;
Dianne Hackborne6b68032011-10-13 16:26:02 -0700262 android::String8 mPreferredConfigurations;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 android::Vector<const char*> mPackageIncludes;
264 android::Vector<const char*> mJarFiles;
265 android::Vector<const char*> mNoCompressExtensions;
266 android::Vector<const char*> mResourceSourceDirs;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700267
Kenny Root1741cd42010-03-18 12:12:11 -0700268 const char* mManifestMinSdkVersion;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700269 const char* mMinSdkVersion;
270 const char* mTargetSdkVersion;
271 const char* mMaxSdkVersion;
272 const char* mVersionCode;
273 const char* mVersionName;
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800274 const char* mCustomPackage;
Josiah Gaskince89f152011-06-08 19:31:40 -0700275 const char* mExtraPackages;
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700276 const char* mMaxResVersion;
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700277 bool mDebugMode;
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800278 bool mNonConstantId;
Eric Fischer90964042010-09-15 15:59:21 -0700279 const char* mProduct;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700280 bool mUseCrunchCache;
Xavier Ducrohet7714a242012-09-05 17:49:21 -0700281 bool mErrorOnFailedInsert;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 /* file specification */
284 int mArgc;
285 char* const* mArgv;
286
287#if 0
288 /* misc stuff */
289 int mPackageCount;
290#endif
Kenny Rootb5ef7ee2009-12-10 13:52:53 -0800291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292};
293
294#endif // __BUNDLE_H