blob: 7ef495194f535402938c9d37ebe631da8474069c [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
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,
Josiah Gaskin8a39da82011-06-06 17:00:35 -070028 kCommandCrunch,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029} Command;
30
31/*
32 * Bundle of goodies, including everything specified on the command line.
33 */
34class Bundle {
35public:
36 Bundle(void)
37 : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false),
38 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
39 mUpdate(false), mExtending(false),
40 mRequireLocalization(false), mPseudolocalize(false),
Kenny Root1741cd42010-03-18 12:12:11 -070041 mWantUTF16(false), mValues(false),
Haitao Fengdbcfed92012-06-22 09:20:26 +080042 mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
Dianne Hackbornef05e072010-03-01 17:43:39 -080043 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -070044 mAutoAddOverlay(false), mGenDependencies(false),
Josiah Gaskin8a39da82011-06-06 17:00:35 -070045 mAssetSourceDir(NULL),
46 mCrunchedOutputDir(NULL), mProguardFile(NULL),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
Kenny Root1741cd42010-03-18 12:12:11 -070048 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
Dianne Hackbornfa6baa22009-05-15 18:45:15 -070049 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
Josiah Gaskince89f152011-06-08 19:31:40 -070050 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -080051 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
Josiah Gaskin8a39da82011-06-06 17:00:35 -070052 mUseCrunchCache(false), mArgc(0), mArgv(NULL)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 {}
54 ~Bundle(void) {}
55
56 /*
57 * Set the command value. Returns "false" if it was previously set.
58 */
59 Command getCommand(void) const { return mCmd; }
60 void setCommand(Command cmd) { mCmd = cmd; }
61
62 /*
63 * Command modifiers. Not all modifiers are appropriate for all
64 * commands.
65 */
66 bool getVerbose(void) const { return mVerbose; }
67 void setVerbose(bool val) { mVerbose = val; }
68 bool getAndroidList(void) const { return mAndroidList; }
69 void setAndroidList(bool val) { mAndroidList = val; }
70 bool getForce(void) const { return mForce; }
71 void setForce(bool val) { mForce = val; }
72 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
73 int getGrayscaleTolerance() { return mGrayscaleTolerance; }
74 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
75 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
76 bool getUpdate(void) const { return mUpdate; }
77 void setUpdate(bool val) { mUpdate = val; }
78 bool getExtending(void) const { return mExtending; }
79 void setExtending(bool val) { mExtending = val; }
80 bool getRequireLocalization(void) const { return mRequireLocalization; }
81 void setRequireLocalization(bool val) { mRequireLocalization = val; }
82 bool getPseudolocalize(void) const { return mPseudolocalize; }
83 void setPseudolocalize(bool val) { mPseudolocalize = val; }
Kenny Root1741cd42010-03-18 12:12:11 -070084 bool getWantUTF16(void) const { return mWantUTF16; }
85 void setWantUTF16(bool val) { mWantUTF16 = val; }
Dianne Hackborne17086b2009-06-19 15:13:28 -070086 bool getValues(void) const { return mValues; }
87 void setValues(bool val) { mValues = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 int getCompressionMethod(void) const { return mCompressionMethod; }
89 void setCompressionMethod(int val) { mCompressionMethod = val; }
Doug Zongkerdbe7a682009-10-09 11:24:51 -070090 bool getJunkPath(void) const { return mJunkPath; }
91 void setJunkPath(bool val) { mJunkPath = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 const char* getOutputAPKFile() const { return mOutputAPKFile; }
93 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -060094 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
95 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
Dianne Hackbornef05e072010-03-01 17:43:39 -080096 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
97 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
Xavier Ducrohet99080c72010-02-04 18:45:31 -080098 bool getAutoAddOverlay() { return mAutoAddOverlay; }
99 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700100 bool getGenDependencies() { return mGenDependencies; }
101 void setGenDependencies(bool val) { mGenDependencies = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700103 /*
104 * Input options.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 */
106 const char* getAssetSourceDir() const { return mAssetSourceDir; }
107 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700108 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
109 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
Joe Onorato1553c822009-08-30 13:36:22 -0700110 const char* getProguardFile() const { return mProguardFile; }
111 void setProguardFile(const char* file) { mProguardFile = file; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
113 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
114 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
115 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
116 const char* getPublicOutputFile() const { return mPublicOutputFile; }
117 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
118 const char* getRClassDir() const { return mRClassDir; }
119 void setRClassDir(const char* dir) { mRClassDir = dir; }
120 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
121 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
Dianne Hackborne6b68032011-10-13 16:26:02 -0700122 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; }
123 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 -0800124 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
125 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
126 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
127 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
128 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
129 void addJarFile(const char* file) { mJarFiles.add(file); }
130 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
131 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
132
Kenny Root1741cd42010-03-18 12:12:11 -0700133 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
134 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700135 const char* getMinSdkVersion() const { return mMinSdkVersion; }
Kenny Root1741cd42010-03-18 12:12:11 -0700136 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700137 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
138 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
139 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
140 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
141 const char* getVersionCode() const { return mVersionCode; }
142 void setVersionCode(const char* val) { mVersionCode = val; }
143 const char* getVersionName() const { return mVersionName; }
144 void setVersionName(const char* val) { mVersionName = val; }
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800145 const char* getCustomPackage() const { return mCustomPackage; }
146 void setCustomPackage(const char* val) { mCustomPackage = val; }
Josiah Gaskince89f152011-06-08 19:31:40 -0700147 const char* getExtraPackages() const { return mExtraPackages; }
148 void setExtraPackages(const char* val) { mExtraPackages = val; }
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700149 const char* getMaxResVersion() const { return mMaxResVersion; }
150 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700151 bool getDebugMode() { return mDebugMode; }
152 void setDebugMode(bool val) { mDebugMode = val; }
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800153 bool getNonConstantId() { return mNonConstantId; }
154 void setNonConstantId(bool val) { mNonConstantId = val; }
Eric Fischer90964042010-09-15 15:59:21 -0700155 const char* getProduct() const { return mProduct; }
156 void setProduct(const char * val) { mProduct = val; }
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700157 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
158 bool getUseCrunchCache() { return mUseCrunchCache; }
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 /*
161 * Set and get the file specification.
162 *
163 * Note this does NOT make a copy of argv.
164 */
165 void setFileSpec(char* const argv[], int argc) {
166 mArgc = argc;
167 mArgv = argv;
168 }
169 int getFileSpecCount(void) const { return mArgc; }
170 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
171 void eatArgs(int n) {
172 if (n > mArgc) n = mArgc;
173 mArgv += n;
174 mArgc -= n;
175 }
176
177#if 0
178 /*
179 * Package count. Nothing to do with anything else here; this is
180 * just a convenient place to stuff it so we don't have to pass it
181 * around everywhere.
182 */
183 int getPackageCount(void) const { return mPackageCount; }
184 void setPackageCount(int val) { mPackageCount = val; }
185#endif
186
Kenny Rootc9f30882010-03-24 11:55:16 -0700187 /* Certain features may only be available on a specific SDK level or
188 * above. SDK levels that have a non-numeric identifier are assumed
189 * to be newer than any SDK level that has a number designated.
Kenny Root1741cd42010-03-18 12:12:11 -0700190 */
Kenny Rootc9f30882010-03-24 11:55:16 -0700191 bool isMinSdkAtLeast(int desired) {
Kenny Root1741cd42010-03-18 12:12:11 -0700192 /* If the application specifies a minSdkVersion in the manifest
193 * then use that. Otherwise, check what the user specified on
194 * the command line. If neither, it's not available since
195 * the minimum SDK version is assumed to be 1.
196 */
197 const char *minVer;
198 if (mManifestMinSdkVersion != NULL) {
199 minVer = mManifestMinSdkVersion;
200 } else if (mMinSdkVersion != NULL) {
201 minVer = mMinSdkVersion;
202 } else {
203 return false;
204 }
205
206 char *end;
207 int minSdkNum = (int)strtol(minVer, &end, 0);
208 if (*end == '\0') {
Kenny Rootc9f30882010-03-24 11:55:16 -0700209 if (minSdkNum < desired) {
Kenny Root1741cd42010-03-18 12:12:11 -0700210 return false;
211 }
212 }
213 return true;
214 }
215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216private:
217 /* commands & modifiers */
218 Command mCmd;
219 bool mVerbose;
220 bool mAndroidList;
221 bool mForce;
222 int mGrayscaleTolerance;
223 bool mMakePackageDirs;
224 bool mUpdate;
225 bool mExtending;
226 bool mRequireLocalization;
227 bool mPseudolocalize;
Kenny Root1741cd42010-03-18 12:12:11 -0700228 bool mWantUTF16;
Dianne Hackborne17086b2009-06-19 15:13:28 -0700229 bool mValues;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 int mCompressionMethod;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700231 bool mJunkPath;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 const char* mOutputAPKFile;
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -0600233 const char* mManifestPackageNameOverride;
Dianne Hackbornef05e072010-03-01 17:43:39 -0800234 const char* mInstrumentationPackageNameOverride;
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800235 bool mAutoAddOverlay;
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700236 bool mGenDependencies;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 const char* mAssetSourceDir;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700238 const char* mCrunchedOutputDir;
Joe Onorato1553c822009-08-30 13:36:22 -0700239 const char* mProguardFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 const char* mAndroidManifestFile;
241 const char* mPublicOutputFile;
242 const char* mRClassDir;
243 const char* mResourceIntermediatesDir;
244 android::String8 mConfigurations;
Dianne Hackborne6b68032011-10-13 16:26:02 -0700245 android::String8 mPreferredConfigurations;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 android::Vector<const char*> mPackageIncludes;
247 android::Vector<const char*> mJarFiles;
248 android::Vector<const char*> mNoCompressExtensions;
249 android::Vector<const char*> mResourceSourceDirs;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700250
Kenny Root1741cd42010-03-18 12:12:11 -0700251 const char* mManifestMinSdkVersion;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700252 const char* mMinSdkVersion;
253 const char* mTargetSdkVersion;
254 const char* mMaxSdkVersion;
255 const char* mVersionCode;
256 const char* mVersionName;
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800257 const char* mCustomPackage;
Josiah Gaskince89f152011-06-08 19:31:40 -0700258 const char* mExtraPackages;
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700259 const char* mMaxResVersion;
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700260 bool mDebugMode;
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800261 bool mNonConstantId;
Eric Fischer90964042010-09-15 15:59:21 -0700262 const char* mProduct;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700263 bool mUseCrunchCache;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 /* file specification */
266 int mArgc;
267 char* const* mArgv;
268
269#if 0
270 /* misc stuff */
271 int mPackageCount;
272#endif
Kenny Rootb5ef7ee2009-12-10 13:52:53 -0800273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274};
275
276#endif // __BUNDLE_H