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