The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2006 The Android Open Source Project |
| 3 | // |
| 4 | // Information about assets being operated on. |
| 5 | // |
| 6 | #ifndef __AAPT_ASSETS_H |
| 7 | #define __AAPT_ASSETS_H |
| 8 | |
| 9 | #include <stdlib.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 10 | #include <androidfw/AssetManager.h> |
| 11 | #include <androidfw/ResourceTypes.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12 | #include <utils/KeyedVector.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 13 | #include <utils/RefBase.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14 | #include <utils/SortedVector.h> |
| 15 | #include <utils/String8.h> |
| 16 | #include <utils/Vector.h> |
Mathias Agopian | 55e3d60 | 2009-06-05 14:56:35 -0700 | [diff] [blame] | 17 | #include "ZipFile.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
| 19 | #include "Bundle.h" |
| 20 | #include "SourcePos.h" |
| 21 | |
| 22 | using namespace android; |
| 23 | |
Raphael Moll | 90897ed | 2012-05-07 16:16:46 -0700 | [diff] [blame] | 24 | |
| 25 | extern const char * const gDefaultIgnoreAssets; |
| 26 | extern const char * gUserIgnoreAssets; |
| 27 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | bool valid_symbol_name(const String8& str); |
| 29 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 30 | class AaptAssets; |
| 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | enum { |
| 33 | AXIS_NONE = 0, |
| 34 | AXIS_MCC = 1, |
| 35 | AXIS_MNC, |
Narayan Kamath | 91447d8 | 2014-01-21 15:32:36 +0000 | [diff] [blame] | 36 | AXIS_LOCALE, |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 37 | AXIS_SCREENLAYOUTSIZE, |
| 38 | AXIS_SCREENLAYOUTLONG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | AXIS_ORIENTATION, |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 40 | AXIS_UIMODETYPE, |
| 41 | AXIS_UIMODENIGHT, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | AXIS_DENSITY, |
| 43 | AXIS_TOUCHSCREEN, |
| 44 | AXIS_KEYSHIDDEN, |
| 45 | AXIS_KEYBOARD, |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 46 | AXIS_NAVHIDDEN, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | AXIS_NAVIGATION, |
| 48 | AXIS_SCREENSIZE, |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 49 | AXIS_SMALLESTSCREENWIDTHDP, |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 50 | AXIS_SCREENWIDTHDP, |
| 51 | AXIS_SCREENHEIGHTDP, |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 52 | AXIS_LAYOUTDIR, |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 53 | AXIS_VERSION, |
| 54 | |
| 55 | AXIS_START = AXIS_MCC, |
| 56 | AXIS_END = AXIS_VERSION, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Narayan Kamath | 91447d8 | 2014-01-21 15:32:36 +0000 | [diff] [blame] | 59 | struct AaptLocaleValue { |
| 60 | char language[4]; |
| 61 | char region[4]; |
| 62 | char script[4]; |
| 63 | char variant[8]; |
| 64 | |
| 65 | AaptLocaleValue() { |
| 66 | memset(this, 0, sizeof(AaptLocaleValue)); |
| 67 | } |
| 68 | |
| 69 | // Initialize this AaptLocaleValue from a config string. |
| 70 | bool initFromFilterString(const String8& config); |
| 71 | |
| 72 | int initFromDirName(const Vector<String8>& parts, const int startIndex); |
| 73 | |
| 74 | // Initialize this AaptLocaleValue from a ResTable_config. |
| 75 | void initFromResTable(const ResTable_config& config); |
| 76 | |
| 77 | void writeTo(ResTable_config* out) const; |
| 78 | |
| 79 | String8 toDirName() const; |
| 80 | |
| 81 | int compare(const AaptLocaleValue& other) const { |
| 82 | return memcmp(this, &other, sizeof(AaptLocaleValue)); |
| 83 | } |
| 84 | |
| 85 | static void splitAndLowerCase(const char* const chars, Vector<String8>* parts, |
| 86 | const char separator); |
| 87 | |
| 88 | inline bool operator<(const AaptLocaleValue& o) const { return compare(o) < 0; } |
| 89 | inline bool operator<=(const AaptLocaleValue& o) const { return compare(o) <= 0; } |
| 90 | inline bool operator==(const AaptLocaleValue& o) const { return compare(o) == 0; } |
| 91 | inline bool operator!=(const AaptLocaleValue& o) const { return compare(o) != 0; } |
| 92 | inline bool operator>=(const AaptLocaleValue& o) const { return compare(o) >= 0; } |
| 93 | inline bool operator>(const AaptLocaleValue& o) const { return compare(o) > 0; } |
| 94 | private: |
| 95 | void setLanguage(const char* language); |
| 96 | void setRegion(const char* language); |
| 97 | void setScript(const char* script); |
| 98 | void setVariant(const char* variant); |
| 99 | }; |
| 100 | |
| 101 | struct AxisValue { |
| 102 | // Used for all axes except AXIS_LOCALE, which is represented |
| 103 | // as a AaptLocaleValue value. |
| 104 | int intValue; |
| 105 | AaptLocaleValue localeValue; |
| 106 | |
| 107 | AxisValue() : intValue(0) { |
| 108 | } |
| 109 | |
| 110 | inline int compare(const AxisValue &other) const { |
| 111 | if (intValue != other.intValue) { |
| 112 | return intValue - other.intValue; |
| 113 | } |
| 114 | |
| 115 | return localeValue.compare(other.localeValue); |
| 116 | } |
| 117 | |
| 118 | inline bool operator<(const AxisValue& o) const { return compare(o) < 0; } |
| 119 | inline bool operator<=(const AxisValue& o) const { return compare(o) <= 0; } |
| 120 | inline bool operator==(const AxisValue& o) const { return compare(o) == 0; } |
| 121 | inline bool operator!=(const AxisValue& o) const { return compare(o) != 0; } |
| 122 | inline bool operator>=(const AxisValue& o) const { return compare(o) >= 0; } |
| 123 | inline bool operator>(const AxisValue& o) const { return compare(o) > 0; } |
| 124 | }; |
| 125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | /** |
| 127 | * This structure contains a specific variation of a single file out |
| 128 | * of all the variations it can have that we can have. |
| 129 | */ |
| 130 | struct AaptGroupEntry |
| 131 | { |
| 132 | public: |
Narayan Kamath | 91447d8 | 2014-01-21 15:32:36 +0000 | [diff] [blame] | 133 | AaptGroupEntry() : mParamsChanged(true) { |
| 134 | memset(&mParams, 0, sizeof(ResTable_config)); |
| 135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | |
| 137 | bool initFromDirName(const char* dir, String8* resType); |
| 138 | |
Narayan Kamath | 91447d8 | 2014-01-21 15:32:36 +0000 | [diff] [blame] | 139 | static bool parseFilterNamePart(const String8& part, int* axis, AxisValue* value); |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 140 | |
Narayan Kamath | 91447d8 | 2014-01-21 15:32:36 +0000 | [diff] [blame] | 141 | static AxisValue getConfigValueForAxis(const ResTable_config& config, int axis); |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 142 | |
| 143 | static bool configSameExcept(const ResTable_config& config, |
| 144 | const ResTable_config& otherConfig, int axis); |
| 145 | |
Narayan Kamath | 91447d8 | 2014-01-21 15:32:36 +0000 | [diff] [blame] | 146 | int compare(const AaptGroupEntry& o) const; |
| 147 | |
| 148 | const ResTable_config toParams() const; |
| 149 | |
| 150 | inline bool operator<(const AaptGroupEntry& o) const { return compare(o) < 0; } |
| 151 | inline bool operator<=(const AaptGroupEntry& o) const { return compare(o) <= 0; } |
| 152 | inline bool operator==(const AaptGroupEntry& o) const { return compare(o) == 0; } |
| 153 | inline bool operator!=(const AaptGroupEntry& o) const { return compare(o) != 0; } |
| 154 | inline bool operator>=(const AaptGroupEntry& o) const { return compare(o) >= 0; } |
| 155 | inline bool operator>(const AaptGroupEntry& o) const { return compare(o) > 0; } |
| 156 | |
| 157 | String8 toString() const; |
| 158 | String8 toDirName(const String8& resType) const; |
| 159 | |
| 160 | const String8& getVersionString() const { return version; } |
| 161 | |
| 162 | private: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static bool getMccName(const char* name, ResTable_config* out = NULL); |
| 164 | static bool getMncName(const char* name, ResTable_config* out = NULL); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 165 | static bool getScreenLayoutSizeName(const char* name, ResTable_config* out = NULL); |
| 166 | static bool getScreenLayoutLongName(const char* name, ResTable_config* out = NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | static bool getOrientationName(const char* name, ResTable_config* out = NULL); |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 168 | static bool getUiModeTypeName(const char* name, ResTable_config* out = NULL); |
| 169 | static bool getUiModeNightName(const char* name, ResTable_config* out = NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | static bool getDensityName(const char* name, ResTable_config* out = NULL); |
| 171 | static bool getTouchscreenName(const char* name, ResTable_config* out = NULL); |
| 172 | static bool getKeysHiddenName(const char* name, ResTable_config* out = NULL); |
| 173 | static bool getKeyboardName(const char* name, ResTable_config* out = NULL); |
| 174 | static bool getNavigationName(const char* name, ResTable_config* out = NULL); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 175 | static bool getNavHiddenName(const char* name, ResTable_config* out = NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | static bool getScreenSizeName(const char* name, ResTable_config* out = NULL); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 177 | static bool getSmallestScreenWidthDpName(const char* name, ResTable_config* out = NULL); |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 178 | static bool getScreenWidthDpName(const char* name, ResTable_config* out = NULL); |
| 179 | static bool getScreenHeightDpName(const char* name, ResTable_config* out = NULL); |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 180 | static bool getLayoutDirectionName(const char* name, ResTable_config* out = NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | static bool getVersionName(const char* name, ResTable_config* out = NULL); |
| 182 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 183 | String8 mcc; |
| 184 | String8 mnc; |
Narayan Kamath | 91447d8 | 2014-01-21 15:32:36 +0000 | [diff] [blame] | 185 | AaptLocaleValue locale; |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 186 | String8 vendor; |
| 187 | String8 smallestScreenWidthDp; |
| 188 | String8 screenWidthDp; |
| 189 | String8 screenHeightDp; |
| 190 | String8 screenLayoutSize; |
| 191 | String8 screenLayoutLong; |
| 192 | String8 orientation; |
| 193 | String8 uiModeType; |
| 194 | String8 uiModeNight; |
| 195 | String8 density; |
| 196 | String8 touchscreen; |
| 197 | String8 keysHidden; |
| 198 | String8 keyboard; |
| 199 | String8 navHidden; |
| 200 | String8 navigation; |
| 201 | String8 screenSize; |
Fabrice Di Meglio | 5f79799 | 2012-06-15 20:16:41 -0700 | [diff] [blame] | 202 | String8 layoutDirection; |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 203 | String8 version; |
| 204 | |
| 205 | mutable bool mParamsChanged; |
| 206 | mutable ResTable_config mParams; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | inline int compare_type(const AaptGroupEntry& lhs, const AaptGroupEntry& rhs) |
| 210 | { |
| 211 | return lhs.compare(rhs); |
| 212 | } |
| 213 | |
| 214 | inline int strictly_order_type(const AaptGroupEntry& lhs, const AaptGroupEntry& rhs) |
| 215 | { |
| 216 | return compare_type(lhs, rhs) < 0; |
| 217 | } |
| 218 | |
| 219 | class AaptGroup; |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 220 | class FilePathStore; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | |
| 222 | /** |
| 223 | * A single asset file we know about. |
| 224 | */ |
| 225 | class AaptFile : public RefBase |
| 226 | { |
| 227 | public: |
| 228 | AaptFile(const String8& sourceFile, const AaptGroupEntry& groupEntry, |
| 229 | const String8& resType) |
| 230 | : mGroupEntry(groupEntry) |
| 231 | , mResourceType(resType) |
| 232 | , mSourceFile(sourceFile) |
| 233 | , mData(NULL) |
| 234 | , mDataSize(0) |
| 235 | , mBufferSize(0) |
| 236 | , mCompression(ZipEntry::kCompressStored) |
| 237 | { |
| 238 | //printf("new AaptFile created %s\n", (const char*)sourceFile); |
| 239 | } |
Marco Nelissen | 6a1fade | 2009-04-20 16:16:01 -0700 | [diff] [blame] | 240 | virtual ~AaptFile() { |
| 241 | free(mData); |
| 242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | |
| 244 | const String8& getPath() const { return mPath; } |
| 245 | const AaptGroupEntry& getGroupEntry() const { return mGroupEntry; } |
| 246 | |
| 247 | // Data API. If there is data attached to the file, |
| 248 | // getSourceFile() is not used. |
| 249 | bool hasData() const { return mData != NULL; } |
| 250 | const void* getData() const { return mData; } |
| 251 | size_t getSize() const { return mDataSize; } |
| 252 | void* editData(size_t size); |
| 253 | void* editData(size_t* outSize = NULL); |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 254 | void* editDataInRange(size_t offset, size_t size); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | void* padData(size_t wordSize); |
| 256 | status_t writeData(const void* data, size_t size); |
| 257 | void clearData(); |
| 258 | |
| 259 | const String8& getResourceType() const { return mResourceType; } |
| 260 | |
| 261 | // File API. If the file does not hold raw data, this is |
| 262 | // a full path to a file on the filesystem that holds its data. |
| 263 | const String8& getSourceFile() const { return mSourceFile; } |
| 264 | |
| 265 | String8 getPrintableSource() const; |
| 266 | |
| 267 | // Desired compression method, as per utils/ZipEntry.h. For example, |
| 268 | // no compression is ZipEntry::kCompressStored. |
| 269 | int getCompressionMethod() const { return mCompression; } |
| 270 | void setCompressionMethod(int c) { mCompression = c; } |
| 271 | private: |
| 272 | friend class AaptGroup; |
| 273 | |
| 274 | String8 mPath; |
| 275 | AaptGroupEntry mGroupEntry; |
| 276 | String8 mResourceType; |
| 277 | String8 mSourceFile; |
| 278 | void* mData; |
| 279 | size_t mDataSize; |
| 280 | size_t mBufferSize; |
| 281 | int mCompression; |
| 282 | }; |
| 283 | |
| 284 | /** |
| 285 | * A group of related files (the same file, with different |
| 286 | * vendor/locale variations). |
| 287 | */ |
| 288 | class AaptGroup : public RefBase |
| 289 | { |
| 290 | public: |
| 291 | AaptGroup(const String8& leaf, const String8& path) |
| 292 | : mLeaf(leaf), mPath(path) { } |
| 293 | virtual ~AaptGroup() { } |
| 294 | |
| 295 | const String8& getLeaf() const { return mLeaf; } |
| 296 | |
| 297 | // Returns the relative path after the AaptGroupEntry dirs. |
| 298 | const String8& getPath() const { return mPath; } |
| 299 | |
| 300 | const DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> >& getFiles() const |
| 301 | { return mFiles; } |
| 302 | |
Adam Lesinski | 0938430 | 2014-01-22 16:07:42 -0800 | [diff] [blame] | 303 | status_t addFile(const sp<AaptFile>& file, const bool overwriteDuplicate=false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | void removeFile(size_t index); |
| 305 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 306 | void print(const String8& prefix) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | |
| 308 | String8 getPrintableSource() const; |
| 309 | |
| 310 | private: |
| 311 | String8 mLeaf; |
| 312 | String8 mPath; |
| 313 | |
| 314 | DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> > mFiles; |
| 315 | }; |
| 316 | |
| 317 | /** |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 318 | * A single directory of assets, which can contain files and other |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | * sub-directories. |
| 320 | */ |
| 321 | class AaptDir : public RefBase |
| 322 | { |
| 323 | public: |
| 324 | AaptDir(const String8& leaf, const String8& path) |
| 325 | : mLeaf(leaf), mPath(path) { } |
| 326 | virtual ~AaptDir() { } |
| 327 | |
| 328 | const String8& getLeaf() const { return mLeaf; } |
| 329 | |
| 330 | const String8& getPath() const { return mPath; } |
| 331 | |
| 332 | const DefaultKeyedVector<String8, sp<AaptGroup> >& getFiles() const { return mFiles; } |
| 333 | const DefaultKeyedVector<String8, sp<AaptDir> >& getDirs() const { return mDirs; } |
| 334 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 335 | virtual status_t addFile(const String8& name, const sp<AaptGroup>& file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | |
| 337 | void removeFile(const String8& name); |
| 338 | void removeDir(const String8& name); |
| 339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | /* |
| 341 | * Perform some sanity checks on the names of files and directories here. |
| 342 | * In particular: |
| 343 | * - Check for illegal chars in filenames. |
| 344 | * - Check filename length. |
| 345 | * - Check for presence of ".gz" and non-".gz" copies of same file. |
| 346 | * - Check for multiple files whose names match in a case-insensitive |
| 347 | * fashion (problematic for some systems). |
| 348 | * |
| 349 | * Comparing names against all other names is O(n^2). We could speed |
| 350 | * it up some by sorting the entries and being smarter about what we |
| 351 | * compare against, but I'm not expecting to have enough files in a |
| 352 | * single directory to make a noticeable difference in speed. |
| 353 | * |
| 354 | * Note that sorting here is not enough to guarantee that the package |
| 355 | * contents are sorted -- subsequent updates can rearrange things. |
| 356 | */ |
| 357 | status_t validate() const; |
| 358 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 359 | void print(const String8& prefix) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | |
| 361 | String8 getPrintableSource() const; |
| 362 | |
| 363 | private: |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 364 | friend class AaptAssets; |
| 365 | |
| 366 | status_t addDir(const String8& name, const sp<AaptDir>& dir); |
| 367 | sp<AaptDir> makeDir(const String8& name); |
| 368 | status_t addLeafFile(const String8& leafName, |
Adam Lesinski | 0938430 | 2014-01-22 16:07:42 -0800 | [diff] [blame] | 369 | const sp<AaptFile>& file, |
| 370 | const bool overwrite=false); |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 371 | virtual ssize_t slurpFullTree(Bundle* bundle, |
| 372 | const String8& srcDir, |
| 373 | const AaptGroupEntry& kind, |
| 374 | const String8& resType, |
Adam Lesinski | 0938430 | 2014-01-22 16:07:42 -0800 | [diff] [blame] | 375 | sp<FilePathStore>& fullResPaths, |
| 376 | const bool overwrite=false); |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | String8 mLeaf; |
| 379 | String8 mPath; |
| 380 | |
| 381 | DefaultKeyedVector<String8, sp<AaptGroup> > mFiles; |
| 382 | DefaultKeyedVector<String8, sp<AaptDir> > mDirs; |
| 383 | }; |
| 384 | |
| 385 | /** |
| 386 | * All information we know about a particular symbol. |
| 387 | */ |
| 388 | class AaptSymbolEntry |
| 389 | { |
| 390 | public: |
| 391 | AaptSymbolEntry() |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 392 | : isPublic(false), isJavaSymbol(false), typeCode(TYPE_UNKNOWN) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | { |
| 394 | } |
| 395 | AaptSymbolEntry(const String8& _name) |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 396 | : name(_name), isPublic(false), isJavaSymbol(false), typeCode(TYPE_UNKNOWN) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | { |
| 398 | } |
| 399 | AaptSymbolEntry(const AaptSymbolEntry& o) |
| 400 | : name(o.name), sourcePos(o.sourcePos), isPublic(o.isPublic) |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 401 | , isJavaSymbol(o.isJavaSymbol), comment(o.comment), typeComment(o.typeComment) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | , typeCode(o.typeCode), int32Val(o.int32Val), stringVal(o.stringVal) |
| 403 | { |
| 404 | } |
| 405 | AaptSymbolEntry operator=(const AaptSymbolEntry& o) |
| 406 | { |
| 407 | sourcePos = o.sourcePos; |
| 408 | isPublic = o.isPublic; |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 409 | isJavaSymbol = o.isJavaSymbol; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | comment = o.comment; |
| 411 | typeComment = o.typeComment; |
| 412 | typeCode = o.typeCode; |
| 413 | int32Val = o.int32Val; |
| 414 | stringVal = o.stringVal; |
| 415 | return *this; |
| 416 | } |
| 417 | |
| 418 | const String8 name; |
| 419 | |
| 420 | SourcePos sourcePos; |
| 421 | bool isPublic; |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 422 | bool isJavaSymbol; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | |
| 424 | String16 comment; |
| 425 | String16 typeComment; |
| 426 | |
| 427 | enum { |
| 428 | TYPE_UNKNOWN = 0, |
| 429 | TYPE_INT32, |
| 430 | TYPE_STRING |
| 431 | }; |
| 432 | |
| 433 | int typeCode; |
| 434 | |
| 435 | // Value. May be one of these. |
| 436 | int32_t int32Val; |
| 437 | String8 stringVal; |
| 438 | }; |
| 439 | |
| 440 | /** |
| 441 | * A group of related symbols (such as indices into a string block) |
| 442 | * that have been generated from the assets. |
| 443 | */ |
| 444 | class AaptSymbols : public RefBase |
| 445 | { |
| 446 | public: |
| 447 | AaptSymbols() { } |
| 448 | virtual ~AaptSymbols() { } |
| 449 | |
| 450 | status_t addSymbol(const String8& name, int32_t value, const SourcePos& pos) { |
| 451 | if (!check_valid_symbol_name(name, pos, "symbol")) { |
| 452 | return BAD_VALUE; |
| 453 | } |
| 454 | AaptSymbolEntry& sym = edit_symbol(name, &pos); |
| 455 | sym.typeCode = AaptSymbolEntry::TYPE_INT32; |
| 456 | sym.int32Val = value; |
| 457 | return NO_ERROR; |
| 458 | } |
| 459 | |
| 460 | status_t addStringSymbol(const String8& name, const String8& value, |
| 461 | const SourcePos& pos) { |
| 462 | if (!check_valid_symbol_name(name, pos, "symbol")) { |
| 463 | return BAD_VALUE; |
| 464 | } |
| 465 | AaptSymbolEntry& sym = edit_symbol(name, &pos); |
| 466 | sym.typeCode = AaptSymbolEntry::TYPE_STRING; |
| 467 | sym.stringVal = value; |
| 468 | return NO_ERROR; |
| 469 | } |
| 470 | |
| 471 | status_t makeSymbolPublic(const String8& name, const SourcePos& pos) { |
| 472 | if (!check_valid_symbol_name(name, pos, "symbol")) { |
| 473 | return BAD_VALUE; |
| 474 | } |
| 475 | AaptSymbolEntry& sym = edit_symbol(name, &pos); |
| 476 | sym.isPublic = true; |
| 477 | return NO_ERROR; |
| 478 | } |
| 479 | |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 480 | status_t makeSymbolJavaSymbol(const String8& name, const SourcePos& pos) { |
| 481 | if (!check_valid_symbol_name(name, pos, "symbol")) { |
| 482 | return BAD_VALUE; |
| 483 | } |
| 484 | AaptSymbolEntry& sym = edit_symbol(name, &pos); |
| 485 | sym.isJavaSymbol = true; |
| 486 | return NO_ERROR; |
| 487 | } |
| 488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | void appendComment(const String8& name, const String16& comment, const SourcePos& pos) { |
| 490 | if (comment.size() <= 0) { |
| 491 | return; |
| 492 | } |
| 493 | AaptSymbolEntry& sym = edit_symbol(name, &pos); |
| 494 | if (sym.comment.size() == 0) { |
| 495 | sym.comment = comment; |
| 496 | } else { |
| 497 | sym.comment.append(String16("\n")); |
| 498 | sym.comment.append(comment); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | void appendTypeComment(const String8& name, const String16& comment) { |
| 503 | if (comment.size() <= 0) { |
| 504 | return; |
| 505 | } |
| 506 | AaptSymbolEntry& sym = edit_symbol(name, NULL); |
| 507 | if (sym.typeComment.size() == 0) { |
| 508 | sym.typeComment = comment; |
| 509 | } else { |
| 510 | sym.typeComment.append(String16("\n")); |
| 511 | sym.typeComment.append(comment); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | sp<AaptSymbols> addNestedSymbol(const String8& name, const SourcePos& pos) { |
| 516 | if (!check_valid_symbol_name(name, pos, "nested symbol")) { |
| 517 | return NULL; |
| 518 | } |
| 519 | |
| 520 | sp<AaptSymbols> sym = mNestedSymbols.valueFor(name); |
| 521 | if (sym == NULL) { |
| 522 | sym = new AaptSymbols(); |
| 523 | mNestedSymbols.add(name, sym); |
| 524 | } |
| 525 | |
| 526 | return sym; |
| 527 | } |
| 528 | |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 529 | status_t applyJavaSymbols(const sp<AaptSymbols>& javaSymbols); |
| 530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | const KeyedVector<String8, AaptSymbolEntry>& getSymbols() const |
| 532 | { return mSymbols; } |
| 533 | const DefaultKeyedVector<String8, sp<AaptSymbols> >& getNestedSymbols() const |
| 534 | { return mNestedSymbols; } |
| 535 | |
| 536 | const String16& getComment(const String8& name) const |
| 537 | { return get_symbol(name).comment; } |
| 538 | const String16& getTypeComment(const String8& name) const |
| 539 | { return get_symbol(name).typeComment; } |
| 540 | |
| 541 | private: |
| 542 | bool check_valid_symbol_name(const String8& symbol, const SourcePos& pos, const char* label) { |
| 543 | if (valid_symbol_name(symbol)) { |
| 544 | return true; |
| 545 | } |
| 546 | pos.error("invalid %s: '%s'\n", label, symbol.string()); |
| 547 | return false; |
| 548 | } |
| 549 | AaptSymbolEntry& edit_symbol(const String8& symbol, const SourcePos* pos) { |
| 550 | ssize_t i = mSymbols.indexOfKey(symbol); |
| 551 | if (i < 0) { |
| 552 | i = mSymbols.add(symbol, AaptSymbolEntry(symbol)); |
| 553 | } |
| 554 | AaptSymbolEntry& sym = mSymbols.editValueAt(i); |
| 555 | if (pos != NULL && sym.sourcePos.line < 0) { |
| 556 | sym.sourcePos = *pos; |
| 557 | } |
| 558 | return sym; |
| 559 | } |
| 560 | const AaptSymbolEntry& get_symbol(const String8& symbol) const { |
| 561 | ssize_t i = mSymbols.indexOfKey(symbol); |
| 562 | if (i >= 0) { |
| 563 | return mSymbols.valueAt(i); |
| 564 | } |
| 565 | return mDefSymbol; |
| 566 | } |
| 567 | |
| 568 | KeyedVector<String8, AaptSymbolEntry> mSymbols; |
| 569 | DefaultKeyedVector<String8, sp<AaptSymbols> > mNestedSymbols; |
| 570 | AaptSymbolEntry mDefSymbol; |
| 571 | }; |
| 572 | |
Marco Nelissen | 6a1fade | 2009-04-20 16:16:01 -0700 | [diff] [blame] | 573 | class ResourceTypeSet : public RefBase, |
| 574 | public KeyedVector<String8,sp<AaptGroup> > |
| 575 | { |
| 576 | public: |
| 577 | ResourceTypeSet(); |
| 578 | }; |
| 579 | |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 580 | // Storage for lists of fully qualified paths for |
| 581 | // resources encountered during slurping. |
| 582 | class FilePathStore : public RefBase, |
| 583 | public Vector<String8> |
| 584 | { |
| 585 | public: |
| 586 | FilePathStore(); |
| 587 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | |
| 589 | /** |
| 590 | * Asset hierarchy being operated on. |
| 591 | */ |
| 592 | class AaptAssets : public AaptDir |
| 593 | { |
| 594 | public: |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 595 | AaptAssets(); |
Marco Nelissen | 6a1fade | 2009-04-20 16:16:01 -0700 | [diff] [blame] | 596 | virtual ~AaptAssets() { delete mRes; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | |
| 598 | const String8& getPackage() const { return mPackage; } |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 599 | void setPackage(const String8& package) { |
| 600 | mPackage = package; |
| 601 | mSymbolsPrivatePackage = package; |
| 602 | mHavePrivateSymbols = false; |
| 603 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 605 | const SortedVector<AaptGroupEntry>& getGroupEntries() const; |
| 606 | |
| 607 | virtual status_t addFile(const String8& name, const sp<AaptGroup>& file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | |
| 609 | sp<AaptFile> addFile(const String8& filePath, |
| 610 | const AaptGroupEntry& entry, |
| 611 | const String8& srcDir, |
| 612 | sp<AaptGroup>* outGroup, |
| 613 | const String8& resType); |
| 614 | |
| 615 | void addResource(const String8& leafName, |
| 616 | const String8& path, |
| 617 | const sp<AaptFile>& file, |
| 618 | const String8& resType); |
| 619 | |
Dianne Hackborn | 64551b2 | 2009-08-15 00:00:33 -0700 | [diff] [blame] | 620 | void addGroupEntry(const AaptGroupEntry& entry) { mGroupEntries.add(entry); } |
| 621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | ssize_t slurpFromArgs(Bundle* bundle); |
| 623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | sp<AaptSymbols> getSymbolsFor(const String8& name); |
| 625 | |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 626 | sp<AaptSymbols> getJavaSymbolsFor(const String8& name); |
| 627 | |
| 628 | status_t applyJavaSymbols(); |
| 629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | const DefaultKeyedVector<String8, sp<AaptSymbols> >& getSymbols() const { return mSymbols; } |
| 631 | |
| 632 | String8 getSymbolsPrivatePackage() const { return mSymbolsPrivatePackage; } |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 633 | void setSymbolsPrivatePackage(const String8& pkg) { |
| 634 | mSymbolsPrivatePackage = pkg; |
| 635 | mHavePrivateSymbols = mSymbolsPrivatePackage != mPackage; |
| 636 | } |
| 637 | |
| 638 | bool havePrivateSymbols() const { return mHavePrivateSymbols; } |
| 639 | |
| 640 | bool isJavaSymbol(const AaptSymbolEntry& sym, bool includePrivate) const; |
| 641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | status_t buildIncludedResources(Bundle* bundle); |
| 643 | status_t addIncludedResources(const sp<AaptFile>& file); |
| 644 | const ResTable& getIncludedResources() const; |
| 645 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 646 | void print(const String8& prefix) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 648 | inline const Vector<sp<AaptDir> >& resDirs() const { return mResDirs; } |
| 649 | sp<AaptDir> resDir(const String8& name) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | |
| 651 | inline sp<AaptAssets> getOverlay() { return mOverlay; } |
| 652 | inline void setOverlay(sp<AaptAssets>& overlay) { mOverlay = overlay; } |
| 653 | |
| 654 | inline KeyedVector<String8, sp<ResourceTypeSet> >* getResources() { return mRes; } |
| 655 | inline void |
Marco Nelissen | 6a1fade | 2009-04-20 16:16:01 -0700 | [diff] [blame] | 656 | setResources(KeyedVector<String8, sp<ResourceTypeSet> >* res) { delete mRes; mRes = res; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 658 | inline sp<FilePathStore>& getFullResPaths() { return mFullResPaths; } |
| 659 | inline void |
| 660 | setFullResPaths(sp<FilePathStore>& res) { mFullResPaths = res; } |
| 661 | |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 662 | inline sp<FilePathStore>& getFullAssetPaths() { return mFullAssetPaths; } |
| 663 | inline void |
| 664 | setFullAssetPaths(sp<FilePathStore>& res) { mFullAssetPaths = res; } |
| 665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | private: |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 667 | virtual ssize_t slurpFullTree(Bundle* bundle, |
| 668 | const String8& srcDir, |
| 669 | const AaptGroupEntry& kind, |
| 670 | const String8& resType, |
| 671 | sp<FilePathStore>& fullResPaths); |
| 672 | |
| 673 | ssize_t slurpResourceTree(Bundle* bundle, const String8& srcDir); |
| 674 | ssize_t slurpResourceZip(Bundle* bundle, const char* filename); |
| 675 | |
| 676 | status_t filter(Bundle* bundle); |
| 677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | String8 mPackage; |
| 679 | SortedVector<AaptGroupEntry> mGroupEntries; |
| 680 | DefaultKeyedVector<String8, sp<AaptSymbols> > mSymbols; |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 681 | DefaultKeyedVector<String8, sp<AaptSymbols> > mJavaSymbols; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | String8 mSymbolsPrivatePackage; |
Dianne Hackborn | 1644c6d7 | 2012-02-06 15:33:21 -0800 | [diff] [blame] | 683 | bool mHavePrivateSymbols; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 685 | Vector<sp<AaptDir> > mResDirs; |
| 686 | |
| 687 | bool mChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | |
| 689 | bool mHaveIncludedAssets; |
| 690 | AssetManager mIncludedAssets; |
| 691 | |
| 692 | sp<AaptAssets> mOverlay; |
| 693 | KeyedVector<String8, sp<ResourceTypeSet> >* mRes; |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 694 | |
| 695 | sp<FilePathStore> mFullResPaths; |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 696 | sp<FilePathStore> mFullAssetPaths; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | }; |
| 698 | |
| 699 | #endif // __AAPT_ASSETS_H |
| 700 | |