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