blob: 2d1060ba23a07cf826242140af9abbaa69dcba3a [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),
Dianne Hackbornef05e072010-03-01 17:43:39 -080042 mCompressionMethod(0), mOutputAPKFile(NULL),
43 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
Mårten Kongstad57f4b772011-03-17 14:13:41 +010044 mIsOverlayPackage(false),
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -070045 mAutoAddOverlay(false), mGenDependencies(false),
Josiah Gaskin8a39da82011-06-06 17:00:35 -070046 mAssetSourceDir(NULL),
47 mCrunchedOutputDir(NULL), mProguardFile(NULL),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
Kenny Root1741cd42010-03-18 12:12:11 -070049 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
Dianne Hackbornfa6baa22009-05-15 18:45:15 -070050 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
Josiah Gaskince89f152011-06-08 19:31:40 -070051 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -080052 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
Josiah Gaskin8a39da82011-06-06 17:00:35 -070053 mUseCrunchCache(false), mArgc(0), mArgv(NULL)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 {}
55 ~Bundle(void) {}
56
57 /*
58 * Set the command value. Returns "false" if it was previously set.
59 */
60 Command getCommand(void) const { return mCmd; }
61 void setCommand(Command cmd) { mCmd = cmd; }
62
63 /*
64 * Command modifiers. Not all modifiers are appropriate for all
65 * commands.
66 */
67 bool getVerbose(void) const { return mVerbose; }
68 void setVerbose(bool val) { mVerbose = val; }
69 bool getAndroidList(void) const { return mAndroidList; }
70 void setAndroidList(bool val) { mAndroidList = val; }
71 bool getForce(void) const { return mForce; }
72 void setForce(bool val) { mForce = val; }
73 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
74 int getGrayscaleTolerance() { return mGrayscaleTolerance; }
75 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
76 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
77 bool getUpdate(void) const { return mUpdate; }
78 void setUpdate(bool val) { mUpdate = val; }
79 bool getExtending(void) const { return mExtending; }
80 void setExtending(bool val) { mExtending = val; }
81 bool getRequireLocalization(void) const { return mRequireLocalization; }
82 void setRequireLocalization(bool val) { mRequireLocalization = val; }
83 bool getPseudolocalize(void) const { return mPseudolocalize; }
84 void setPseudolocalize(bool val) { mPseudolocalize = val; }
Kenny Root1741cd42010-03-18 12:12:11 -070085 bool getWantUTF16(void) const { return mWantUTF16; }
86 void setWantUTF16(bool val) { mWantUTF16 = val; }
Dianne Hackborne17086b2009-06-19 15:13:28 -070087 bool getValues(void) const { return mValues; }
88 void setValues(bool val) { mValues = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 int getCompressionMethod(void) const { return mCompressionMethod; }
90 void setCompressionMethod(int val) { mCompressionMethod = val; }
Doug Zongkerdbe7a682009-10-09 11:24:51 -070091 bool getJunkPath(void) const { return mJunkPath; }
92 void setJunkPath(bool val) { mJunkPath = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 const char* getOutputAPKFile() const { return mOutputAPKFile; }
94 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -060095 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
96 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
Dianne Hackbornef05e072010-03-01 17:43:39 -080097 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
98 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
Mårten Kongstad57f4b772011-03-17 14:13:41 +010099 bool getIsOverlayPackage() const { return mIsOverlayPackage; }
100 void setIsOverlayPackage(bool val) { mIsOverlayPackage = val; }
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800101 bool getAutoAddOverlay() { return mAutoAddOverlay; }
102 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700103 bool getGenDependencies() { return mGenDependencies; }
104 void setGenDependencies(bool val) { mGenDependencies = val; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700106 /*
107 * Input options.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 */
109 const char* getAssetSourceDir() const { return mAssetSourceDir; }
110 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700111 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
112 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
Joe Onorato1553c822009-08-30 13:36:22 -0700113 const char* getProguardFile() const { return mProguardFile; }
114 void setProguardFile(const char* file) { mProguardFile = file; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
116 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
117 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
118 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
119 const char* getPublicOutputFile() const { return mPublicOutputFile; }
120 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
121 const char* getRClassDir() const { return mRClassDir; }
122 void setRClassDir(const char* dir) { mRClassDir = dir; }
123 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
124 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
Dianne Hackborne6b68032011-10-13 16:26:02 -0700125 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; }
126 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 -0800127 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
128 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
129 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
130 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
131 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
132 void addJarFile(const char* file) { mJarFiles.add(file); }
133 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
134 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
135
Kenny Root1741cd42010-03-18 12:12:11 -0700136 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
137 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700138 const char* getMinSdkVersion() const { return mMinSdkVersion; }
Kenny Root1741cd42010-03-18 12:12:11 -0700139 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700140 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
141 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
142 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
143 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
144 const char* getVersionCode() const { return mVersionCode; }
145 void setVersionCode(const char* val) { mVersionCode = val; }
146 const char* getVersionName() const { return mVersionName; }
147 void setVersionName(const char* val) { mVersionName = val; }
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800148 const char* getCustomPackage() const { return mCustomPackage; }
149 void setCustomPackage(const char* val) { mCustomPackage = val; }
Josiah Gaskince89f152011-06-08 19:31:40 -0700150 const char* getExtraPackages() const { return mExtraPackages; }
151 void setExtraPackages(const char* val) { mExtraPackages = val; }
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700152 const char* getMaxResVersion() const { return mMaxResVersion; }
153 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700154 bool getDebugMode() { return mDebugMode; }
155 void setDebugMode(bool val) { mDebugMode = val; }
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800156 bool getNonConstantId() { return mNonConstantId; }
157 void setNonConstantId(bool val) { mNonConstantId = val; }
Eric Fischer90964042010-09-15 15:59:21 -0700158 const char* getProduct() const { return mProduct; }
159 void setProduct(const char * val) { mProduct = val; }
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700160 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
161 bool getUseCrunchCache() { return mUseCrunchCache; }
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 /*
164 * Set and get the file specification.
165 *
166 * Note this does NOT make a copy of argv.
167 */
168 void setFileSpec(char* const argv[], int argc) {
169 mArgc = argc;
170 mArgv = argv;
171 }
172 int getFileSpecCount(void) const { return mArgc; }
173 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
174 void eatArgs(int n) {
175 if (n > mArgc) n = mArgc;
176 mArgv += n;
177 mArgc -= n;
178 }
179
180#if 0
181 /*
182 * Package count. Nothing to do with anything else here; this is
183 * just a convenient place to stuff it so we don't have to pass it
184 * around everywhere.
185 */
186 int getPackageCount(void) const { return mPackageCount; }
187 void setPackageCount(int val) { mPackageCount = val; }
188#endif
189
Kenny Rootc9f30882010-03-24 11:55:16 -0700190 /* Certain features may only be available on a specific SDK level or
191 * above. SDK levels that have a non-numeric identifier are assumed
192 * to be newer than any SDK level that has a number designated.
Kenny Root1741cd42010-03-18 12:12:11 -0700193 */
Kenny Rootc9f30882010-03-24 11:55:16 -0700194 bool isMinSdkAtLeast(int desired) {
Kenny Root1741cd42010-03-18 12:12:11 -0700195 /* If the application specifies a minSdkVersion in the manifest
196 * then use that. Otherwise, check what the user specified on
197 * the command line. If neither, it's not available since
198 * the minimum SDK version is assumed to be 1.
199 */
200 const char *minVer;
201 if (mManifestMinSdkVersion != NULL) {
202 minVer = mManifestMinSdkVersion;
203 } else if (mMinSdkVersion != NULL) {
204 minVer = mMinSdkVersion;
205 } else {
206 return false;
207 }
208
209 char *end;
210 int minSdkNum = (int)strtol(minVer, &end, 0);
211 if (*end == '\0') {
Kenny Rootc9f30882010-03-24 11:55:16 -0700212 if (minSdkNum < desired) {
Kenny Root1741cd42010-03-18 12:12:11 -0700213 return false;
214 }
215 }
216 return true;
217 }
218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219private:
220 /* commands & modifiers */
221 Command mCmd;
222 bool mVerbose;
223 bool mAndroidList;
224 bool mForce;
225 int mGrayscaleTolerance;
226 bool mMakePackageDirs;
227 bool mUpdate;
228 bool mExtending;
229 bool mRequireLocalization;
230 bool mPseudolocalize;
Kenny Root1741cd42010-03-18 12:12:11 -0700231 bool mWantUTF16;
Dianne Hackborne17086b2009-06-19 15:13:28 -0700232 bool mValues;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 int mCompressionMethod;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700234 bool mJunkPath;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 const char* mOutputAPKFile;
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -0600236 const char* mManifestPackageNameOverride;
Dianne Hackbornef05e072010-03-01 17:43:39 -0800237 const char* mInstrumentationPackageNameOverride;
Mårten Kongstad57f4b772011-03-17 14:13:41 +0100238 bool mIsOverlayPackage;
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800239 bool mAutoAddOverlay;
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700240 bool mGenDependencies;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 const char* mAssetSourceDir;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700242 const char* mCrunchedOutputDir;
Joe Onorato1553c822009-08-30 13:36:22 -0700243 const char* mProguardFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 const char* mAndroidManifestFile;
245 const char* mPublicOutputFile;
246 const char* mRClassDir;
247 const char* mResourceIntermediatesDir;
248 android::String8 mConfigurations;
Dianne Hackborne6b68032011-10-13 16:26:02 -0700249 android::String8 mPreferredConfigurations;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 android::Vector<const char*> mPackageIncludes;
251 android::Vector<const char*> mJarFiles;
252 android::Vector<const char*> mNoCompressExtensions;
253 android::Vector<const char*> mResourceSourceDirs;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700254
Kenny Root1741cd42010-03-18 12:12:11 -0700255 const char* mManifestMinSdkVersion;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700256 const char* mMinSdkVersion;
257 const char* mTargetSdkVersion;
258 const char* mMaxSdkVersion;
259 const char* mVersionCode;
260 const char* mVersionName;
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800261 const char* mCustomPackage;
Josiah Gaskince89f152011-06-08 19:31:40 -0700262 const char* mExtraPackages;
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700263 const char* mMaxResVersion;
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700264 bool mDebugMode;
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800265 bool mNonConstantId;
Eric Fischer90964042010-09-15 15:59:21 -0700266 const char* mProduct;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700267 bool mUseCrunchCache;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 /* file specification */
270 int mArgc;
271 char* const* mArgv;
272
273#if 0
274 /* misc stuff */
275 int mPackageCount;
276#endif
Kenny Rootb5ef7ee2009-12-10 13:52:53 -0800277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278};
279
280#endif // __BUNDLE_H