]>
Commit | Line | Data |
---|---|---|
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> | |
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 | ||
17 | /* | |
18 | * Things we can do. | |
19 | */ | |
20 | typedef enum Command { | |
21 | kCommandUnknown = 0, | |
22 | kCommandVersion, | |
23 | kCommandList, | |
24 | kCommandDump, | |
25 | kCommandAdd, | |
26 | kCommandRemove, | |
27 | kCommandPackage, | |
28 | kCommandCrunch, | |
29 | } Command; | |
30 | ||
31 | /* | |
32 | * Bundle of goodies, including everything specified on the command line. | |
33 | */ | |
34 | class Bundle { | |
35 | public: | |
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), | |
41 | mWantUTF16(false), mValues(false), | |
42 | mCompressionMethod(0), mOutputAPKFile(NULL), | |
43 | mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL), | |
44 | mAutoAddOverlay(false), mGenDependencies(false), | |
45 | mAssetSourceDir(NULL), | |
46 | mCrunchedOutputDir(NULL), mProguardFile(NULL), | |
47 | mAndroidManifestFile(NULL), mPublicOutputFile(NULL), | |
48 | mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL), | |
49 | mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL), | |
50 | mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL), | |
51 | mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL), | |
52 | mUseCrunchCache(false), mArgc(0), mArgv(NULL) | |
53 | {} | |
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; } | |
84 | bool getWantUTF16(void) const { return mWantUTF16; } | |
85 | void setWantUTF16(bool val) { mWantUTF16 = val; } | |
86 | bool getValues(void) const { return mValues; } | |
87 | void setValues(bool val) { mValues = val; } | |
88 | int getCompressionMethod(void) const { return mCompressionMethod; } | |
89 | void setCompressionMethod(int val) { mCompressionMethod = val; } | |
90 | bool getJunkPath(void) const { return mJunkPath; } | |
91 | void setJunkPath(bool val) { mJunkPath = val; } | |
92 | const char* getOutputAPKFile() const { return mOutputAPKFile; } | |
93 | void setOutputAPKFile(const char* val) { mOutputAPKFile = val; } | |
94 | const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; } | |
95 | void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } | |
96 | const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; } | |
97 | void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; } | |
98 | bool getAutoAddOverlay() { return mAutoAddOverlay; } | |
99 | void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; } | |
100 | bool getGenDependencies() { return mGenDependencies; } | |
101 | void setGenDependencies(bool val) { mGenDependencies = val; } | |
102 | ||
103 | /* | |
104 | * Input options. | |
105 | */ | |
106 | const char* getAssetSourceDir() const { return mAssetSourceDir; } | |
107 | void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; } | |
108 | const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; } | |
109 | void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; } | |
110 | const char* getProguardFile() const { return mProguardFile; } | |
111 | void setProguardFile(const char* file) { mProguardFile = file; } | |
112 | 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; } } | |
122 | 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; } } | |
124 | 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 | ||
133 | const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; } | |
134 | void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; } | |
135 | const char* getMinSdkVersion() const { return mMinSdkVersion; } | |
136 | void setMinSdkVersion(const char* val) { mMinSdkVersion = val; } | |
137 | 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; } | |
145 | const char* getCustomPackage() const { return mCustomPackage; } | |
146 | void setCustomPackage(const char* val) { mCustomPackage = val; } | |
147 | const char* getExtraPackages() const { return mExtraPackages; } | |
148 | void setExtraPackages(const char* val) { mExtraPackages = val; } | |
149 | const char* getMaxResVersion() const { return mMaxResVersion; } | |
150 | void setMaxResVersion(const char * val) { mMaxResVersion = val; } | |
151 | bool getDebugMode() { return mDebugMode; } | |
152 | void setDebugMode(bool val) { mDebugMode = val; } | |
153 | bool getNonConstantId() { return mNonConstantId; } | |
154 | void setNonConstantId(bool val) { mNonConstantId = val; } | |
155 | const char* getProduct() const { return mProduct; } | |
156 | void setProduct(const char * val) { mProduct = val; } | |
157 | void setUseCrunchCache(bool val) { mUseCrunchCache = val; } | |
158 | bool getUseCrunchCache() { return mUseCrunchCache; } | |
159 | ||
160 | /* | |
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 | ||
187 | /* 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. | |
190 | */ | |
191 | bool isMinSdkAtLeast(int desired) { | |
192 | /* 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') { | |
209 | if (minSdkNum < desired) { | |
210 | return false; | |
211 | } | |
212 | } | |
213 | return true; | |
214 | } | |
215 | ||
216 | private: | |
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; | |
228 | bool mWantUTF16; | |
229 | bool mValues; | |
230 | int mCompressionMethod; | |
231 | bool mJunkPath; | |
232 | const char* mOutputAPKFile; | |
233 | const char* mManifestPackageNameOverride; | |
234 | const char* mInstrumentationPackageNameOverride; | |
235 | bool mAutoAddOverlay; | |
236 | bool mGenDependencies; | |
237 | const char* mAssetSourceDir; | |
238 | const char* mCrunchedOutputDir; | |
239 | const char* mProguardFile; | |
240 | const char* mAndroidManifestFile; | |
241 | const char* mPublicOutputFile; | |
242 | const char* mRClassDir; | |
243 | const char* mResourceIntermediatesDir; | |
244 | android::String8 mConfigurations; | |
245 | android::String8 mPreferredConfigurations; | |
246 | android::Vector<const char*> mPackageIncludes; | |
247 | android::Vector<const char*> mJarFiles; | |
248 | android::Vector<const char*> mNoCompressExtensions; | |
249 | android::Vector<const char*> mResourceSourceDirs; | |
250 | ||
251 | const char* mManifestMinSdkVersion; | |
252 | const char* mMinSdkVersion; | |
253 | const char* mTargetSdkVersion; | |
254 | const char* mMaxSdkVersion; | |
255 | const char* mVersionCode; | |
256 | const char* mVersionName; | |
257 | const char* mCustomPackage; | |
258 | const char* mExtraPackages; | |
259 | const char* mMaxResVersion; | |
260 | bool mDebugMode; | |
261 | bool mNonConstantId; | |
262 | const char* mProduct; | |
263 | bool mUseCrunchCache; | |
264 | ||
265 | /* file specification */ | |
266 | int mArgc; | |
267 | char* const* mArgv; | |
268 | ||
269 | #if 0 | |
270 | /* misc stuff */ | |
271 | int mPackageCount; | |
272 | #endif | |
273 | ||
274 | }; | |
275 | ||
276 | #endif // __BUNDLE_H |