blob: ceb52a07103b5de9668504f23f8d889886d080d2 [file] [log] [blame]
Adam Lesinski282e1812014-01-23 18:17:42 -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>
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
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
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,
40 kCommandCrunch,
41 kCommandSingleCrunch,
42} 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/*
Adam Lesinski282e1812014-01-23 18:17:42 -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),
Adam Lesinski282e1812014-01-23 18:17:42 -080063 mWantUTF16(false), mValues(false), mIncludeMetaData(false),
64 mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
65 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
66 mAutoAddOverlay(false), mGenDependencies(false),
Adam Lesinski282e1812014-01-23 18:17:42 -080067 mCrunchedOutputDir(NULL), mProguardFile(NULL),
68 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
69 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
70 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
Jeff Davidsondf08d1c2014-02-25 12:28:08 -080071 mVersionCode(NULL), mVersionName(NULL), mReplaceVersion(false), mCustomPackage(NULL),
72 mExtraPackages(NULL), mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false),
73 mProduct(NULL), mUseCrunchCache(false), mErrorOnFailedInsert(false),
74 mErrorOnMissingConfigEntry(false), mOutputTextSymbols(NULL),
Adam Lesinski282e1812014-01-23 18:17:42 -080075 mSingleCrunchInputFile(NULL), mSingleCrunchOutputFile(NULL),
Adam Lesinskide898ff2014-01-29 18:20:45 -080076 mBuildSharedLibrary(false),
Adam Lesinski282e1812014-01-23 18:17:42 -080077 mArgc(0), mArgv(NULL)
78 {}
79 ~Bundle(void) {}
80
81 /*
82 * Set the command value. Returns "false" if it was previously set.
83 */
84 Command getCommand(void) const { return mCmd; }
85 void setCommand(Command cmd) { mCmd = cmd; }
86
87 /*
88 * Command modifiers. Not all modifiers are appropriate for all
89 * commands.
90 */
91 bool getVerbose(void) const { return mVerbose; }
92 void setVerbose(bool val) { mVerbose = val; }
93 bool getAndroidList(void) const { return mAndroidList; }
94 void setAndroidList(bool val) { mAndroidList = val; }
95 bool getForce(void) const { return mForce; }
96 void setForce(bool val) { mForce = val; }
97 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
98 int getGrayscaleTolerance() const { return mGrayscaleTolerance; }
99 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
100 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
101 bool getUpdate(void) const { return mUpdate; }
102 void setUpdate(bool val) { mUpdate = val; }
103 bool getExtending(void) const { return mExtending; }
104 void setExtending(bool val) { mExtending = val; }
105 bool getRequireLocalization(void) const { return mRequireLocalization; }
106 void setRequireLocalization(bool val) { mRequireLocalization = val; }
Anton Krumina2ef5c02014-03-12 14:46:44 -0700107 short getPseudolocalize(void) const { return mPseudolocalize; }
108 void setPseudolocalize(short val) { mPseudolocalize = val; }
Adam Lesinski282e1812014-01-23 18:17:42 -0800109 void setWantUTF16(bool val) { mWantUTF16 = val; }
110 bool getValues(void) const { return mValues; }
111 void setValues(bool val) { mValues = val; }
112 bool getIncludeMetaData(void) const { return mIncludeMetaData; }
113 void setIncludeMetaData(bool val) { mIncludeMetaData = val; }
114 int getCompressionMethod(void) const { return mCompressionMethod; }
115 void setCompressionMethod(int val) { mCompressionMethod = val; }
116 bool getJunkPath(void) const { return mJunkPath; }
117 void setJunkPath(bool val) { mJunkPath = val; }
118 const char* getOutputAPKFile() const { return mOutputAPKFile; }
119 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
120 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
121 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
122 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
123 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
124 bool getAutoAddOverlay() { return mAutoAddOverlay; }
125 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
126 bool getGenDependencies() { return mGenDependencies; }
127 void setGenDependencies(bool val) { mGenDependencies = val; }
128 bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
129 void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
Ying Wangcd28bd32013-11-14 17:12:10 -0800130 bool getErrorOnMissingConfigEntry() { return mErrorOnMissingConfigEntry; }
131 void setErrorOnMissingConfigEntry(bool val) { mErrorOnMissingConfigEntry = val; }
Adam Lesinski282e1812014-01-23 18:17:42 -0800132
133 bool getUTF16StringsOption() {
134 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
135 }
136
137 /*
138 * Input options.
139 */
Adam Lesinski09384302014-01-22 16:07:42 -0800140 const android::Vector<const char*>& getAssetSourceDirs() const { return mAssetSourceDirs; }
141 void addAssetSourceDir(const char* dir) { mAssetSourceDirs.insertAt(dir,0); }
Adam Lesinski282e1812014-01-23 18:17:42 -0800142 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
143 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
144 const char* getProguardFile() const { return mProguardFile; }
145 void setProguardFile(const char* file) { mProguardFile = file; }
146 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
147 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
148 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
149 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
150 const char* getPublicOutputFile() const { return mPublicOutputFile; }
151 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
152 const char* getRClassDir() const { return mRClassDir; }
153 void setRClassDir(const char* dir) { mRClassDir = dir; }
Adam Lesinskifab50872014-04-16 14:40:42 -0700154 const android::String8& getConfigurations() const { return mConfigurations; }
Adam Lesinski282e1812014-01-23 18:17:42 -0800155 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
Adam Lesinskifab50872014-04-16 14:40:42 -0700156 const android::String8& getPreferredDensity() const { return mPreferredDensity; }
157 void setPreferredDensity(const char* val) { mPreferredDensity = val; }
158 void addSplitConfigurations(const char* val) { mPartialConfigurations.add(android::String8(val)); }
159 const android::Vector<android::String8>& getSplitConfigurations() const { return mPartialConfigurations; }
Adam Lesinski282e1812014-01-23 18:17:42 -0800160 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
161 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
162 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
163 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
164 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
165 void addJarFile(const char* file) { mJarFiles.add(file); }
166 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
167 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
168
169 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
170 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
171 const char* getMinSdkVersion() const { return mMinSdkVersion; }
172 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
173 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
174 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
175 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
176 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
177 const char* getVersionCode() const { return mVersionCode; }
178 void setVersionCode(const char* val) { mVersionCode = val; }
179 const char* getVersionName() const { return mVersionName; }
180 void setVersionName(const char* val) { mVersionName = val; }
Jeff Davidsondf08d1c2014-02-25 12:28:08 -0800181 bool getReplaceVersion() { return mReplaceVersion; }
182 void setReplaceVersion(bool val) { mReplaceVersion = val; }
Adam Lesinski282e1812014-01-23 18:17:42 -0800183 const char* getCustomPackage() const { return mCustomPackage; }
184 void setCustomPackage(const char* val) { mCustomPackage = val; }
185 const char* getExtraPackages() const { return mExtraPackages; }
186 void setExtraPackages(const char* val) { mExtraPackages = val; }
187 const char* getMaxResVersion() const { return mMaxResVersion; }
188 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
189 bool getDebugMode() const { return mDebugMode; }
190 void setDebugMode(bool val) { mDebugMode = val; }
191 bool getNonConstantId() const { return mNonConstantId; }
192 void setNonConstantId(bool val) { mNonConstantId = val; }
193 const char* getProduct() const { return mProduct; }
194 void setProduct(const char * val) { mProduct = val; }
195 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
196 bool getUseCrunchCache() const { return mUseCrunchCache; }
197 const char* getOutputTextSymbols() const { return mOutputTextSymbols; }
198 void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; }
199 const char* getSingleCrunchInputFile() const { return mSingleCrunchInputFile; }
200 void setSingleCrunchInputFile(const char* val) { mSingleCrunchInputFile = val; }
201 const char* getSingleCrunchOutputFile() const { return mSingleCrunchOutputFile; }
202 void setSingleCrunchOutputFile(const char* val) { mSingleCrunchOutputFile = val; }
Adam Lesinskide898ff2014-01-29 18:20:45 -0800203 bool getBuildSharedLibrary() const { return mBuildSharedLibrary; }
204 void setBuildSharedLibrary(bool val) { mBuildSharedLibrary = val; }
Adam Lesinski282e1812014-01-23 18:17:42 -0800205
206 /*
207 * Set and get the file specification.
208 *
209 * Note this does NOT make a copy of argv.
210 */
211 void setFileSpec(char* const argv[], int argc) {
212 mArgc = argc;
213 mArgv = argv;
214 }
215 int getFileSpecCount(void) const { return mArgc; }
216 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
217 void eatArgs(int n) {
218 if (n > mArgc) n = mArgc;
219 mArgv += n;
220 mArgc -= n;
221 }
222
223#if 0
224 /*
225 * Package count. Nothing to do with anything else here; this is
226 * just a convenient place to stuff it so we don't have to pass it
227 * around everywhere.
228 */
229 int getPackageCount(void) const { return mPackageCount; }
230 void setPackageCount(int val) { mPackageCount = val; }
231#endif
232
233 /* Certain features may only be available on a specific SDK level or
234 * above. SDK levels that have a non-numeric identifier are assumed
235 * to be newer than any SDK level that has a number designated.
236 */
237 bool isMinSdkAtLeast(int desired) {
238 /* If the application specifies a minSdkVersion in the manifest
239 * then use that. Otherwise, check what the user specified on
240 * the command line. If neither, it's not available since
241 * the minimum SDK version is assumed to be 1.
242 */
243 const char *minVer;
244 if (mManifestMinSdkVersion != NULL) {
245 minVer = mManifestMinSdkVersion;
246 } else if (mMinSdkVersion != NULL) {
247 minVer = mMinSdkVersion;
248 } else {
249 return false;
250 }
251
252 char *end;
253 int minSdkNum = (int)strtol(minVer, &end, 0);
254 if (*end == '\0') {
255 if (minSdkNum < desired) {
256 return false;
257 }
258 }
259 return true;
260 }
261
262private:
263 /* commands & modifiers */
264 Command mCmd;
265 bool mVerbose;
266 bool mAndroidList;
267 bool mForce;
268 int mGrayscaleTolerance;
269 bool mMakePackageDirs;
270 bool mUpdate;
271 bool mExtending;
272 bool mRequireLocalization;
Anton Krumina2ef5c02014-03-12 14:46:44 -0700273 short mPseudolocalize;
Adam Lesinski282e1812014-01-23 18:17:42 -0800274 bool mWantUTF16;
275 bool mValues;
276 bool mIncludeMetaData;
277 int mCompressionMethod;
278 bool mJunkPath;
279 const char* mOutputAPKFile;
280 const char* mManifestPackageNameOverride;
281 const char* mInstrumentationPackageNameOverride;
282 bool mAutoAddOverlay;
283 bool mGenDependencies;
Adam Lesinski282e1812014-01-23 18:17:42 -0800284 const char* mCrunchedOutputDir;
285 const char* mProguardFile;
286 const char* mAndroidManifestFile;
287 const char* mPublicOutputFile;
288 const char* mRClassDir;
289 const char* mResourceIntermediatesDir;
290 android::String8 mConfigurations;
Adam Lesinskifab50872014-04-16 14:40:42 -0700291 android::String8 mPreferredDensity;
292 android::Vector<android::String8> mPartialConfigurations;
Adam Lesinski282e1812014-01-23 18:17:42 -0800293 android::Vector<const char*> mPackageIncludes;
294 android::Vector<const char*> mJarFiles;
295 android::Vector<const char*> mNoCompressExtensions;
Adam Lesinski09384302014-01-22 16:07:42 -0800296 android::Vector<const char*> mAssetSourceDirs;
Adam Lesinski282e1812014-01-23 18:17:42 -0800297 android::Vector<const char*> mResourceSourceDirs;
298
299 const char* mManifestMinSdkVersion;
300 const char* mMinSdkVersion;
301 const char* mTargetSdkVersion;
302 const char* mMaxSdkVersion;
303 const char* mVersionCode;
304 const char* mVersionName;
Jeff Davidsondf08d1c2014-02-25 12:28:08 -0800305 bool mReplaceVersion;
Adam Lesinski282e1812014-01-23 18:17:42 -0800306 const char* mCustomPackage;
307 const char* mExtraPackages;
308 const char* mMaxResVersion;
309 bool mDebugMode;
310 bool mNonConstantId;
311 const char* mProduct;
312 bool mUseCrunchCache;
313 bool mErrorOnFailedInsert;
Ying Wangcd28bd32013-11-14 17:12:10 -0800314 bool mErrorOnMissingConfigEntry;
Adam Lesinski282e1812014-01-23 18:17:42 -0800315 const char* mOutputTextSymbols;
316 const char* mSingleCrunchInputFile;
317 const char* mSingleCrunchOutputFile;
Adam Lesinskide898ff2014-01-29 18:20:45 -0800318 bool mBuildSharedLibrary;
Adam Lesinski282e1812014-01-23 18:17:42 -0800319
320 /* file specification */
321 int mArgc;
322 char* const* mArgv;
323
324#if 0
325 /* misc stuff */
326 int mPackageCount;
327#endif
328
329};
330
331#endif // __BUNDLE_H