blob: a6f24428dd93a1f727bc01a5a1802f28ef45c252 [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,
Xavier Ducrohetb1f6ad82012-12-21 09:54:02 -080041 kCommandSingleCrunch,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042} Command;
43
44/*
Anton Krumina2ef5c02014-03-12 14:46:44 -070045 * Pseudolocalization methods
46 */
47typedef enum PseudolocalizationMethod {
48 NO_PSEUDOLOCALIZATION = 0,
49 PSEUDO_ACCENTED,
50 PSEUDO_BIDI,
51} PseudolocalizationMethod;
52
53/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 * Bundle of goodies, including everything specified on the command line.
55 */
56class Bundle {
57public:
58 Bundle(void)
59 : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false),
60 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
61 mUpdate(false), mExtending(false),
Anton Krumina2ef5c02014-03-12 14:46:44 -070062 mRequireLocalization(false), mPseudolocalize(NO_PSEUDOLOCALIZATION),
Kenny Root1741cd42010-03-18 12:12:11 -070063 mWantUTF16(false), mValues(false),
Haitao Fengdbcfed92012-06-22 09:20:26 +080064 mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
Dianne Hackbornef05e072010-03-01 17:43:39 -080065 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -070066 mAutoAddOverlay(false), mGenDependencies(false),
Anton Krumina2ef5c02014-03-12 14:46:44 -070067 mAssetSourceDir(NULL),
Josiah Gaskin8a39da82011-06-06 17:00:35 -070068 mCrunchedOutputDir(NULL), mProguardFile(NULL),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
Kenny Root1741cd42010-03-18 12:12:11 -070070 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
Dianne Hackbornfa6baa22009-05-15 18:45:15 -070071 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
Josiah Gaskince89f152011-06-08 19:31:40 -070072 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -080073 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
Xavier Ducrohetf5de6502012-09-11 14:45:22 -070074 mUseCrunchCache(false), mErrorOnFailedInsert(false), mOutputTextSymbols(NULL),
Xavier Ducrohetb1f6ad82012-12-21 09:54:02 -080075 mSingleCrunchInputFile(NULL), mSingleCrunchOutputFile(NULL),
Xavier Ducrohetf5de6502012-09-11 14:45:22 -070076 mArgc(0), mArgv(NULL)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 {}
78 ~Bundle(void) {}
79
80 /*
81 * Set the command value. Returns "false" if it was previously set.
82 */
83 Command getCommand(void) const { return mCmd; }
84 void setCommand(Command cmd) { mCmd = cmd; }
85
86 /*
87 * Command modifiers. Not all modifiers are appropriate for all
88 * commands.
89 */
90 bool getVerbose(void) const { return mVerbose; }
91 void setVerbose(bool val) { mVerbose = val; }
92 bool getAndroidList(void) const { return mAndroidList; }
93 void setAndroidList(bool val) { mAndroidList = val; }
94 bool getForce(void) const { return mForce; }
95 void setForce(bool val) { mForce = val; }
96 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
Jeff Brownc0f73662012-03-16 22:17:41 -070097 int getGrayscaleTolerance() const { return mGrayscaleTolerance; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
99 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
100 bool getUpdate(void) const { return mUpdate; }
101 void setUpdate(bool val) { mUpdate = val; }
102 bool getExtending(void) const { return mExtending; }
103 void setExtending(bool val) { mExtending = val; }
104 bool getRequireLocalization(void) const { return mRequireLocalization; }
105 void setRequireLocalization(bool val) { mRequireLocalization = val; }
Anton Krumina2ef5c02014-03-12 14:46:44 -0700106 short getPseudolocalize(void) const { return mPseudolocalize; }
107 void setPseudolocalize(short val) { mPseudolocalize = val; }
Kenny Root1741cd42010-03-18 12:12:11 -0700108 void setWantUTF16(bool val) { mWantUTF16 = val; }
Dianne Hackborne17086b2009-06-19 15:13:28 -0700109 bool getValues(void) const { return mValues; }
110 void setValues(bool val) { mValues = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 int getCompressionMethod(void) const { return mCompressionMethod; }
112 void setCompressionMethod(int val) { mCompressionMethod = val; }
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700113 bool getJunkPath(void) const { return mJunkPath; }
114 void setJunkPath(bool val) { mJunkPath = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 const char* getOutputAPKFile() const { return mOutputAPKFile; }
116 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -0600117 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
118 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
Dianne Hackbornef05e072010-03-01 17:43:39 -0800119 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
120 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800121 bool getAutoAddOverlay() { return mAutoAddOverlay; }
122 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700123 bool getGenDependencies() { return mGenDependencies; }
124 void setGenDependencies(bool val) { mGenDependencies = val; }
Xavier Ducrohet7714a242012-09-05 17:49:21 -0700125 bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
126 void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127
Dianne Hackborn6c997a92012-01-31 11:27:43 -0800128 bool getUTF16StringsOption() {
129 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
130 }
131
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700132 /*
133 * Input options.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 */
135 const char* getAssetSourceDir() const { return mAssetSourceDir; }
136 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700137 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
138 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
Joe Onorato1553c822009-08-30 13:36:22 -0700139 const char* getProguardFile() const { return mProguardFile; }
140 void setProguardFile(const char* file) { mProguardFile = file; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
142 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
143 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
144 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
145 const char* getPublicOutputFile() const { return mPublicOutputFile; }
146 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
147 const char* getRClassDir() const { return mRClassDir; }
148 void setRClassDir(const char* dir) { mRClassDir = dir; }
149 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
150 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
Dianne Hackborne6b68032011-10-13 16:26:02 -0700151 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; }
152 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 -0800153 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
154 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
155 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
156 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
157 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
158 void addJarFile(const char* file) { mJarFiles.add(file); }
159 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
160 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
161
Kenny Root1741cd42010-03-18 12:12:11 -0700162 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
163 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700164 const char* getMinSdkVersion() const { return mMinSdkVersion; }
Kenny Root1741cd42010-03-18 12:12:11 -0700165 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700166 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
167 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
168 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
169 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
170 const char* getVersionCode() const { return mVersionCode; }
171 void setVersionCode(const char* val) { mVersionCode = val; }
172 const char* getVersionName() const { return mVersionName; }
173 void setVersionName(const char* val) { mVersionName = val; }
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800174 const char* getCustomPackage() const { return mCustomPackage; }
175 void setCustomPackage(const char* val) { mCustomPackage = val; }
Josiah Gaskince89f152011-06-08 19:31:40 -0700176 const char* getExtraPackages() const { return mExtraPackages; }
177 void setExtraPackages(const char* val) { mExtraPackages = val; }
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700178 const char* getMaxResVersion() const { return mMaxResVersion; }
179 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
Jeff Brownc0f73662012-03-16 22:17:41 -0700180 bool getDebugMode() const { return mDebugMode; }
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700181 void setDebugMode(bool val) { mDebugMode = val; }
Jeff Brownc0f73662012-03-16 22:17:41 -0700182 bool getNonConstantId() const { return mNonConstantId; }
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800183 void setNonConstantId(bool val) { mNonConstantId = val; }
Eric Fischer90964042010-09-15 15:59:21 -0700184 const char* getProduct() const { return mProduct; }
185 void setProduct(const char * val) { mProduct = val; }
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700186 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
Jeff Brownc0f73662012-03-16 22:17:41 -0700187 bool getUseCrunchCache() const { return mUseCrunchCache; }
Xavier Ducrohetf5de6502012-09-11 14:45:22 -0700188 const char* getOutputTextSymbols() const { return mOutputTextSymbols; }
189 void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; }
Xavier Ducrohetb1f6ad82012-12-21 09:54:02 -0800190 const char* getSingleCrunchInputFile() const { return mSingleCrunchInputFile; }
191 void setSingleCrunchInputFile(const char* val) { mSingleCrunchInputFile = val; }
192 const char* getSingleCrunchOutputFile() const { return mSingleCrunchOutputFile; }
193 void setSingleCrunchOutputFile(const char* val) { mSingleCrunchOutputFile = val; }
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 /*
196 * Set and get the file specification.
197 *
198 * Note this does NOT make a copy of argv.
199 */
200 void setFileSpec(char* const argv[], int argc) {
201 mArgc = argc;
202 mArgv = argv;
203 }
204 int getFileSpecCount(void) const { return mArgc; }
205 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
206 void eatArgs(int n) {
207 if (n > mArgc) n = mArgc;
208 mArgv += n;
209 mArgc -= n;
210 }
211
212#if 0
213 /*
214 * Package count. Nothing to do with anything else here; this is
215 * just a convenient place to stuff it so we don't have to pass it
216 * around everywhere.
217 */
218 int getPackageCount(void) const { return mPackageCount; }
219 void setPackageCount(int val) { mPackageCount = val; }
220#endif
221
Kenny Rootc9f30882010-03-24 11:55:16 -0700222 /* Certain features may only be available on a specific SDK level or
223 * above. SDK levels that have a non-numeric identifier are assumed
224 * to be newer than any SDK level that has a number designated.
Kenny Root1741cd42010-03-18 12:12:11 -0700225 */
Kenny Rootc9f30882010-03-24 11:55:16 -0700226 bool isMinSdkAtLeast(int desired) {
Kenny Root1741cd42010-03-18 12:12:11 -0700227 /* If the application specifies a minSdkVersion in the manifest
228 * then use that. Otherwise, check what the user specified on
229 * the command line. If neither, it's not available since
230 * the minimum SDK version is assumed to be 1.
231 */
232 const char *minVer;
233 if (mManifestMinSdkVersion != NULL) {
234 minVer = mManifestMinSdkVersion;
235 } else if (mMinSdkVersion != NULL) {
236 minVer = mMinSdkVersion;
237 } else {
238 return false;
239 }
240
241 char *end;
242 int minSdkNum = (int)strtol(minVer, &end, 0);
243 if (*end == '\0') {
Kenny Rootc9f30882010-03-24 11:55:16 -0700244 if (minSdkNum < desired) {
Kenny Root1741cd42010-03-18 12:12:11 -0700245 return false;
246 }
247 }
248 return true;
249 }
250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251private:
252 /* commands & modifiers */
253 Command mCmd;
254 bool mVerbose;
255 bool mAndroidList;
256 bool mForce;
257 int mGrayscaleTolerance;
258 bool mMakePackageDirs;
259 bool mUpdate;
260 bool mExtending;
261 bool mRequireLocalization;
Anton Krumina2ef5c02014-03-12 14:46:44 -0700262 short mPseudolocalize;
Kenny Root1741cd42010-03-18 12:12:11 -0700263 bool mWantUTF16;
Dianne Hackborne17086b2009-06-19 15:13:28 -0700264 bool mValues;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 int mCompressionMethod;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700266 bool mJunkPath;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 const char* mOutputAPKFile;
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -0600268 const char* mManifestPackageNameOverride;
Dianne Hackbornef05e072010-03-01 17:43:39 -0800269 const char* mInstrumentationPackageNameOverride;
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800270 bool mAutoAddOverlay;
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700271 bool mGenDependencies;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 const char* mAssetSourceDir;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700273 const char* mCrunchedOutputDir;
Joe Onorato1553c822009-08-30 13:36:22 -0700274 const char* mProguardFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 const char* mAndroidManifestFile;
276 const char* mPublicOutputFile;
277 const char* mRClassDir;
278 const char* mResourceIntermediatesDir;
279 android::String8 mConfigurations;
Dianne Hackborne6b68032011-10-13 16:26:02 -0700280 android::String8 mPreferredConfigurations;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 android::Vector<const char*> mPackageIncludes;
282 android::Vector<const char*> mJarFiles;
283 android::Vector<const char*> mNoCompressExtensions;
284 android::Vector<const char*> mResourceSourceDirs;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700285
Kenny Root1741cd42010-03-18 12:12:11 -0700286 const char* mManifestMinSdkVersion;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700287 const char* mMinSdkVersion;
288 const char* mTargetSdkVersion;
289 const char* mMaxSdkVersion;
290 const char* mVersionCode;
291 const char* mVersionName;
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800292 const char* mCustomPackage;
Josiah Gaskince89f152011-06-08 19:31:40 -0700293 const char* mExtraPackages;
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700294 const char* mMaxResVersion;
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700295 bool mDebugMode;
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800296 bool mNonConstantId;
Eric Fischer90964042010-09-15 15:59:21 -0700297 const char* mProduct;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700298 bool mUseCrunchCache;
Xavier Ducrohet7714a242012-09-05 17:49:21 -0700299 bool mErrorOnFailedInsert;
Xavier Ducrohetf5de6502012-09-11 14:45:22 -0700300 const char* mOutputTextSymbols;
Xavier Ducrohetb1f6ad82012-12-21 09:54:02 -0800301 const char* mSingleCrunchInputFile;
302 const char* mSingleCrunchOutputFile;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 /* file specification */
305 int mArgc;
306 char* const* mArgv;
307
308#if 0
309 /* misc stuff */
310 int mPackageCount;
311#endif
Kenny Rootb5ef7ee2009-12-10 13:52:53 -0800312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313};
314
315#endif // __BUNDLE_H