Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2006 The Android Open Source Project |
| 3 | // |
| 4 | // Build resource files from raw assets. |
| 5 | // |
| 6 | |
| 7 | #ifndef RESOURCE_TABLE_H |
| 8 | #define RESOURCE_TABLE_H |
| 9 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 10 | #include <map> |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 11 | #include <queue> |
| 12 | #include <set> |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 13 | |
Adam Lesinski | de7de47 | 2014-11-03 12:03:08 -0800 | [diff] [blame] | 14 | #include "ConfigDescription.h" |
| 15 | #include "ResourceFilter.h" |
| 16 | #include "SourcePos.h" |
| 17 | #include "StringPool.h" |
| 18 | #include "Symbol.h" |
| 19 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 20 | class XMLNode; |
| 21 | class ResourceTable; |
| 22 | |
| 23 | enum { |
| 24 | XML_COMPILE_STRIP_COMMENTS = 1<<0, |
| 25 | XML_COMPILE_ASSIGN_ATTRIBUTE_IDS = 1<<1, |
| 26 | XML_COMPILE_COMPACT_WHITESPACE = 1<<2, |
| 27 | XML_COMPILE_STRIP_WHITESPACE = 1<<3, |
| 28 | XML_COMPILE_STRIP_RAW_VALUES = 1<<4, |
| 29 | XML_COMPILE_UTF8 = 1<<5, |
Dan Albert | 030f536 | 2015-03-04 13:54:20 -0800 | [diff] [blame] | 30 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 31 | XML_COMPILE_STANDARD_RESOURCE = |
| 32 | XML_COMPILE_STRIP_COMMENTS | XML_COMPILE_ASSIGN_ATTRIBUTE_IDS |
| 33 | | XML_COMPILE_STRIP_WHITESPACE | XML_COMPILE_STRIP_RAW_VALUES |
| 34 | }; |
| 35 | |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 36 | status_t compileXmlFile(const Bundle* bundle, |
| 37 | const sp<AaptAssets>& assets, |
| 38 | const String16& resourceName, |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 39 | const sp<AaptFile>& target, |
| 40 | ResourceTable* table, |
| 41 | int options = XML_COMPILE_STANDARD_RESOURCE); |
| 42 | |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 43 | status_t compileXmlFile(const Bundle* bundle, |
| 44 | const sp<AaptAssets>& assets, |
| 45 | const String16& resourceName, |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 46 | const sp<AaptFile>& target, |
| 47 | const sp<AaptFile>& outTarget, |
| 48 | ResourceTable* table, |
| 49 | int options = XML_COMPILE_STANDARD_RESOURCE); |
| 50 | |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 51 | status_t compileXmlFile(const Bundle* bundle, |
| 52 | const sp<AaptAssets>& assets, |
| 53 | const String16& resourceName, |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 54 | const sp<XMLNode>& xmlTree, |
| 55 | const sp<AaptFile>& target, |
| 56 | ResourceTable* table, |
| 57 | int options = XML_COMPILE_STANDARD_RESOURCE); |
| 58 | |
| 59 | status_t compileResourceFile(Bundle* bundle, |
| 60 | const sp<AaptAssets>& assets, |
| 61 | const sp<AaptFile>& in, |
| 62 | const ResTable_config& defParams, |
| 63 | const bool overwrite, |
| 64 | ResourceTable* outTable); |
| 65 | |
| 66 | struct AccessorCookie |
| 67 | { |
| 68 | SourcePos sourcePos; |
| 69 | String8 attr; |
| 70 | String8 value; |
| 71 | |
| 72 | AccessorCookie(const SourcePos&p, const String8& a, const String8& v) |
| 73 | :sourcePos(p), |
| 74 | attr(a), |
| 75 | value(v) |
| 76 | { |
| 77 | } |
| 78 | }; |
| 79 | |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 80 | // Holds the necessary information to compile the |
| 81 | // resource. |
| 82 | struct CompileResourceWorkItem { |
| 83 | String16 resourceName; |
| 84 | String8 resPath; |
| 85 | sp<AaptFile> file; |
Adam Lesinski | 9d0f7d4 | 2015-10-28 15:44:27 -0700 | [diff] [blame^] | 86 | sp<XMLNode> xmlRoot; |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 89 | class ResourceTable : public ResTable::Accessor |
| 90 | { |
| 91 | public: |
Adam Lesinski | 833f3cc | 2014-06-18 15:06:01 -0700 | [diff] [blame] | 92 | // The type of package to build. |
| 93 | enum PackageType { |
| 94 | App, |
| 95 | System, |
| 96 | SharedLibrary, |
| 97 | AppFeature |
| 98 | }; |
| 99 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 100 | class Package; |
| 101 | class Type; |
| 102 | class Entry; |
Adam Lesinski | beb9e33 | 2015-08-14 13:16:18 -0700 | [diff] [blame] | 103 | class ConfigList; |
| 104 | |
| 105 | /** |
| 106 | * Exposed for testing. Determines whether a versioned resource should be generated |
| 107 | * based on the other available configurations for that resource. |
| 108 | */ |
| 109 | static bool shouldGenerateVersionedResource(const sp<ConfigList>& configList, |
| 110 | const ConfigDescription& sourceConfig, |
| 111 | const int sdkVersionToGenerate); |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 112 | |
Adam Lesinski | 833f3cc | 2014-06-18 15:06:01 -0700 | [diff] [blame] | 113 | ResourceTable(Bundle* bundle, const String16& assetsPackage, PackageType type); |
| 114 | |
| 115 | const String16& getAssetsPackage() const { |
| 116 | return mAssetsPackage; |
| 117 | } |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 118 | |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Returns the queue of resources that need to be compiled. |
| 121 | * This is only used for resources that have been generated |
| 122 | * during the compilation phase. If they were just added |
| 123 | * to the AaptAssets, then they may be skipped over |
| 124 | * and would mess up iteration order for the existing |
| 125 | * resources. |
| 126 | */ |
Dan Albert | 030f536 | 2015-03-04 13:54:20 -0800 | [diff] [blame] | 127 | std::queue<CompileResourceWorkItem>& getWorkQueue() { |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 128 | return mWorkQueue; |
| 129 | } |
| 130 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 131 | status_t addIncludedResources(Bundle* bundle, const sp<AaptAssets>& assets); |
| 132 | |
| 133 | status_t addPublic(const SourcePos& pos, |
| 134 | const String16& package, |
| 135 | const String16& type, |
| 136 | const String16& name, |
| 137 | const uint32_t ident); |
| 138 | |
| 139 | status_t addEntry(const SourcePos& pos, |
| 140 | const String16& package, |
| 141 | const String16& type, |
| 142 | const String16& name, |
| 143 | const String16& value, |
| 144 | const Vector<StringPool::entry_style_span>* style = NULL, |
| 145 | const ResTable_config* params = NULL, |
| 146 | const bool doSetIndex = false, |
| 147 | const int32_t format = ResTable_map::TYPE_ANY, |
| 148 | const bool overwrite = false); |
| 149 | |
| 150 | status_t startBag(const SourcePos& pos, |
| 151 | const String16& package, |
| 152 | const String16& type, |
| 153 | const String16& name, |
| 154 | const String16& bagParent, |
| 155 | const ResTable_config* params = NULL, |
| 156 | bool overlay = false, |
| 157 | bool replace = false, |
| 158 | bool isId = false); |
| 159 | |
| 160 | status_t addBag(const SourcePos& pos, |
| 161 | const String16& package, |
| 162 | const String16& type, |
| 163 | const String16& name, |
| 164 | const String16& bagParent, |
| 165 | const String16& bagKey, |
| 166 | const String16& value, |
| 167 | const Vector<StringPool::entry_style_span>* style = NULL, |
| 168 | const ResTable_config* params = NULL, |
| 169 | bool replace = false, |
| 170 | bool isId = false, |
| 171 | const int32_t format = ResTable_map::TYPE_ANY); |
| 172 | |
| 173 | bool hasBagOrEntry(const String16& package, |
| 174 | const String16& type, |
| 175 | const String16& name) const; |
| 176 | |
| 177 | bool hasBagOrEntry(const String16& package, |
| 178 | const String16& type, |
| 179 | const String16& name, |
| 180 | const ResTable_config& config) const; |
| 181 | |
| 182 | bool hasBagOrEntry(const String16& ref, |
| 183 | const String16* defType = NULL, |
| 184 | const String16* defPackage = NULL); |
| 185 | |
| 186 | bool appendComment(const String16& package, |
| 187 | const String16& type, |
| 188 | const String16& name, |
| 189 | const String16& comment, |
| 190 | bool onlyIfEmpty = false); |
| 191 | |
| 192 | bool appendTypeComment(const String16& package, |
| 193 | const String16& type, |
| 194 | const String16& name, |
| 195 | const String16& comment); |
| 196 | |
| 197 | void canAddEntry(const SourcePos& pos, |
| 198 | const String16& package, const String16& type, const String16& name); |
| 199 | |
| 200 | size_t size() const; |
| 201 | size_t numLocalResources() const; |
| 202 | bool hasResources() const; |
| 203 | |
Adam Lesinski | 82a2dd8 | 2014-09-17 18:34:15 -0700 | [diff] [blame] | 204 | status_t modifyForCompat(const Bundle* bundle); |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 205 | status_t modifyForCompat(const Bundle* bundle, |
| 206 | const String16& resourceName, |
| 207 | const sp<AaptFile>& file, |
| 208 | const sp<XMLNode>& root); |
Adam Lesinski | 82a2dd8 | 2014-09-17 18:34:15 -0700 | [diff] [blame] | 209 | |
Adam Lesinski | 9d0f7d4 | 2015-10-28 15:44:27 -0700 | [diff] [blame^] | 210 | status_t processBundleFormat(const Bundle* bundle, |
| 211 | const String16& resourceName, |
| 212 | const sp<AaptFile>& file, |
| 213 | const sp<XMLNode>& parent); |
| 214 | |
| 215 | |
Adam Lesinski | 27f69f4 | 2014-08-21 13:19:12 -0700 | [diff] [blame] | 216 | sp<AaptFile> flatten(Bundle* bundle, const sp<const ResourceFilter>& filter, |
| 217 | const bool isBase); |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 218 | |
| 219 | static inline uint32_t makeResId(uint32_t packageId, |
| 220 | uint32_t typeId, |
| 221 | uint32_t nameId) |
| 222 | { |
| 223 | return nameId | (typeId<<16) | (packageId<<24); |
| 224 | } |
| 225 | |
| 226 | static inline uint32_t getResId(const sp<Package>& p, |
| 227 | const sp<Type>& t, |
| 228 | uint32_t nameId); |
| 229 | |
| 230 | uint32_t getResId(const String16& package, |
| 231 | const String16& type, |
| 232 | const String16& name, |
| 233 | bool onlyPublic = true) const; |
| 234 | |
| 235 | uint32_t getResId(const String16& ref, |
| 236 | const String16* defType = NULL, |
| 237 | const String16* defPackage = NULL, |
| 238 | const char** outErrorMsg = NULL, |
| 239 | bool onlyPublic = true) const; |
| 240 | |
| 241 | static bool isValidResourceName(const String16& s); |
| 242 | |
| 243 | bool stringToValue(Res_value* outValue, StringPool* pool, |
| 244 | const String16& str, |
| 245 | bool preserveSpaces, bool coerceType, |
| 246 | uint32_t attrID, |
| 247 | const Vector<StringPool::entry_style_span>* style = NULL, |
| 248 | String16* outStr = NULL, void* accessorCookie = NULL, |
| 249 | uint32_t attrType = ResTable_map::TYPE_ANY, |
| 250 | const String8* configTypeName = NULL, |
| 251 | const ConfigDescription* config = NULL); |
| 252 | |
| 253 | status_t assignResourceIds(); |
Adrian Roos | 5892248 | 2015-06-01 17:59:41 -0700 | [diff] [blame] | 254 | status_t addSymbols(const sp<AaptSymbols>& outSymbols = NULL, |
| 255 | bool skipSymbolsWithoutDefaultLocalization = false); |
Adam Lesinski | a01a937 | 2014-03-20 18:04:57 -0700 | [diff] [blame] | 256 | void addLocalization(const String16& name, const String8& locale, const SourcePos& src); |
Adrian Roos | 5892248 | 2015-06-01 17:59:41 -0700 | [diff] [blame] | 257 | void addDefaultLocalization(const String16& name); |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 258 | status_t validateLocalizations(void); |
| 259 | |
Adam Lesinski | 27f69f4 | 2014-08-21 13:19:12 -0700 | [diff] [blame] | 260 | status_t flatten(Bundle* bundle, const sp<const ResourceFilter>& filter, |
| 261 | const sp<AaptFile>& dest, const bool isBase); |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 262 | status_t flattenLibraryTable(const sp<AaptFile>& dest, const Vector<sp<Package> >& libs); |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 263 | |
| 264 | void writePublicDefinitions(const String16& package, FILE* fp); |
| 265 | |
| 266 | virtual uint32_t getCustomResource(const String16& package, |
| 267 | const String16& type, |
| 268 | const String16& name) const; |
| 269 | virtual uint32_t getCustomResourceWithCreation(const String16& package, |
| 270 | const String16& type, |
| 271 | const String16& name, |
| 272 | const bool createIfNeeded); |
| 273 | virtual uint32_t getRemappedPackage(uint32_t origPackage) const; |
| 274 | virtual bool getAttributeType(uint32_t attrID, uint32_t* outType); |
| 275 | virtual bool getAttributeMin(uint32_t attrID, uint32_t* outMin); |
| 276 | virtual bool getAttributeMax(uint32_t attrID, uint32_t* outMax); |
| 277 | virtual bool getAttributeKeys(uint32_t attrID, Vector<String16>* outKeys); |
| 278 | virtual bool getAttributeEnum(uint32_t attrID, |
| 279 | const char16_t* name, size_t nameLen, |
| 280 | Res_value* outValue); |
| 281 | virtual bool getAttributeFlags(uint32_t attrID, |
| 282 | const char16_t* name, size_t nameLen, |
| 283 | Res_value* outValue); |
| 284 | virtual uint32_t getAttributeL10N(uint32_t attrID); |
| 285 | |
| 286 | virtual bool getLocalizationSetting(); |
| 287 | virtual void reportError(void* accessorCookie, const char* fmt, ...); |
| 288 | |
| 289 | void setCurrentXmlPos(const SourcePos& pos) { mCurrentXmlPos = pos; } |
| 290 | |
| 291 | class Item { |
| 292 | public: |
| 293 | Item() : isId(false), format(ResTable_map::TYPE_ANY), bagKeyId(0), evaluating(false) |
| 294 | { memset(&parsedValue, 0, sizeof(parsedValue)); } |
| 295 | Item(const SourcePos& pos, |
| 296 | bool _isId, |
| 297 | const String16& _value, |
| 298 | const Vector<StringPool::entry_style_span>* _style = NULL, |
| 299 | int32_t format = ResTable_map::TYPE_ANY); |
| 300 | Item(const Item& o) : sourcePos(o.sourcePos), |
| 301 | isId(o.isId), value(o.value), style(o.style), |
| 302 | format(o.format), bagKeyId(o.bagKeyId), evaluating(false) { |
| 303 | memset(&parsedValue, 0, sizeof(parsedValue)); |
| 304 | } |
| 305 | ~Item() { } |
| 306 | |
| 307 | Item& operator=(const Item& o) { |
| 308 | sourcePos = o.sourcePos; |
| 309 | isId = o.isId; |
| 310 | value = o.value; |
| 311 | style = o.style; |
| 312 | format = o.format; |
| 313 | bagKeyId = o.bagKeyId; |
| 314 | parsedValue = o.parsedValue; |
| 315 | return *this; |
| 316 | } |
| 317 | |
| 318 | SourcePos sourcePos; |
| 319 | mutable bool isId; |
| 320 | String16 value; |
| 321 | Vector<StringPool::entry_style_span> style; |
| 322 | int32_t format; |
| 323 | uint32_t bagKeyId; |
| 324 | mutable bool evaluating; |
| 325 | Res_value parsedValue; |
| 326 | }; |
| 327 | |
| 328 | class Entry : public RefBase { |
| 329 | public: |
| 330 | Entry(const String16& name, const SourcePos& pos) |
| 331 | : mName(name), mType(TYPE_UNKNOWN), |
| 332 | mItemFormat(ResTable_map::TYPE_ANY), mNameIndex(-1), mPos(pos) |
| 333 | { } |
Adam Lesinski | 82a2dd8 | 2014-09-17 18:34:15 -0700 | [diff] [blame] | 334 | |
| 335 | Entry(const Entry& entry); |
Adam Lesinski | 978ab9d | 2014-09-24 19:02:52 -0700 | [diff] [blame] | 336 | Entry& operator=(const Entry& entry); |
Adam Lesinski | 82a2dd8 | 2014-09-17 18:34:15 -0700 | [diff] [blame] | 337 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 338 | virtual ~Entry() { } |
| 339 | |
| 340 | enum type { |
| 341 | TYPE_UNKNOWN = 0, |
| 342 | TYPE_ITEM, |
| 343 | TYPE_BAG |
| 344 | }; |
| 345 | |
| 346 | String16 getName() const { return mName; } |
| 347 | type getType() const { return mType; } |
| 348 | |
| 349 | void setParent(const String16& parent) { mParent = parent; } |
| 350 | String16 getParent() const { return mParent; } |
| 351 | |
| 352 | status_t makeItABag(const SourcePos& sourcePos); |
| 353 | |
| 354 | status_t emptyBag(const SourcePos& sourcePos); |
| 355 | |
| 356 | status_t setItem(const SourcePos& pos, |
| 357 | const String16& value, |
| 358 | const Vector<StringPool::entry_style_span>* style = NULL, |
| 359 | int32_t format = ResTable_map::TYPE_ANY, |
| 360 | const bool overwrite = false); |
| 361 | |
| 362 | status_t addToBag(const SourcePos& pos, |
| 363 | const String16& key, const String16& value, |
| 364 | const Vector<StringPool::entry_style_span>* style = NULL, |
| 365 | bool replace=false, bool isId = false, |
| 366 | int32_t format = ResTable_map::TYPE_ANY); |
| 367 | |
Adam Lesinski | 82a2dd8 | 2014-09-17 18:34:15 -0700 | [diff] [blame] | 368 | status_t removeFromBag(const String16& key); |
| 369 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 370 | // Index of the entry's name string in the key pool. |
| 371 | int32_t getNameIndex() const { return mNameIndex; } |
| 372 | void setNameIndex(int32_t index) { mNameIndex = index; } |
| 373 | |
| 374 | const Item* getItem() const { return mType == TYPE_ITEM ? &mItem : NULL; } |
| 375 | const KeyedVector<String16, Item>& getBag() const { return mBag; } |
| 376 | |
| 377 | status_t generateAttributes(ResourceTable* table, |
| 378 | const String16& package); |
| 379 | |
| 380 | status_t assignResourceIds(ResourceTable* table, |
| 381 | const String16& package); |
| 382 | |
| 383 | status_t prepareFlatten(StringPool* strings, ResourceTable* table, |
| 384 | const String8* configTypeName, const ConfigDescription* config); |
| 385 | |
| 386 | status_t remapStringValue(StringPool* strings); |
| 387 | |
| 388 | ssize_t flatten(Bundle*, const sp<AaptFile>& data, bool isPublic); |
| 389 | |
| 390 | const SourcePos& getPos() const { return mPos; } |
| 391 | |
| 392 | private: |
| 393 | String16 mName; |
| 394 | String16 mParent; |
| 395 | type mType; |
| 396 | Item mItem; |
| 397 | int32_t mItemFormat; |
| 398 | KeyedVector<String16, Item> mBag; |
| 399 | int32_t mNameIndex; |
| 400 | uint32_t mParentId; |
| 401 | SourcePos mPos; |
| 402 | }; |
| 403 | |
| 404 | class ConfigList : public RefBase { |
| 405 | public: |
| 406 | ConfigList(const String16& name, const SourcePos& pos) |
| 407 | : mName(name), mPos(pos), mPublic(false), mEntryIndex(-1) { } |
| 408 | virtual ~ConfigList() { } |
| 409 | |
| 410 | String16 getName() const { return mName; } |
| 411 | const SourcePos& getPos() const { return mPos; } |
| 412 | |
| 413 | void appendComment(const String16& comment, bool onlyIfEmpty = false); |
| 414 | const String16& getComment() const { return mComment; } |
| 415 | |
| 416 | void appendTypeComment(const String16& comment); |
| 417 | const String16& getTypeComment() const { return mTypeComment; } |
| 418 | |
| 419 | // Index of this entry in its Type. |
| 420 | int32_t getEntryIndex() const { return mEntryIndex; } |
| 421 | void setEntryIndex(int32_t index) { mEntryIndex = index; } |
| 422 | |
| 423 | void setPublic(bool pub) { mPublic = pub; } |
| 424 | bool getPublic() const { return mPublic; } |
| 425 | void setPublicSourcePos(const SourcePos& pos) { mPublicSourcePos = pos; } |
| 426 | const SourcePos& getPublicSourcePos() { return mPublicSourcePos; } |
| 427 | |
| 428 | void addEntry(const ResTable_config& config, const sp<Entry>& entry) { |
| 429 | mEntries.add(config, entry); |
| 430 | } |
| 431 | |
| 432 | const DefaultKeyedVector<ConfigDescription, sp<Entry> >& getEntries() const { return mEntries; } |
| 433 | private: |
| 434 | const String16 mName; |
| 435 | const SourcePos mPos; |
| 436 | String16 mComment; |
| 437 | String16 mTypeComment; |
| 438 | bool mPublic; |
| 439 | SourcePos mPublicSourcePos; |
| 440 | int32_t mEntryIndex; |
| 441 | DefaultKeyedVector<ConfigDescription, sp<Entry> > mEntries; |
| 442 | }; |
| 443 | |
| 444 | class Public { |
| 445 | public: |
| 446 | Public() : sourcePos(), ident(0) { } |
| 447 | Public(const SourcePos& pos, |
| 448 | const String16& _comment, |
| 449 | uint32_t _ident) |
| 450 | : sourcePos(pos), |
| 451 | comment(_comment), ident(_ident) { } |
| 452 | Public(const Public& o) : sourcePos(o.sourcePos), |
| 453 | comment(o.comment), ident(o.ident) { } |
| 454 | ~Public() { } |
| 455 | |
| 456 | Public& operator=(const Public& o) { |
| 457 | sourcePos = o.sourcePos; |
| 458 | comment = o.comment; |
| 459 | ident = o.ident; |
| 460 | return *this; |
| 461 | } |
| 462 | |
| 463 | SourcePos sourcePos; |
| 464 | String16 comment; |
| 465 | uint32_t ident; |
| 466 | }; |
| 467 | |
| 468 | class Type : public RefBase { |
| 469 | public: |
| 470 | Type(const String16& name, const SourcePos& pos) |
| 471 | : mName(name), mFirstPublicSourcePos(NULL), mPublicIndex(-1), mIndex(-1), mPos(pos) |
| 472 | { } |
| 473 | virtual ~Type() { delete mFirstPublicSourcePos; } |
| 474 | |
| 475 | status_t addPublic(const SourcePos& pos, |
| 476 | const String16& name, |
| 477 | const uint32_t ident); |
| 478 | |
| 479 | void canAddEntry(const String16& name); |
| 480 | |
| 481 | String16 getName() const { return mName; } |
| 482 | sp<Entry> getEntry(const String16& entry, |
| 483 | const SourcePos& pos, |
| 484 | const ResTable_config* config = NULL, |
| 485 | bool doSetIndex = false, |
| 486 | bool overlay = false, |
| 487 | bool autoAddOverlay = false); |
| 488 | |
Adam Lesinski | 9b624c1 | 2014-11-19 17:49:26 -0800 | [diff] [blame] | 489 | bool isPublic(const String16& entry) const { |
| 490 | return mPublic.indexOfKey(entry) >= 0; |
| 491 | } |
| 492 | |
| 493 | sp<ConfigList> removeEntry(const String16& entry); |
| 494 | |
| 495 | SortedVector<ConfigDescription> getUniqueConfigs() const; |
| 496 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 497 | const SourcePos& getFirstPublicSourcePos() const { return *mFirstPublicSourcePos; } |
| 498 | |
| 499 | int32_t getPublicIndex() const { return mPublicIndex; } |
| 500 | |
| 501 | int32_t getIndex() const { return mIndex; } |
| 502 | void setIndex(int32_t index) { mIndex = index; } |
| 503 | |
| 504 | status_t applyPublicEntryOrder(); |
| 505 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 506 | const DefaultKeyedVector<String16, sp<ConfigList> >& getConfigs() const { return mConfigs; } |
| 507 | const Vector<sp<ConfigList> >& getOrderedConfigs() const { return mOrderedConfigs; } |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 508 | const SortedVector<String16>& getCanAddEntries() const { return mCanAddEntries; } |
| 509 | |
| 510 | const SourcePos& getPos() const { return mPos; } |
Adam Lesinski | 9b624c1 | 2014-11-19 17:49:26 -0800 | [diff] [blame] | 511 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 512 | private: |
| 513 | String16 mName; |
| 514 | SourcePos* mFirstPublicSourcePos; |
| 515 | DefaultKeyedVector<String16, Public> mPublic; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 516 | DefaultKeyedVector<String16, sp<ConfigList> > mConfigs; |
| 517 | Vector<sp<ConfigList> > mOrderedConfigs; |
| 518 | SortedVector<String16> mCanAddEntries; |
| 519 | int32_t mPublicIndex; |
| 520 | int32_t mIndex; |
| 521 | SourcePos mPos; |
| 522 | }; |
| 523 | |
| 524 | class Package : public RefBase { |
| 525 | public: |
Adam Lesinski | 833f3cc | 2014-06-18 15:06:01 -0700 | [diff] [blame] | 526 | Package(const String16& name, size_t packageId); |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 527 | virtual ~Package() { } |
| 528 | |
| 529 | String16 getName() const { return mName; } |
| 530 | sp<Type> getType(const String16& type, |
| 531 | const SourcePos& pos, |
| 532 | bool doSetIndex = false); |
| 533 | |
Adam Lesinski | 833f3cc | 2014-06-18 15:06:01 -0700 | [diff] [blame] | 534 | size_t getAssignedId() const { return mPackageId; } |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 535 | |
| 536 | const ResStringPool& getTypeStrings() const { return mTypeStrings; } |
| 537 | uint32_t indexOfTypeString(const String16& s) const { return mTypeStringsMapping.valueFor(s); } |
| 538 | const sp<AaptFile> getTypeStringsData() const { return mTypeStringsData; } |
| 539 | status_t setTypeStrings(const sp<AaptFile>& data); |
| 540 | |
| 541 | const ResStringPool& getKeyStrings() const { return mKeyStrings; } |
| 542 | uint32_t indexOfKeyString(const String16& s) const { return mKeyStringsMapping.valueFor(s); } |
| 543 | const sp<AaptFile> getKeyStringsData() const { return mKeyStringsData; } |
| 544 | status_t setKeyStrings(const sp<AaptFile>& data); |
| 545 | |
| 546 | status_t applyPublicTypeOrder(); |
| 547 | |
| 548 | const DefaultKeyedVector<String16, sp<Type> >& getTypes() const { return mTypes; } |
| 549 | const Vector<sp<Type> >& getOrderedTypes() const { return mOrderedTypes; } |
| 550 | |
Adam Lesinski | 9b624c1 | 2014-11-19 17:49:26 -0800 | [diff] [blame] | 551 | void movePrivateAttrs(); |
| 552 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 553 | private: |
| 554 | status_t setStrings(const sp<AaptFile>& data, |
| 555 | ResStringPool* strings, |
| 556 | DefaultKeyedVector<String16, uint32_t>* mappings); |
| 557 | |
| 558 | const String16 mName; |
Adam Lesinski | 833f3cc | 2014-06-18 15:06:01 -0700 | [diff] [blame] | 559 | const size_t mPackageId; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 560 | DefaultKeyedVector<String16, sp<Type> > mTypes; |
| 561 | Vector<sp<Type> > mOrderedTypes; |
| 562 | sp<AaptFile> mTypeStringsData; |
| 563 | sp<AaptFile> mKeyStringsData; |
| 564 | ResStringPool mTypeStrings; |
| 565 | ResStringPool mKeyStrings; |
| 566 | DefaultKeyedVector<String16, uint32_t> mTypeStringsMapping; |
| 567 | DefaultKeyedVector<String16, uint32_t> mKeyStringsMapping; |
| 568 | }; |
| 569 | |
Adam Lesinski | de7de47 | 2014-11-03 12:03:08 -0800 | [diff] [blame] | 570 | void getDensityVaryingResources(KeyedVector<Symbol, Vector<SymbolDefinition> >& resources); |
| 571 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 572 | private: |
| 573 | void writePublicDefinitions(const String16& package, FILE* fp, bool pub); |
| 574 | sp<Package> getPackage(const String16& package); |
| 575 | sp<Type> getType(const String16& package, |
| 576 | const String16& type, |
| 577 | const SourcePos& pos, |
| 578 | bool doSetIndex = false); |
| 579 | sp<Entry> getEntry(const String16& package, |
| 580 | const String16& type, |
| 581 | const String16& name, |
| 582 | const SourcePos& pos, |
| 583 | bool overlay, |
| 584 | const ResTable_config* config = NULL, |
| 585 | bool doSetIndex = false); |
| 586 | sp<const Entry> getEntry(uint32_t resID, |
| 587 | const ResTable_config* config = NULL) const; |
Adam Lesinski | e572c01 | 2014-09-19 15:10:04 -0700 | [diff] [blame] | 588 | sp<ConfigList> getConfigList(const String16& package, |
| 589 | const String16& type, |
| 590 | const String16& name) const; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 591 | const Item* getItem(uint32_t resID, uint32_t attrID) const; |
| 592 | bool getItemValue(uint32_t resID, uint32_t attrID, |
| 593 | Res_value* outValue); |
Adam Lesinski | 28994d8 | 2015-01-13 13:42:41 -0800 | [diff] [blame] | 594 | int getPublicAttributeSdkLevel(uint32_t attrId) const; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 595 | |
Adam Lesinski | 9d0f7d4 | 2015-10-28 15:44:27 -0700 | [diff] [blame^] | 596 | status_t processBundleFormatImpl(const Bundle* bundle, |
| 597 | const String16& resourceName, |
| 598 | const sp<AaptFile>& file, |
| 599 | const sp<XMLNode>& parent, |
| 600 | Vector<sp<XMLNode> >* namespaces); |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 601 | |
| 602 | String16 mAssetsPackage; |
Adam Lesinski | 833f3cc | 2014-06-18 15:06:01 -0700 | [diff] [blame] | 603 | PackageType mPackageType; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 604 | sp<AaptAssets> mAssets; |
Adam Lesinski | 833f3cc | 2014-06-18 15:06:01 -0700 | [diff] [blame] | 605 | uint32_t mTypeIdOffset; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 606 | DefaultKeyedVector<String16, sp<Package> > mPackages; |
| 607 | Vector<sp<Package> > mOrderedPackages; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 608 | size_t mNumLocal; |
| 609 | SourcePos mCurrentXmlPos; |
| 610 | Bundle* mBundle; |
Dan Albert | 030f536 | 2015-03-04 13:54:20 -0800 | [diff] [blame] | 611 | |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 612 | // key = string resource name, value = set of locales in which that name is defined |
Dan Albert | 030f536 | 2015-03-04 13:54:20 -0800 | [diff] [blame] | 613 | std::map<String16, std::map<String8, SourcePos>> mLocalizations; |
Adrian Roos | 5892248 | 2015-06-01 17:59:41 -0700 | [diff] [blame] | 614 | // set of string resources names that have a default localization |
| 615 | std::set<String16> mHasDefaultLocalization; |
Dan Albert | 030f536 | 2015-03-04 13:54:20 -0800 | [diff] [blame] | 616 | std::queue<CompileResourceWorkItem> mWorkQueue; |
Adam Lesinski | 282e181 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 617 | }; |
| 618 | |
| 619 | #endif |