]>
Commit | Line | Data |
---|---|---|
a534180c TAOSP |
1 | // |
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> | |
79e5d372 MA |
10 | #include <utils/Log.h> |
11 | #include <utils/threads.h> | |
12 | #include <utils/List.h> | |
13 | #include <utils/Errors.h> | |
a534180c TAOSP |
14 | #include <utils/String8.h> |
15 | #include <utils/Vector.h> | |
16 | ||
4f41c7f7 DH |
17 | enum { |
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 | ||
a534180c TAOSP |
29 | /* |
30 | * Things we can do. | |
31 | */ | |
32 | typedef enum Command { | |
33 | kCommandUnknown = 0, | |
34 | kCommandVersion, | |
35 | kCommandList, | |
36 | kCommandDump, | |
37 | kCommandAdd, | |
38 | kCommandRemove, | |
39 | kCommandPackage, | |
dddb1fc7 | 40 | kCommandCrunch, |
a534180c TAOSP |
41 | } Command; |
42 | ||
43 | /* | |
44 | * Bundle of goodies, including everything specified on the command line. | |
45 | */ | |
46 | class Bundle { | |
47 | public: | |
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), | |
5af43148 | 53 | mWantUTF16(false), mValues(false), |
e64a6a7a | 54 | mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL), |
af945cf3 | 55 | mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL), |
52ffc169 | 56 | mAutoAddOverlay(false), mGenDependencies(false), |
dddb1fc7 JG |
57 | mAssetSourceDir(NULL), |
58 | mCrunchedOutputDir(NULL), mProguardFile(NULL), | |
a534180c | 59 | mAndroidManifestFile(NULL), mPublicOutputFile(NULL), |
5af43148 | 60 | mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL), |
53288885 | 61 | mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL), |
bc7b4f40 | 62 | mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL), |
54f200b0 | 63 | mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL), |
3b8c05ce | 64 | mUseCrunchCache(false), mErrorOnFailedInsert(false), mArgc(0), mArgv(NULL) |
a534180c TAOSP |
65 | {} |
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; } | |
c5d0eefd | 85 | int getGrayscaleTolerance() const { return mGrayscaleTolerance; } |
a534180c TAOSP |
86 | 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; } | |
5af43148 | 96 | void setWantUTF16(bool val) { mWantUTF16 = val; } |
7751daa4 DH |
97 | bool getValues(void) const { return mValues; } |
98 | void setValues(bool val) { mValues = val; } | |
a534180c TAOSP |
99 | int getCompressionMethod(void) const { return mCompressionMethod; } |
100 | void setCompressionMethod(int val) { mCompressionMethod = val; } | |
1e8883fc DZ |
101 | bool getJunkPath(void) const { return mJunkPath; } |
102 | void setJunkPath(bool val) { mJunkPath = val; } | |
a534180c TAOSP |
103 | const char* getOutputAPKFile() const { return mOutputAPKFile; } |
104 | void setOutputAPKFile(const char* val) { mOutputAPKFile = val; } | |
094e8965 JH |
105 | const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; } |
106 | void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } | |
af945cf3 DH |
107 | const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; } |
108 | void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; } | |
636d3b70 XD |
109 | bool getAutoAddOverlay() { return mAutoAddOverlay; } |
110 | void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; } | |
52ffc169 JG |
111 | bool getGenDependencies() { return mGenDependencies; } |
112 | void setGenDependencies(bool val) { mGenDependencies = val; } | |
3b8c05ce XD |
113 | bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; } |
114 | void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; } | |
a534180c | 115 | |
4f41c7f7 DH |
116 | bool getUTF16StringsOption() { |
117 | return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO); | |
118 | } | |
119 | ||
1e8883fc DZ |
120 | /* |
121 | * Input options. | |
a534180c TAOSP |
122 | */ |
123 | const char* getAssetSourceDir() const { return mAssetSourceDir; } | |
124 | void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; } | |
dddb1fc7 JG |
125 | const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; } |
126 | void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; } | |
6648ff78 JO |
127 | const char* getProguardFile() const { return mProguardFile; } |
128 | void setProguardFile(const char* file) { mProguardFile = file; } | |
a534180c TAOSP |
129 | 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; } } | |
e29f4ada DH |
139 | 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; } } | |
a534180c TAOSP |
141 | 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 | ||
5af43148 KR |
150 | const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; } |
151 | void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; } | |
7e486e33 | 152 | const char* getMinSdkVersion() const { return mMinSdkVersion; } |
5af43148 | 153 | void setMinSdkVersion(const char* val) { mMinSdkVersion = val; } |
7e486e33 DH |
154 | 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; } | |
fa19db5e XD |
162 | const char* getCustomPackage() const { return mCustomPackage; } |
163 | void setCustomPackage(const char* val) { mCustomPackage = val; } | |
bc7b4f40 JG |
164 | const char* getExtraPackages() const { return mExtraPackages; } |
165 | void setExtraPackages(const char* val) { mExtraPackages = val; } | |
73412e58 FK |
166 | const char* getMaxResVersion() const { return mMaxResVersion; } |
167 | void setMaxResVersion(const char * val) { mMaxResVersion = val; } | |
c5d0eefd | 168 | bool getDebugMode() const { return mDebugMode; } |
f04c74b7 | 169 | void setDebugMode(bool val) { mDebugMode = val; } |
c5d0eefd | 170 | bool getNonConstantId() const { return mNonConstantId; } |
54f200b0 | 171 | void setNonConstantId(bool val) { mNonConstantId = val; } |
b8ea3a3f EF |
172 | const char* getProduct() const { return mProduct; } |
173 | void setProduct(const char * val) { mProduct = val; } | |
dddb1fc7 | 174 | void setUseCrunchCache(bool val) { mUseCrunchCache = val; } |
c5d0eefd | 175 | bool getUseCrunchCache() const { return mUseCrunchCache; } |
1e8883fc | 176 | |
a534180c TAOSP |
177 | /* |
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 | ||
1bad9d29 KR |
204 | /* 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. | |
5af43148 | 207 | */ |
1bad9d29 | 208 | bool isMinSdkAtLeast(int desired) { |
5af43148 KR |
209 | /* 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') { | |
1bad9d29 | 226 | if (minSdkNum < desired) { |
5af43148 KR |
227 | return false; |
228 | } | |
229 | } | |
230 | return true; | |
231 | } | |
232 | ||
a534180c TAOSP |
233 | private: |
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; | |
5af43148 | 245 | bool mWantUTF16; |
7751daa4 | 246 | bool mValues; |
a534180c | 247 | int mCompressionMethod; |
1e8883fc | 248 | bool mJunkPath; |
a534180c | 249 | const char* mOutputAPKFile; |
094e8965 | 250 | const char* mManifestPackageNameOverride; |
af945cf3 | 251 | const char* mInstrumentationPackageNameOverride; |
636d3b70 | 252 | bool mAutoAddOverlay; |
52ffc169 | 253 | bool mGenDependencies; |
a534180c | 254 | const char* mAssetSourceDir; |
dddb1fc7 | 255 | const char* mCrunchedOutputDir; |
6648ff78 | 256 | const char* mProguardFile; |
a534180c TAOSP |
257 | const char* mAndroidManifestFile; |
258 | const char* mPublicOutputFile; | |
259 | const char* mRClassDir; | |
260 | const char* mResourceIntermediatesDir; | |
261 | android::String8 mConfigurations; | |
e29f4ada | 262 | android::String8 mPreferredConfigurations; |
a534180c TAOSP |
263 | android::Vector<const char*> mPackageIncludes; |
264 | android::Vector<const char*> mJarFiles; | |
265 | android::Vector<const char*> mNoCompressExtensions; | |
266 | android::Vector<const char*> mResourceSourceDirs; | |
1e8883fc | 267 | |
5af43148 | 268 | const char* mManifestMinSdkVersion; |
7e486e33 DH |
269 | const char* mMinSdkVersion; |
270 | const char* mTargetSdkVersion; | |
271 | const char* mMaxSdkVersion; | |
272 | const char* mVersionCode; | |
273 | const char* mVersionName; | |
fa19db5e | 274 | const char* mCustomPackage; |
bc7b4f40 | 275 | const char* mExtraPackages; |
73412e58 | 276 | const char* mMaxResVersion; |
f04c74b7 | 277 | bool mDebugMode; |
54f200b0 | 278 | bool mNonConstantId; |
b8ea3a3f | 279 | const char* mProduct; |
dddb1fc7 | 280 | bool mUseCrunchCache; |
3b8c05ce | 281 | bool mErrorOnFailedInsert; |
1e8883fc | 282 | |
a534180c TAOSP |
283 | /* file specification */ |
284 | int mArgc; | |
285 | char* const* mArgv; | |
286 | ||
287 | #if 0 | |
288 | /* misc stuff */ | |
289 | int mPackageCount; | |
290 | #endif | |
7dc0cd41 | 291 | |
a534180c TAOSP |
292 | }; |
293 | ||
294 | #endif // __BUNDLE_H |