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>
20 typedef enum Command
{
31 * Bundle of goodies, including everything specified on the command line.
36 : mCmd(kCommandUnknown
), mVerbose(false), mAndroidList(false),
37 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
38 mUpdate(false), mExtending(false),
39 mRequireLocalization(false), mPseudolocalize(false),
40 mWantUTF16(false), mValues(false),
41 mCompressionMethod(0), mOutputAPKFile(NULL
),
42 mManifestPackageNameOverride(NULL
), mInstrumentationPackageNameOverride(NULL
),
43 mAutoAddOverlay(false), mAssetSourceDir(NULL
), mProguardFile(NULL
),
44 mAndroidManifestFile(NULL
), mPublicOutputFile(NULL
),
45 mRClassDir(NULL
), mResourceIntermediatesDir(NULL
), mManifestMinSdkVersion(NULL
),
46 mMinSdkVersion(NULL
), mTargetSdkVersion(NULL
), mMaxSdkVersion(NULL
),
47 mVersionCode(NULL
), mVersionName(NULL
), mCustomPackage(NULL
),
53 * Set the command value. Returns "false" if it was previously set.
55 Command
getCommand(void) const { return mCmd
; }
56 void setCommand(Command cmd
) { mCmd
= cmd
; }
59 * Command modifiers. Not all modifiers are appropriate for all
62 bool getVerbose(void) const { return mVerbose
; }
63 void setVerbose(bool val
) { mVerbose
= val
; }
64 bool getAndroidList(void) const { return mAndroidList
; }
65 void setAndroidList(bool val
) { mAndroidList
= val
; }
66 bool getForce(void) const { return mForce
; }
67 void setForce(bool val
) { mForce
= val
; }
68 void setGrayscaleTolerance(int val
) { mGrayscaleTolerance
= val
; }
69 int getGrayscaleTolerance() { return mGrayscaleTolerance
; }
70 bool getMakePackageDirs(void) const { return mMakePackageDirs
; }
71 void setMakePackageDirs(bool val
) { mMakePackageDirs
= val
; }
72 bool getUpdate(void) const { return mUpdate
; }
73 void setUpdate(bool val
) { mUpdate
= val
; }
74 bool getExtending(void) const { return mExtending
; }
75 void setExtending(bool val
) { mExtending
= val
; }
76 bool getRequireLocalization(void) const { return mRequireLocalization
; }
77 void setRequireLocalization(bool val
) { mRequireLocalization
= val
; }
78 bool getPseudolocalize(void) const { return mPseudolocalize
; }
79 void setPseudolocalize(bool val
) { mPseudolocalize
= val
; }
80 bool getWantUTF16(void) const { return mWantUTF16
; }
81 void setWantUTF16(bool val
) { mWantUTF16
= val
; }
82 bool getValues(void) const { return mValues
; }
83 void setValues(bool val
) { mValues
= val
; }
84 int getCompressionMethod(void) const { return mCompressionMethod
; }
85 void setCompressionMethod(int val
) { mCompressionMethod
= val
; }
86 bool getJunkPath(void) const { return mJunkPath
; }
87 void setJunkPath(bool val
) { mJunkPath
= val
; }
88 const char* getOutputAPKFile() const { return mOutputAPKFile
; }
89 void setOutputAPKFile(const char* val
) { mOutputAPKFile
= val
; }
90 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride
; }
91 void setManifestPackageNameOverride(const char * val
) { mManifestPackageNameOverride
= val
; }
92 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride
; }
93 void setInstrumentationPackageNameOverride(const char * val
) { mInstrumentationPackageNameOverride
= val
; }
94 bool getAutoAddOverlay() { return mAutoAddOverlay
; }
95 void setAutoAddOverlay(bool val
) { mAutoAddOverlay
= val
; }
100 const char* getAssetSourceDir() const { return mAssetSourceDir
; }
101 void setAssetSourceDir(const char* dir
) { mAssetSourceDir
= dir
; }
102 const char* getProguardFile() const { return mProguardFile
; }
103 void setProguardFile(const char* file
) { mProguardFile
= file
; }
104 const android::Vector
<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs
; }
105 void addResourceSourceDir(const char* dir
) { mResourceSourceDirs
.insertAt(dir
,0); }
106 const char* getAndroidManifestFile() const { return mAndroidManifestFile
; }
107 void setAndroidManifestFile(const char* file
) { mAndroidManifestFile
= file
; }
108 const char* getPublicOutputFile() const { return mPublicOutputFile
; }
109 void setPublicOutputFile(const char* file
) { mPublicOutputFile
= file
; }
110 const char* getRClassDir() const { return mRClassDir
; }
111 void setRClassDir(const char* dir
) { mRClassDir
= dir
; }
112 const char* getConfigurations() const { return mConfigurations
.size() > 0 ? mConfigurations
.string() : NULL
; }
113 void addConfigurations(const char* val
) { if (mConfigurations
.size() > 0) { mConfigurations
.append(","); mConfigurations
.append(val
); } else { mConfigurations
= val
; } }
114 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir
; }
115 void setResourceIntermediatesDir(const char* dir
) { mResourceIntermediatesDir
= dir
; }
116 const android::Vector
<const char*>& getPackageIncludes() const { return mPackageIncludes
; }
117 void addPackageInclude(const char* file
) { mPackageIncludes
.add(file
); }
118 const android::Vector
<const char*>& getJarFiles() const { return mJarFiles
; }
119 void addJarFile(const char* file
) { mJarFiles
.add(file
); }
120 const android::Vector
<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions
; }
121 void addNoCompressExtension(const char* ext
) { mNoCompressExtensions
.add(ext
); }
123 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion
; }
124 void setManifestMinSdkVersion(const char* val
) { mManifestMinSdkVersion
= val
; }
125 const char* getMinSdkVersion() const { return mMinSdkVersion
; }
126 void setMinSdkVersion(const char* val
) { mMinSdkVersion
= val
; }
127 const char* getTargetSdkVersion() const { return mTargetSdkVersion
; }
128 void setTargetSdkVersion(const char* val
) { mTargetSdkVersion
= val
; }
129 const char* getMaxSdkVersion() const { return mMaxSdkVersion
; }
130 void setMaxSdkVersion(const char* val
) { mMaxSdkVersion
= val
; }
131 const char* getVersionCode() const { return mVersionCode
; }
132 void setVersionCode(const char* val
) { mVersionCode
= val
; }
133 const char* getVersionName() const { return mVersionName
; }
134 void setVersionName(const char* val
) { mVersionName
= val
; }
135 const char* getCustomPackage() const { return mCustomPackage
; }
136 void setCustomPackage(const char* val
) { mCustomPackage
= val
; }
139 * Set and get the file specification.
141 * Note this does NOT make a copy of argv.
143 void setFileSpec(char* const argv
[], int argc
) {
147 int getFileSpecCount(void) const { return mArgc
; }
148 const char* getFileSpecEntry(int idx
) const { return mArgv
[idx
]; }
149 void eatArgs(int n
) {
150 if (n
> mArgc
) n
= mArgc
;
157 * Package count. Nothing to do with anything else here; this is
158 * just a convenient place to stuff it so we don't have to pass it
161 int getPackageCount(void) const { return mPackageCount
; }
162 void setPackageCount(int val
) { mPackageCount
= val
; }
165 /* Certain features may only be available on a specific SDK level or
166 * above. SDK levels that have a non-numeric identifier are assumed
167 * to be newer than any SDK level that has a number designated.
169 bool isMinSdkAtLeast(int desired
) {
170 /* If the application specifies a minSdkVersion in the manifest
171 * then use that. Otherwise, check what the user specified on
172 * the command line. If neither, it's not available since
173 * the minimum SDK version is assumed to be 1.
176 if (mManifestMinSdkVersion
!= NULL
) {
177 minVer
= mManifestMinSdkVersion
;
178 } else if (mMinSdkVersion
!= NULL
) {
179 minVer
= mMinSdkVersion
;
185 int minSdkNum
= (int)strtol(minVer
, &end
, 0);
187 if (minSdkNum
< desired
) {
195 /* commands & modifiers */
200 int mGrayscaleTolerance
;
201 bool mMakePackageDirs
;
204 bool mRequireLocalization
;
205 bool mPseudolocalize
;
208 int mCompressionMethod
;
210 const char* mOutputAPKFile
;
211 const char* mManifestPackageNameOverride
;
212 const char* mInstrumentationPackageNameOverride
;
213 bool mAutoAddOverlay
;
214 const char* mAssetSourceDir
;
215 const char* mProguardFile
;
216 const char* mAndroidManifestFile
;
217 const char* mPublicOutputFile
;
218 const char* mRClassDir
;
219 const char* mResourceIntermediatesDir
;
220 android::String8 mConfigurations
;
221 android::Vector
<const char*> mPackageIncludes
;
222 android::Vector
<const char*> mJarFiles
;
223 android::Vector
<const char*> mNoCompressExtensions
;
224 android::Vector
<const char*> mResourceSourceDirs
;
226 const char* mManifestMinSdkVersion
;
227 const char* mMinSdkVersion
;
228 const char* mTargetSdkVersion
;
229 const char* mMaxSdkVersion
;
230 const char* mVersionCode
;
231 const char* mVersionName
;
232 const char* mCustomPackage
;
234 /* file specification */