blob: 9733b6d834714eef15ed67ebd1a523ea08434ef0 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001//
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 Agopianb13b9bd2012-02-17 18:27:36 -080010#include <androidfw/AssetManager.h>
11#include <androidfw/ResourceTypes.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012#include <utils/KeyedVector.h>
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080013#include <utils/RefBase.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080014#include <utils/SortedVector.h>
15#include <utils/String8.h>
16#include <utils/Vector.h>
Mathias Agopian55e3d602009-06-05 14:56:35 -070017#include "ZipFile.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
19#include "Bundle.h"
20#include "SourcePos.h"
21
22using namespace android;
23
Raphael Moll90897ed2012-05-07 16:16:46 -070024
25extern const char * const gDefaultIgnoreAssets;
26extern const char * gUserIgnoreAssets;
27
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028bool valid_symbol_name(const String8& str);
29
Dianne Hackborne6b68032011-10-13 16:26:02 -070030class AaptAssets;
31
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032enum {
33 AXIS_NONE = 0,
34 AXIS_MCC = 1,
35 AXIS_MNC,
Narayan Kamath788fa412014-01-21 15:32:36 +000036 AXIS_LOCALE,
Dianne Hackbornc4db95c2009-07-21 17:46:02 -070037 AXIS_SCREENLAYOUTSIZE,
38 AXIS_SCREENLAYOUTLONG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 AXIS_ORIENTATION,
Tobias Haamel27b28b32010-02-09 23:09:17 +010040 AXIS_UIMODETYPE,
41 AXIS_UIMODENIGHT,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 AXIS_DENSITY,
43 AXIS_TOUCHSCREEN,
44 AXIS_KEYSHIDDEN,
45 AXIS_KEYBOARD,
Dianne Hackborn93e462b2009-09-15 22:50:40 -070046 AXIS_NAVHIDDEN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 AXIS_NAVIGATION,
48 AXIS_SCREENSIZE,
Dianne Hackborn69cb8752011-05-19 18:13:32 -070049 AXIS_SMALLESTSCREENWIDTHDP,
Dianne Hackbornebff8f92011-05-12 18:07:47 -070050 AXIS_SCREENWIDTHDP,
51 AXIS_SCREENHEIGHTDP,
Fabrice Di Meglio5f797992012-06-15 20:16:41 -070052 AXIS_LAYOUTDIR,
Dianne Hackborne6b68032011-10-13 16:26:02 -070053 AXIS_VERSION,
54
55 AXIS_START = AXIS_MCC,
56 AXIS_END = AXIS_VERSION,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057};
58
Narayan Kamath788fa412014-01-21 15:32:36 +000059struct 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; }
94private:
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
101struct 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 Project9066cfe2009-03-03 19:31:44 -0800126/**
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 */
130struct AaptGroupEntry
131{
132public:
Narayan Kamath788fa412014-01-21 15:32:36 +0000133 AaptGroupEntry() : mParamsChanged(true) {
134 memset(&mParams, 0, sizeof(ResTable_config));
135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136
137 bool initFromDirName(const char* dir, String8* resType);
138
Narayan Kamath788fa412014-01-21 15:32:36 +0000139 static bool parseFilterNamePart(const String8& part, int* axis, AxisValue* value);
Dianne Hackborne6b68032011-10-13 16:26:02 -0700140
Narayan Kamath788fa412014-01-21 15:32:36 +0000141 static AxisValue getConfigValueForAxis(const ResTable_config& config, int axis);
Dianne Hackborne6b68032011-10-13 16:26:02 -0700142
143 static bool configSameExcept(const ResTable_config& config,
144 const ResTable_config& otherConfig, int axis);
145
Narayan Kamath788fa412014-01-21 15:32:36 +0000146 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
162private:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static bool getMccName(const char* name, ResTable_config* out = NULL);
164 static bool getMncName(const char* name, ResTable_config* out = NULL);
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700165 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 Project9066cfe2009-03-03 19:31:44 -0800167 static bool getOrientationName(const char* name, ResTable_config* out = NULL);
Tobias Haamel27b28b32010-02-09 23:09:17 +0100168 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 Project9066cfe2009-03-03 19:31:44 -0800170 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 Hackborn93e462b2009-09-15 22:50:40 -0700175 static bool getNavHiddenName(const char* name, ResTable_config* out = NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 static bool getScreenSizeName(const char* name, ResTable_config* out = NULL);
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700177 static bool getSmallestScreenWidthDpName(const char* name, ResTable_config* out = NULL);
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700178 static bool getScreenWidthDpName(const char* name, ResTable_config* out = NULL);
179 static bool getScreenHeightDpName(const char* name, ResTable_config* out = NULL);
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700180 static bool getLayoutDirectionName(const char* name, ResTable_config* out = NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 static bool getVersionName(const char* name, ResTable_config* out = NULL);
182
Dianne Hackborne6b68032011-10-13 16:26:02 -0700183 String8 mcc;
184 String8 mnc;
Narayan Kamath788fa412014-01-21 15:32:36 +0000185 AaptLocaleValue locale;
Dianne Hackborne6b68032011-10-13 16:26:02 -0700186 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 Meglio5f797992012-06-15 20:16:41 -0700202 String8 layoutDirection;
Dianne Hackborne6b68032011-10-13 16:26:02 -0700203 String8 version;
204
205 mutable bool mParamsChanged;
206 mutable ResTable_config mParams;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207};
208
209inline int compare_type(const AaptGroupEntry& lhs, const AaptGroupEntry& rhs)
210{
211 return lhs.compare(rhs);
212}
213
214inline int strictly_order_type(const AaptGroupEntry& lhs, const AaptGroupEntry& rhs)
215{
216 return compare_type(lhs, rhs) < 0;
217}
218
219class AaptGroup;
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700220class FilePathStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221
222/**
223 * A single asset file we know about.
224 */
225class AaptFile : public RefBase
226{
227public:
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 Nelissen6a1fade2009-04-20 16:16:01 -0700240 virtual ~AaptFile() {
241 free(mData);
242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243
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);
254 void* padData(size_t wordSize);
255 status_t writeData(const void* data, size_t size);
256 void clearData();
257
258 const String8& getResourceType() const { return mResourceType; }
259
260 // File API. If the file does not hold raw data, this is
261 // a full path to a file on the filesystem that holds its data.
262 const String8& getSourceFile() const { return mSourceFile; }
263
264 String8 getPrintableSource() const;
265
266 // Desired compression method, as per utils/ZipEntry.h. For example,
267 // no compression is ZipEntry::kCompressStored.
268 int getCompressionMethod() const { return mCompression; }
269 void setCompressionMethod(int c) { mCompression = c; }
270private:
271 friend class AaptGroup;
272
273 String8 mPath;
274 AaptGroupEntry mGroupEntry;
275 String8 mResourceType;
276 String8 mSourceFile;
277 void* mData;
278 size_t mDataSize;
279 size_t mBufferSize;
280 int mCompression;
281};
282
283/**
284 * A group of related files (the same file, with different
285 * vendor/locale variations).
286 */
287class AaptGroup : public RefBase
288{
289public:
290 AaptGroup(const String8& leaf, const String8& path)
291 : mLeaf(leaf), mPath(path) { }
292 virtual ~AaptGroup() { }
293
294 const String8& getLeaf() const { return mLeaf; }
295
296 // Returns the relative path after the AaptGroupEntry dirs.
297 const String8& getPath() const { return mPath; }
298
299 const DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> >& getFiles() const
300 { return mFiles; }
301
302 status_t addFile(const sp<AaptFile>& file);
303 void removeFile(size_t index);
304
Dianne Hackborne6b68032011-10-13 16:26:02 -0700305 void print(const String8& prefix) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306
307 String8 getPrintableSource() const;
308
309private:
310 String8 mLeaf;
311 String8 mPath;
312
313 DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> > mFiles;
314};
315
316/**
Dianne Hackborne6b68032011-10-13 16:26:02 -0700317 * A single directory of assets, which can contain files and other
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 * sub-directories.
319 */
320class AaptDir : public RefBase
321{
322public:
323 AaptDir(const String8& leaf, const String8& path)
324 : mLeaf(leaf), mPath(path) { }
325 virtual ~AaptDir() { }
326
327 const String8& getLeaf() const { return mLeaf; }
328
329 const String8& getPath() const { return mPath; }
330
331 const DefaultKeyedVector<String8, sp<AaptGroup> >& getFiles() const { return mFiles; }
332 const DefaultKeyedVector<String8, sp<AaptDir> >& getDirs() const { return mDirs; }
333
Dianne Hackborne6b68032011-10-13 16:26:02 -0700334 virtual status_t addFile(const String8& name, const sp<AaptGroup>& file);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335
336 void removeFile(const String8& name);
337 void removeDir(const String8& name);
338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 /*
340 * Perform some sanity checks on the names of files and directories here.
341 * In particular:
342 * - Check for illegal chars in filenames.
343 * - Check filename length.
344 * - Check for presence of ".gz" and non-".gz" copies of same file.
345 * - Check for multiple files whose names match in a case-insensitive
346 * fashion (problematic for some systems).
347 *
348 * Comparing names against all other names is O(n^2). We could speed
349 * it up some by sorting the entries and being smarter about what we
350 * compare against, but I'm not expecting to have enough files in a
351 * single directory to make a noticeable difference in speed.
352 *
353 * Note that sorting here is not enough to guarantee that the package
354 * contents are sorted -- subsequent updates can rearrange things.
355 */
356 status_t validate() const;
357
Dianne Hackborne6b68032011-10-13 16:26:02 -0700358 void print(const String8& prefix) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359
360 String8 getPrintableSource() const;
361
362private:
Dianne Hackborne6b68032011-10-13 16:26:02 -0700363 friend class AaptAssets;
364
365 status_t addDir(const String8& name, const sp<AaptDir>& dir);
366 sp<AaptDir> makeDir(const String8& name);
367 status_t addLeafFile(const String8& leafName,
368 const sp<AaptFile>& file);
369 virtual ssize_t slurpFullTree(Bundle* bundle,
370 const String8& srcDir,
371 const AaptGroupEntry& kind,
372 const String8& resType,
373 sp<FilePathStore>& fullResPaths);
374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 String8 mLeaf;
376 String8 mPath;
377
378 DefaultKeyedVector<String8, sp<AaptGroup> > mFiles;
379 DefaultKeyedVector<String8, sp<AaptDir> > mDirs;
380};
381
382/**
383 * All information we know about a particular symbol.
384 */
385class AaptSymbolEntry
386{
387public:
388 AaptSymbolEntry()
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800389 : isPublic(false), isJavaSymbol(false), typeCode(TYPE_UNKNOWN)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 {
391 }
392 AaptSymbolEntry(const String8& _name)
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800393 : name(_name), isPublic(false), isJavaSymbol(false), typeCode(TYPE_UNKNOWN)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 {
395 }
396 AaptSymbolEntry(const AaptSymbolEntry& o)
397 : name(o.name), sourcePos(o.sourcePos), isPublic(o.isPublic)
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800398 , isJavaSymbol(o.isJavaSymbol), comment(o.comment), typeComment(o.typeComment)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 , typeCode(o.typeCode), int32Val(o.int32Val), stringVal(o.stringVal)
400 {
401 }
402 AaptSymbolEntry operator=(const AaptSymbolEntry& o)
403 {
404 sourcePos = o.sourcePos;
405 isPublic = o.isPublic;
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800406 isJavaSymbol = o.isJavaSymbol;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 comment = o.comment;
408 typeComment = o.typeComment;
409 typeCode = o.typeCode;
410 int32Val = o.int32Val;
411 stringVal = o.stringVal;
412 return *this;
413 }
414
415 const String8 name;
416
417 SourcePos sourcePos;
418 bool isPublic;
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800419 bool isJavaSymbol;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420
421 String16 comment;
422 String16 typeComment;
423
424 enum {
425 TYPE_UNKNOWN = 0,
426 TYPE_INT32,
427 TYPE_STRING
428 };
429
430 int typeCode;
431
432 // Value. May be one of these.
433 int32_t int32Val;
434 String8 stringVal;
435};
436
437/**
438 * A group of related symbols (such as indices into a string block)
439 * that have been generated from the assets.
440 */
441class AaptSymbols : public RefBase
442{
443public:
444 AaptSymbols() { }
445 virtual ~AaptSymbols() { }
446
447 status_t addSymbol(const String8& name, int32_t value, const SourcePos& pos) {
448 if (!check_valid_symbol_name(name, pos, "symbol")) {
449 return BAD_VALUE;
450 }
451 AaptSymbolEntry& sym = edit_symbol(name, &pos);
452 sym.typeCode = AaptSymbolEntry::TYPE_INT32;
453 sym.int32Val = value;
454 return NO_ERROR;
455 }
456
457 status_t addStringSymbol(const String8& name, const String8& value,
458 const SourcePos& pos) {
459 if (!check_valid_symbol_name(name, pos, "symbol")) {
460 return BAD_VALUE;
461 }
462 AaptSymbolEntry& sym = edit_symbol(name, &pos);
463 sym.typeCode = AaptSymbolEntry::TYPE_STRING;
464 sym.stringVal = value;
465 return NO_ERROR;
466 }
467
468 status_t makeSymbolPublic(const String8& name, const SourcePos& pos) {
469 if (!check_valid_symbol_name(name, pos, "symbol")) {
470 return BAD_VALUE;
471 }
472 AaptSymbolEntry& sym = edit_symbol(name, &pos);
473 sym.isPublic = true;
474 return NO_ERROR;
475 }
476
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800477 status_t makeSymbolJavaSymbol(const String8& name, const SourcePos& pos) {
478 if (!check_valid_symbol_name(name, pos, "symbol")) {
479 return BAD_VALUE;
480 }
481 AaptSymbolEntry& sym = edit_symbol(name, &pos);
482 sym.isJavaSymbol = true;
483 return NO_ERROR;
484 }
485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 void appendComment(const String8& name, const String16& comment, const SourcePos& pos) {
487 if (comment.size() <= 0) {
488 return;
489 }
490 AaptSymbolEntry& sym = edit_symbol(name, &pos);
491 if (sym.comment.size() == 0) {
492 sym.comment = comment;
493 } else {
494 sym.comment.append(String16("\n"));
495 sym.comment.append(comment);
496 }
497 }
498
499 void appendTypeComment(const String8& name, const String16& comment) {
500 if (comment.size() <= 0) {
501 return;
502 }
503 AaptSymbolEntry& sym = edit_symbol(name, NULL);
504 if (sym.typeComment.size() == 0) {
505 sym.typeComment = comment;
506 } else {
507 sym.typeComment.append(String16("\n"));
508 sym.typeComment.append(comment);
509 }
510 }
511
512 sp<AaptSymbols> addNestedSymbol(const String8& name, const SourcePos& pos) {
513 if (!check_valid_symbol_name(name, pos, "nested symbol")) {
514 return NULL;
515 }
516
517 sp<AaptSymbols> sym = mNestedSymbols.valueFor(name);
518 if (sym == NULL) {
519 sym = new AaptSymbols();
520 mNestedSymbols.add(name, sym);
521 }
522
523 return sym;
524 }
525
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800526 status_t applyJavaSymbols(const sp<AaptSymbols>& javaSymbols);
527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 const KeyedVector<String8, AaptSymbolEntry>& getSymbols() const
529 { return mSymbols; }
530 const DefaultKeyedVector<String8, sp<AaptSymbols> >& getNestedSymbols() const
531 { return mNestedSymbols; }
532
533 const String16& getComment(const String8& name) const
534 { return get_symbol(name).comment; }
535 const String16& getTypeComment(const String8& name) const
536 { return get_symbol(name).typeComment; }
537
538private:
539 bool check_valid_symbol_name(const String8& symbol, const SourcePos& pos, const char* label) {
540 if (valid_symbol_name(symbol)) {
541 return true;
542 }
543 pos.error("invalid %s: '%s'\n", label, symbol.string());
544 return false;
545 }
546 AaptSymbolEntry& edit_symbol(const String8& symbol, const SourcePos* pos) {
547 ssize_t i = mSymbols.indexOfKey(symbol);
548 if (i < 0) {
549 i = mSymbols.add(symbol, AaptSymbolEntry(symbol));
550 }
551 AaptSymbolEntry& sym = mSymbols.editValueAt(i);
552 if (pos != NULL && sym.sourcePos.line < 0) {
553 sym.sourcePos = *pos;
554 }
555 return sym;
556 }
557 const AaptSymbolEntry& get_symbol(const String8& symbol) const {
558 ssize_t i = mSymbols.indexOfKey(symbol);
559 if (i >= 0) {
560 return mSymbols.valueAt(i);
561 }
562 return mDefSymbol;
563 }
564
565 KeyedVector<String8, AaptSymbolEntry> mSymbols;
566 DefaultKeyedVector<String8, sp<AaptSymbols> > mNestedSymbols;
567 AaptSymbolEntry mDefSymbol;
568};
569
Marco Nelissen6a1fade2009-04-20 16:16:01 -0700570class ResourceTypeSet : public RefBase,
571 public KeyedVector<String8,sp<AaptGroup> >
572{
573public:
574 ResourceTypeSet();
575};
576
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700577// Storage for lists of fully qualified paths for
578// resources encountered during slurping.
579class FilePathStore : public RefBase,
580 public Vector<String8>
581{
582public:
583 FilePathStore();
584};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585
586/**
587 * Asset hierarchy being operated on.
588 */
589class AaptAssets : public AaptDir
590{
591public:
Dianne Hackborne6b68032011-10-13 16:26:02 -0700592 AaptAssets();
Marco Nelissen6a1fade2009-04-20 16:16:01 -0700593 virtual ~AaptAssets() { delete mRes; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594
595 const String8& getPackage() const { return mPackage; }
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800596 void setPackage(const String8& package) {
597 mPackage = package;
598 mSymbolsPrivatePackage = package;
599 mHavePrivateSymbols = false;
600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601
Dianne Hackborne6b68032011-10-13 16:26:02 -0700602 const SortedVector<AaptGroupEntry>& getGroupEntries() const;
603
604 virtual status_t addFile(const String8& name, const sp<AaptGroup>& file);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605
606 sp<AaptFile> addFile(const String8& filePath,
607 const AaptGroupEntry& entry,
608 const String8& srcDir,
609 sp<AaptGroup>* outGroup,
610 const String8& resType);
611
612 void addResource(const String8& leafName,
613 const String8& path,
614 const sp<AaptFile>& file,
615 const String8& resType);
616
Dianne Hackborn64551b22009-08-15 00:00:33 -0700617 void addGroupEntry(const AaptGroupEntry& entry) { mGroupEntries.add(entry); }
618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 ssize_t slurpFromArgs(Bundle* bundle);
620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 sp<AaptSymbols> getSymbolsFor(const String8& name);
622
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800623 sp<AaptSymbols> getJavaSymbolsFor(const String8& name);
624
625 status_t applyJavaSymbols();
626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 const DefaultKeyedVector<String8, sp<AaptSymbols> >& getSymbols() const { return mSymbols; }
628
629 String8 getSymbolsPrivatePackage() const { return mSymbolsPrivatePackage; }
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800630 void setSymbolsPrivatePackage(const String8& pkg) {
631 mSymbolsPrivatePackage = pkg;
632 mHavePrivateSymbols = mSymbolsPrivatePackage != mPackage;
633 }
634
635 bool havePrivateSymbols() const { return mHavePrivateSymbols; }
636
637 bool isJavaSymbol(const AaptSymbolEntry& sym, bool includePrivate) const;
638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 status_t buildIncludedResources(Bundle* bundle);
640 status_t addIncludedResources(const sp<AaptFile>& file);
641 const ResTable& getIncludedResources() const;
642
Dianne Hackborne6b68032011-10-13 16:26:02 -0700643 void print(const String8& prefix) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644
Dianne Hackborne6b68032011-10-13 16:26:02 -0700645 inline const Vector<sp<AaptDir> >& resDirs() const { return mResDirs; }
646 sp<AaptDir> resDir(const String8& name) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647
648 inline sp<AaptAssets> getOverlay() { return mOverlay; }
649 inline void setOverlay(sp<AaptAssets>& overlay) { mOverlay = overlay; }
650
651 inline KeyedVector<String8, sp<ResourceTypeSet> >* getResources() { return mRes; }
652 inline void
Marco Nelissen6a1fade2009-04-20 16:16:01 -0700653 setResources(KeyedVector<String8, sp<ResourceTypeSet> >* res) { delete mRes; mRes = res; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700655 inline sp<FilePathStore>& getFullResPaths() { return mFullResPaths; }
656 inline void
657 setFullResPaths(sp<FilePathStore>& res) { mFullResPaths = res; }
658
Josiah Gaskin03589cc2011-06-27 16:26:02 -0700659 inline sp<FilePathStore>& getFullAssetPaths() { return mFullAssetPaths; }
660 inline void
661 setFullAssetPaths(sp<FilePathStore>& res) { mFullAssetPaths = res; }
662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663private:
Dianne Hackborne6b68032011-10-13 16:26:02 -0700664 virtual ssize_t slurpFullTree(Bundle* bundle,
665 const String8& srcDir,
666 const AaptGroupEntry& kind,
667 const String8& resType,
668 sp<FilePathStore>& fullResPaths);
669
670 ssize_t slurpResourceTree(Bundle* bundle, const String8& srcDir);
671 ssize_t slurpResourceZip(Bundle* bundle, const char* filename);
672
673 status_t filter(Bundle* bundle);
674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 String8 mPackage;
676 SortedVector<AaptGroupEntry> mGroupEntries;
677 DefaultKeyedVector<String8, sp<AaptSymbols> > mSymbols;
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800678 DefaultKeyedVector<String8, sp<AaptSymbols> > mJavaSymbols;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 String8 mSymbolsPrivatePackage;
Dianne Hackborn1644c6d72012-02-06 15:33:21 -0800680 bool mHavePrivateSymbols;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681
Dianne Hackborne6b68032011-10-13 16:26:02 -0700682 Vector<sp<AaptDir> > mResDirs;
683
684 bool mChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685
686 bool mHaveIncludedAssets;
687 AssetManager mIncludedAssets;
688
689 sp<AaptAssets> mOverlay;
690 KeyedVector<String8, sp<ResourceTypeSet> >* mRes;
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700691
692 sp<FilePathStore> mFullResPaths;
Josiah Gaskin03589cc2011-06-27 16:26:02 -0700693 sp<FilePathStore> mFullAssetPaths;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694};
695
696#endif // __AAPT_ASSETS_H
697