2 // Copyright 2006 The Android Open Source Project
4 // State bundle. Used to pass around stuff like command-line args.
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>
24 SDK_HONEYCOMB_MR2
= 13,
25 SDK_ICE_CREAM_SANDWICH
= 14,
26 SDK_ICE_CREAM_SANDWICH_MR1
= 15,
32 typedef enum Command
{
44 * Bundle of goodies, including everything specified on the command line.
49 : mCmd(kCommandUnknown
), mVerbose(false), mAndroidList(false),
50 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
51 mUpdate(false), mExtending(false),
52 mRequireLocalization(false), mPseudolocalize(false),
53 mWantUTF16(false), mValues(false),
54 mCompressionMethod(0), mOutputAPKFile(NULL
),
55 mManifestPackageNameOverride(NULL
), mInstrumentationPackageNameOverride(NULL
),
56 mAutoAddOverlay(false), mGenDependencies(false),
57 mAssetSourceDir(NULL
),
58 mCrunchedOutputDir(NULL
), mProguardFile(NULL
),
59 mAndroidManifestFile(NULL
), mPublicOutputFile(NULL
),
60 mRClassDir(NULL
), mResourceIntermediatesDir(NULL
), mManifestMinSdkVersion(NULL
),
61 mMinSdkVersion(NULL
), mTargetSdkVersion(NULL
), mMaxSdkVersion(NULL
),
62 mVersionCode(NULL
), mVersionName(NULL
), mCustomPackage(NULL
), mExtraPackages(NULL
),
63 mMaxResVersion(NULL
), mDebugMode(false), mNonConstantId(false), mProduct(NULL
),
64 mUseCrunchCache(false), mArgc(0), mArgv(NULL
)
69 * Set the command value. Returns "false" if it was previously set.
71 Command
getCommand(void) const { return mCmd
; }
72 void setCommand(Command cmd
) { mCmd
= cmd
; }
75 * Command modifiers. Not all modifiers are appropriate for all
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
; }
85 int getGrayscaleTolerance() const { return mGrayscaleTolerance
; }
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
; }
96 void setWantUTF16(bool val
) { mWantUTF16
= val
; }
97 bool getValues(void) const { return mValues
; }
98 void setValues(bool val
) { mValues
= val
; }
99 int getCompressionMethod(void) const { return mCompressionMethod
; }
100 void setCompressionMethod(int val
) { mCompressionMethod
= val
; }
101 bool getJunkPath(void) const { return mJunkPath
; }
102 void setJunkPath(bool val
) { mJunkPath
= val
; }
103 const char* getOutputAPKFile() const { return mOutputAPKFile
; }
104 void setOutputAPKFile(const char* val
) { mOutputAPKFile
= val
; }
105 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride
; }
106 void setManifestPackageNameOverride(const char * val
) { mManifestPackageNameOverride
= val
; }
107 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride
; }
108 void setInstrumentationPackageNameOverride(const char * val
) { mInstrumentationPackageNameOverride
= val
; }
109 bool getAutoAddOverlay() { return mAutoAddOverlay
; }
110 void setAutoAddOverlay(bool val
) { mAutoAddOverlay
= val
; }
111 bool getGenDependencies() { return mGenDependencies
; }
112 void setGenDependencies(bool val
) { mGenDependencies
= val
; }
114 bool getUTF16StringsOption() {
115 return mWantUTF16
|| !isMinSdkAtLeast(SDK_FROYO
);
121 const char* getAssetSourceDir() const { return mAssetSourceDir
; }
122 void setAssetSourceDir(const char* dir
) { mAssetSourceDir
= dir
; }
123 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir
; }
124 void setCrunchedOutputDir(const char* dir
) { mCrunchedOutputDir
= dir
; }
125 const char* getProguardFile() const { return mProguardFile
; }
126 void setProguardFile(const char* file
) { mProguardFile
= file
; }
127 const android::Vector
<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs
; }
128 void addResourceSourceDir(const char* dir
) { mResourceSourceDirs
.insertAt(dir
,0); }
129 const char* getAndroidManifestFile() const { return mAndroidManifestFile
; }
130 void setAndroidManifestFile(const char* file
) { mAndroidManifestFile
= file
; }
131 const char* getPublicOutputFile() const { return mPublicOutputFile
; }
132 void setPublicOutputFile(const char* file
) { mPublicOutputFile
= file
; }
133 const char* getRClassDir() const { return mRClassDir
; }
134 void setRClassDir(const char* dir
) { mRClassDir
= dir
; }
135 const char* getConfigurations() const { return mConfigurations
.size() > 0 ? mConfigurations
.string() : NULL
; }
136 void addConfigurations(const char* val
) { if (mConfigurations
.size() > 0) { mConfigurations
.append(","); mConfigurations
.append(val
); } else { mConfigurations
= val
; } }
137 const char* getPreferredConfigurations() const { return mPreferredConfigurations
.size() > 0 ? mPreferredConfigurations
.string() : NULL
; }
138 void addPreferredConfigurations(const char* val
) { if (mPreferredConfigurations
.size() > 0) { mPreferredConfigurations
.append(","); mPreferredConfigurations
.append(val
); } else { mPreferredConfigurations
= val
; } }
139 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir
; }
140 void setResourceIntermediatesDir(const char* dir
) { mResourceIntermediatesDir
= dir
; }
141 const android::Vector
<const char*>& getPackageIncludes() const { return mPackageIncludes
; }
142 void addPackageInclude(const char* file
) { mPackageIncludes
.add(file
); }
143 const android::Vector
<const char*>& getJarFiles() const { return mJarFiles
; }
144 void addJarFile(const char* file
) { mJarFiles
.add(file
); }
145 const android::Vector
<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions
; }
146 void addNoCompressExtension(const char* ext
) { mNoCompressExtensions
.add(ext
); }
148 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion
; }
149 void setManifestMinSdkVersion(const char* val
) { mManifestMinSdkVersion
= val
; }
150 const char* getMinSdkVersion() const { return mMinSdkVersion
; }
151 void setMinSdkVersion(const char* val
) { mMinSdkVersion
= val
; }
152 const char* getTargetSdkVersion() const { return mTargetSdkVersion
; }
153 void setTargetSdkVersion(const char* val
) { mTargetSdkVersion
= val
; }
154 const char* getMaxSdkVersion() const { return mMaxSdkVersion
; }
155 void setMaxSdkVersion(const char* val
) { mMaxSdkVersion
= val
; }
156 const char* getVersionCode() const { return mVersionCode
; }
157 void setVersionCode(const char* val
) { mVersionCode
= val
; }
158 const char* getVersionName() const { return mVersionName
; }
159 void setVersionName(const char* val
) { mVersionName
= val
; }
160 const char* getCustomPackage() const { return mCustomPackage
; }
161 void setCustomPackage(const char* val
) { mCustomPackage
= val
; }
162 const char* getExtraPackages() const { return mExtraPackages
; }
163 void setExtraPackages(const char* val
) { mExtraPackages
= val
; }
164 const char* getMaxResVersion() const { return mMaxResVersion
; }
165 void setMaxResVersion(const char * val
) { mMaxResVersion
= val
; }
166 bool getDebugMode() const { return mDebugMode
; }
167 void setDebugMode(bool val
) { mDebugMode
= val
; }
168 bool getNonConstantId() const { return mNonConstantId
; }
169 void setNonConstantId(bool val
) { mNonConstantId
= val
; }
170 const char* getProduct() const { return mProduct
; }
171 void setProduct(const char * val
) { mProduct
= val
; }
172 void setUseCrunchCache(bool val
) { mUseCrunchCache
= val
; }
173 bool getUseCrunchCache() const { return mUseCrunchCache
; }
176 * Set and get the file specification.
178 * Note this does NOT make a copy of argv.
180 void setFileSpec(char* const argv
[], int argc
) {
184 int getFileSpecCount(void) const { return mArgc
; }
185 const char* getFileSpecEntry(int idx
) const { return mArgv
[idx
]; }
186 void eatArgs(int n
) {
187 if (n
> mArgc
) n
= mArgc
;
194 * Package count. Nothing to do with anything else here; this is
195 * just a convenient place to stuff it so we don't have to pass it
198 int getPackageCount(void) const { return mPackageCount
; }
199 void setPackageCount(int val
) { mPackageCount
= val
; }
202 /* Certain features may only be available on a specific SDK level or
203 * above. SDK levels that have a non-numeric identifier are assumed
204 * to be newer than any SDK level that has a number designated.
206 bool isMinSdkAtLeast(int desired
) {
207 /* If the application specifies a minSdkVersion in the manifest
208 * then use that. Otherwise, check what the user specified on
209 * the command line. If neither, it's not available since
210 * the minimum SDK version is assumed to be 1.
213 if (mManifestMinSdkVersion
!= NULL
) {
214 minVer
= mManifestMinSdkVersion
;
215 } else if (mMinSdkVersion
!= NULL
) {
216 minVer
= mMinSdkVersion
;
222 int minSdkNum
= (int)strtol(minVer
, &end
, 0);
224 if (minSdkNum
< desired
) {
232 /* commands & modifiers */
237 int mGrayscaleTolerance
;
238 bool mMakePackageDirs
;
241 bool mRequireLocalization
;
242 bool mPseudolocalize
;
245 int mCompressionMethod
;
247 const char* mOutputAPKFile
;
248 const char* mManifestPackageNameOverride
;
249 const char* mInstrumentationPackageNameOverride
;
250 bool mAutoAddOverlay
;
251 bool mGenDependencies
;
252 const char* mAssetSourceDir
;
253 const char* mCrunchedOutputDir
;
254 const char* mProguardFile
;
255 const char* mAndroidManifestFile
;
256 const char* mPublicOutputFile
;
257 const char* mRClassDir
;
258 const char* mResourceIntermediatesDir
;
259 android::String8 mConfigurations
;
260 android::String8 mPreferredConfigurations
;
261 android::Vector
<const char*> mPackageIncludes
;
262 android::Vector
<const char*> mJarFiles
;
263 android::Vector
<const char*> mNoCompressExtensions
;
264 android::Vector
<const char*> mResourceSourceDirs
;
266 const char* mManifestMinSdkVersion
;
267 const char* mMinSdkVersion
;
268 const char* mTargetSdkVersion
;
269 const char* mMaxSdkVersion
;
270 const char* mVersionCode
;
271 const char* mVersionName
;
272 const char* mCustomPackage
;
273 const char* mExtraPackages
;
274 const char* mMaxResVersion
;
277 const char* mProduct
;
278 bool mUseCrunchCache
;
280 /* file specification */