ResourceTypes.h revision d4b169173ad7805369204277580d3942cb08174a
1/* 2 * Copyright (C) 2005 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17// 18// Definitions of resource data structures. 19// 20#ifndef _LIBS_UTILS_RESOURCE_TYPES_H 21#define _LIBS_UTILS_RESOURCE_TYPES_H 22 23#include <androidfw/Asset.h> 24#include <androidfw/LocaleData.h> 25#include <utils/ByteOrder.h> 26#include <utils/Errors.h> 27#include <utils/String16.h> 28#include <utils/Vector.h> 29#include <utils/KeyedVector.h> 30 31#include <utils/threads.h> 32 33#include <stdint.h> 34#include <sys/types.h> 35 36#include <android/configuration.h> 37 38namespace android { 39 40/** 41 * In C++11, char16_t is defined as *at least* 16 bits. We do a lot of 42 * casting on raw data and expect char16_t to be exactly 16 bits. 43 */ 44#if __cplusplus >= 201103L 45struct __assertChar16Size { 46 static_assert(sizeof(char16_t) == sizeof(uint16_t), "char16_t is not 16 bits"); 47 static_assert(alignof(char16_t) == alignof(uint16_t), "char16_t is not 16-bit aligned"); 48}; 49#endif 50 51/** ******************************************************************** 52 * PNG Extensions 53 * 54 * New private chunks that may be placed in PNG images. 55 * 56 *********************************************************************** */ 57 58/** 59 * This chunk specifies how to split an image into segments for 60 * scaling. 61 * 62 * There are J horizontal and K vertical segments. These segments divide 63 * the image into J*K regions as follows (where J=4 and K=3): 64 * 65 * F0 S0 F1 S1 66 * +-----+----+------+-------+ 67 * S2| 0 | 1 | 2 | 3 | 68 * +-----+----+------+-------+ 69 * | | | | | 70 * | | | | | 71 * F2| 4 | 5 | 6 | 7 | 72 * | | | | | 73 * | | | | | 74 * +-----+----+------+-------+ 75 * S3| 8 | 9 | 10 | 11 | 76 * +-----+----+------+-------+ 77 * 78 * Each horizontal and vertical segment is considered to by either 79 * stretchable (marked by the Sx labels) or fixed (marked by the Fy 80 * labels), in the horizontal or vertical axis, respectively. In the 81 * above example, the first is horizontal segment (F0) is fixed, the 82 * next is stretchable and then they continue to alternate. Note that 83 * the segment list for each axis can begin or end with a stretchable 84 * or fixed segment. 85 * 86 * The relative sizes of the stretchy segments indicates the relative 87 * amount of stretchiness of the regions bordered by the segments. For 88 * example, regions 3, 7 and 11 above will take up more horizontal space 89 * than regions 1, 5 and 9 since the horizontal segment associated with 90 * the first set of regions is larger than the other set of regions. The 91 * ratios of the amount of horizontal (or vertical) space taken by any 92 * two stretchable slices is exactly the ratio of their corresponding 93 * segment lengths. 94 * 95 * xDivs and yDivs are arrays of horizontal and vertical pixel 96 * indices. The first pair of Divs (in either array) indicate the 97 * starting and ending points of the first stretchable segment in that 98 * axis. The next pair specifies the next stretchable segment, etc. So 99 * in the above example xDiv[0] and xDiv[1] specify the horizontal 100 * coordinates for the regions labeled 1, 5 and 9. xDiv[2] and 101 * xDiv[3] specify the coordinates for regions 3, 7 and 11. Note that 102 * the leftmost slices always start at x=0 and the rightmost slices 103 * always end at the end of the image. So, for example, the regions 0, 104 * 4 and 8 (which are fixed along the X axis) start at x value 0 and 105 * go to xDiv[0] and slices 2, 6 and 10 start at xDiv[1] and end at 106 * xDiv[2]. 107 * 108 * The colors array contains hints for each of the regions. They are 109 * ordered according left-to-right and top-to-bottom as indicated above. 110 * For each segment that is a solid color the array entry will contain 111 * that color value; otherwise it will contain NO_COLOR. Segments that 112 * are completely transparent will always have the value TRANSPARENT_COLOR. 113 * 114 * The PNG chunk type is "npTc". 115 */ 116struct alignas(uintptr_t) Res_png_9patch 117{ 118 Res_png_9patch() : wasDeserialized(false), xDivsOffset(0), 119 yDivsOffset(0), colorsOffset(0) { } 120 121 int8_t wasDeserialized; 122 uint8_t numXDivs; 123 uint8_t numYDivs; 124 uint8_t numColors; 125 126 // The offset (from the start of this structure) to the xDivs & yDivs 127 // array for this 9patch. To get a pointer to this array, call 128 // getXDivs or getYDivs. Note that the serialized form for 9patches places 129 // the xDivs, yDivs and colors arrays immediately after the location 130 // of the Res_png_9patch struct. 131 uint32_t xDivsOffset; 132 uint32_t yDivsOffset; 133 134 int32_t paddingLeft, paddingRight; 135 int32_t paddingTop, paddingBottom; 136 137 enum { 138 // The 9 patch segment is not a solid color. 139 NO_COLOR = 0x00000001, 140 141 // The 9 patch segment is completely transparent. 142 TRANSPARENT_COLOR = 0x00000000 143 }; 144 145 // The offset (from the start of this structure) to the colors array 146 // for this 9patch. 147 uint32_t colorsOffset; 148 149 // Convert data from device representation to PNG file representation. 150 void deviceToFile(); 151 // Convert data from PNG file representation to device representation. 152 void fileToDevice(); 153 154 // Serialize/Marshall the patch data into a newly malloc-ed block. 155 static void* serialize(const Res_png_9patch& patchHeader, const int32_t* xDivs, 156 const int32_t* yDivs, const uint32_t* colors); 157 // Serialize/Marshall the patch data into |outData|. 158 static void serialize(const Res_png_9patch& patchHeader, const int32_t* xDivs, 159 const int32_t* yDivs, const uint32_t* colors, void* outData); 160 // Deserialize/Unmarshall the patch data 161 static Res_png_9patch* deserialize(void* data); 162 // Compute the size of the serialized data structure 163 size_t serializedSize() const; 164 165 // These tell where the next section of a patch starts. 166 // For example, the first patch includes the pixels from 167 // 0 to xDivs[0]-1 and the second patch includes the pixels 168 // from xDivs[0] to xDivs[1]-1. 169 inline int32_t* getXDivs() const { 170 return reinterpret_cast<int32_t*>(reinterpret_cast<uintptr_t>(this) + xDivsOffset); 171 } 172 inline int32_t* getYDivs() const { 173 return reinterpret_cast<int32_t*>(reinterpret_cast<uintptr_t>(this) + yDivsOffset); 174 } 175 inline uint32_t* getColors() const { 176 return reinterpret_cast<uint32_t*>(reinterpret_cast<uintptr_t>(this) + colorsOffset); 177 } 178 179} __attribute__((packed)); 180 181/** ******************************************************************** 182 * Base Types 183 * 184 * These are standard types that are shared between multiple specific 185 * resource types. 186 * 187 *********************************************************************** */ 188 189/** 190 * Header that appears at the front of every data chunk in a resource. 191 */ 192struct ResChunk_header 193{ 194 // Type identifier for this chunk. The meaning of this value depends 195 // on the containing chunk. 196 uint16_t type; 197 198 // Size of the chunk header (in bytes). Adding this value to 199 // the address of the chunk allows you to find its associated data 200 // (if any). 201 uint16_t headerSize; 202 203 // Total size of this chunk (in bytes). This is the chunkSize plus 204 // the size of any data associated with the chunk. Adding this value 205 // to the chunk allows you to completely skip its contents (including 206 // any child chunks). If this value is the same as chunkSize, there is 207 // no data associated with the chunk. 208 uint32_t size; 209}; 210 211enum { 212 RES_NULL_TYPE = 0x0000, 213 RES_STRING_POOL_TYPE = 0x0001, 214 RES_TABLE_TYPE = 0x0002, 215 RES_XML_TYPE = 0x0003, 216 217 // Chunk types in RES_XML_TYPE 218 RES_XML_FIRST_CHUNK_TYPE = 0x0100, 219 RES_XML_START_NAMESPACE_TYPE= 0x0100, 220 RES_XML_END_NAMESPACE_TYPE = 0x0101, 221 RES_XML_START_ELEMENT_TYPE = 0x0102, 222 RES_XML_END_ELEMENT_TYPE = 0x0103, 223 RES_XML_CDATA_TYPE = 0x0104, 224 RES_XML_LAST_CHUNK_TYPE = 0x017f, 225 // This contains a uint32_t array mapping strings in the string 226 // pool back to resource identifiers. It is optional. 227 RES_XML_RESOURCE_MAP_TYPE = 0x0180, 228 229 // Chunk types in RES_TABLE_TYPE 230 RES_TABLE_PACKAGE_TYPE = 0x0200, 231 RES_TABLE_TYPE_TYPE = 0x0201, 232 RES_TABLE_TYPE_SPEC_TYPE = 0x0202, 233 RES_TABLE_LIBRARY_TYPE = 0x0203 234}; 235 236/** 237 * Macros for building/splitting resource identifiers. 238 */ 239#define Res_VALIDID(resid) (resid != 0) 240#define Res_CHECKID(resid) ((resid&0xFFFF0000) != 0) 241#define Res_MAKEID(package, type, entry) \ 242 (((package+1)<<24) | (((type+1)&0xFF)<<16) | (entry&0xFFFF)) 243#define Res_GETPACKAGE(id) ((id>>24)-1) 244#define Res_GETTYPE(id) (((id>>16)&0xFF)-1) 245#define Res_GETENTRY(id) (id&0xFFFF) 246 247#define Res_INTERNALID(resid) ((resid&0xFFFF0000) != 0 && (resid&0xFF0000) == 0) 248#define Res_MAKEINTERNAL(entry) (0x01000000 | (entry&0xFFFF)) 249#define Res_MAKEARRAY(entry) (0x02000000 | (entry&0xFFFF)) 250 251static const size_t Res_MAXPACKAGE = 255; 252static const size_t Res_MAXTYPE = 255; 253 254/** 255 * Representation of a value in a resource, supplying type 256 * information. 257 */ 258struct Res_value 259{ 260 // Number of bytes in this structure. 261 uint16_t size; 262 263 // Always set to 0. 264 uint8_t res0; 265 266 // Type of the data value. 267 enum { 268 // The 'data' is either 0 or 1, specifying this resource is either 269 // undefined or empty, respectively. 270 TYPE_NULL = 0x00, 271 // The 'data' holds a ResTable_ref, a reference to another resource 272 // table entry. 273 TYPE_REFERENCE = 0x01, 274 // The 'data' holds an attribute resource identifier. 275 TYPE_ATTRIBUTE = 0x02, 276 // The 'data' holds an index into the containing resource table's 277 // global value string pool. 278 TYPE_STRING = 0x03, 279 // The 'data' holds a single-precision floating point number. 280 TYPE_FLOAT = 0x04, 281 // The 'data' holds a complex number encoding a dimension value, 282 // such as "100in". 283 TYPE_DIMENSION = 0x05, 284 // The 'data' holds a complex number encoding a fraction of a 285 // container. 286 TYPE_FRACTION = 0x06, 287 // The 'data' holds a dynamic ResTable_ref, which needs to be 288 // resolved before it can be used like a TYPE_REFERENCE. 289 TYPE_DYNAMIC_REFERENCE = 0x07, 290 291 // Beginning of integer flavors... 292 TYPE_FIRST_INT = 0x10, 293 294 // The 'data' is a raw integer value of the form n..n. 295 TYPE_INT_DEC = 0x10, 296 // The 'data' is a raw integer value of the form 0xn..n. 297 TYPE_INT_HEX = 0x11, 298 // The 'data' is either 0 or 1, for input "false" or "true" respectively. 299 TYPE_INT_BOOLEAN = 0x12, 300 301 // Beginning of color integer flavors... 302 TYPE_FIRST_COLOR_INT = 0x1c, 303 304 // The 'data' is a raw integer value of the form #aarrggbb. 305 TYPE_INT_COLOR_ARGB8 = 0x1c, 306 // The 'data' is a raw integer value of the form #rrggbb. 307 TYPE_INT_COLOR_RGB8 = 0x1d, 308 // The 'data' is a raw integer value of the form #argb. 309 TYPE_INT_COLOR_ARGB4 = 0x1e, 310 // The 'data' is a raw integer value of the form #rgb. 311 TYPE_INT_COLOR_RGB4 = 0x1f, 312 313 // ...end of integer flavors. 314 TYPE_LAST_COLOR_INT = 0x1f, 315 316 // ...end of integer flavors. 317 TYPE_LAST_INT = 0x1f 318 }; 319 uint8_t dataType; 320 321 // Structure of complex data values (TYPE_UNIT and TYPE_FRACTION) 322 enum { 323 // Where the unit type information is. This gives us 16 possible 324 // types, as defined below. 325 COMPLEX_UNIT_SHIFT = 0, 326 COMPLEX_UNIT_MASK = 0xf, 327 328 // TYPE_DIMENSION: Value is raw pixels. 329 COMPLEX_UNIT_PX = 0, 330 // TYPE_DIMENSION: Value is Device Independent Pixels. 331 COMPLEX_UNIT_DIP = 1, 332 // TYPE_DIMENSION: Value is a Scaled device independent Pixels. 333 COMPLEX_UNIT_SP = 2, 334 // TYPE_DIMENSION: Value is in points. 335 COMPLEX_UNIT_PT = 3, 336 // TYPE_DIMENSION: Value is in inches. 337 COMPLEX_UNIT_IN = 4, 338 // TYPE_DIMENSION: Value is in millimeters. 339 COMPLEX_UNIT_MM = 5, 340 341 // TYPE_FRACTION: A basic fraction of the overall size. 342 COMPLEX_UNIT_FRACTION = 0, 343 // TYPE_FRACTION: A fraction of the parent size. 344 COMPLEX_UNIT_FRACTION_PARENT = 1, 345 346 // Where the radix information is, telling where the decimal place 347 // appears in the mantissa. This give us 4 possible fixed point 348 // representations as defined below. 349 COMPLEX_RADIX_SHIFT = 4, 350 COMPLEX_RADIX_MASK = 0x3, 351 352 // The mantissa is an integral number -- i.e., 0xnnnnnn.0 353 COMPLEX_RADIX_23p0 = 0, 354 // The mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn 355 COMPLEX_RADIX_16p7 = 1, 356 // The mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn 357 COMPLEX_RADIX_8p15 = 2, 358 // The mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn 359 COMPLEX_RADIX_0p23 = 3, 360 361 // Where the actual value is. This gives us 23 bits of 362 // precision. The top bit is the sign. 363 COMPLEX_MANTISSA_SHIFT = 8, 364 COMPLEX_MANTISSA_MASK = 0xffffff 365 }; 366 367 // Possible data values for TYPE_NULL. 368 enum { 369 // The value is not defined. 370 DATA_NULL_UNDEFINED = 0, 371 // The value is explicitly defined as empty. 372 DATA_NULL_EMPTY = 1 373 }; 374 375 // The data for this item, as interpreted according to dataType. 376 typedef uint32_t data_type; 377 data_type data; 378 379 void copyFrom_dtoh(const Res_value& src); 380}; 381 382/** 383 * This is a reference to a unique entry (a ResTable_entry structure) 384 * in a resource table. The value is structured as: 0xpptteeee, 385 * where pp is the package index, tt is the type index in that 386 * package, and eeee is the entry index in that type. The package 387 * and type values start at 1 for the first item, to help catch cases 388 * where they have not been supplied. 389 */ 390struct ResTable_ref 391{ 392 uint32_t ident; 393}; 394 395/** 396 * Reference to a string in a string pool. 397 */ 398struct ResStringPool_ref 399{ 400 // Index into the string pool table (uint32_t-offset from the indices 401 // immediately after ResStringPool_header) at which to find the location 402 // of the string data in the pool. 403 uint32_t index; 404}; 405 406/** ******************************************************************** 407 * String Pool 408 * 409 * A set of strings that can be references by others through a 410 * ResStringPool_ref. 411 * 412 *********************************************************************** */ 413 414/** 415 * Definition for a pool of strings. The data of this chunk is an 416 * array of uint32_t providing indices into the pool, relative to 417 * stringsStart. At stringsStart are all of the UTF-16 strings 418 * concatenated together; each starts with a uint16_t of the string's 419 * length and each ends with a 0x0000 terminator. If a string is > 420 * 32767 characters, the high bit of the length is set meaning to take 421 * those 15 bits as a high word and it will be followed by another 422 * uint16_t containing the low word. 423 * 424 * If styleCount is not zero, then immediately following the array of 425 * uint32_t indices into the string table is another array of indices 426 * into a style table starting at stylesStart. Each entry in the 427 * style table is an array of ResStringPool_span structures. 428 */ 429struct ResStringPool_header 430{ 431 struct ResChunk_header header; 432 433 // Number of strings in this pool (number of uint32_t indices that follow 434 // in the data). 435 uint32_t stringCount; 436 437 // Number of style span arrays in the pool (number of uint32_t indices 438 // follow the string indices). 439 uint32_t styleCount; 440 441 // Flags. 442 enum { 443 // If set, the string index is sorted by the string values (based 444 // on strcmp16()). 445 SORTED_FLAG = 1<<0, 446 447 // String pool is encoded in UTF-8 448 UTF8_FLAG = 1<<8 449 }; 450 uint32_t flags; 451 452 // Index from header of the string data. 453 uint32_t stringsStart; 454 455 // Index from header of the style data. 456 uint32_t stylesStart; 457}; 458 459/** 460 * This structure defines a span of style information associated with 461 * a string in the pool. 462 */ 463struct ResStringPool_span 464{ 465 enum { 466 END = 0xFFFFFFFF 467 }; 468 469 // This is the name of the span -- that is, the name of the XML 470 // tag that defined it. The special value END (0xFFFFFFFF) indicates 471 // the end of an array of spans. 472 ResStringPool_ref name; 473 474 // The range of characters in the string that this span applies to. 475 uint32_t firstChar, lastChar; 476}; 477 478/** 479 * Convenience class for accessing data in a ResStringPool resource. 480 */ 481class ResStringPool 482{ 483public: 484 ResStringPool(); 485 ResStringPool(const void* data, size_t size, bool copyData=false); 486 ~ResStringPool(); 487 488 void setToEmpty(); 489 status_t setTo(const void* data, size_t size, bool copyData=false); 490 491 status_t getError() const; 492 493 void uninit(); 494 495 // Return string entry as UTF16; if the pool is UTF8, the string will 496 // be converted before returning. 497 inline const char16_t* stringAt(const ResStringPool_ref& ref, size_t* outLen) const { 498 return stringAt(ref.index, outLen); 499 } 500 const char16_t* stringAt(size_t idx, size_t* outLen) const; 501 502 // Note: returns null if the string pool is not UTF8. 503 const char* string8At(size_t idx, size_t* outLen) const; 504 505 // Return string whether the pool is UTF8 or UTF16. Does not allow you 506 // to distinguish null. 507 const String8 string8ObjectAt(size_t idx) const; 508 509 const ResStringPool_span* styleAt(const ResStringPool_ref& ref) const; 510 const ResStringPool_span* styleAt(size_t idx) const; 511 512 ssize_t indexOfString(const char16_t* str, size_t strLen) const; 513 514 size_t size() const; 515 size_t styleCount() const; 516 size_t bytes() const; 517 518 bool isSorted() const; 519 bool isUTF8() const; 520 521private: 522 status_t mError; 523 void* mOwnedData; 524 const ResStringPool_header* mHeader; 525 size_t mSize; 526 mutable Mutex mDecodeLock; 527 const uint32_t* mEntries; 528 const uint32_t* mEntryStyles; 529 const void* mStrings; 530 char16_t mutable** mCache; 531 uint32_t mStringPoolSize; // number of uint16_t 532 const uint32_t* mStyles; 533 uint32_t mStylePoolSize; // number of uint32_t 534}; 535 536/** 537 * Wrapper class that allows the caller to retrieve a string from 538 * a string pool without knowing which string pool to look. 539 */ 540class StringPoolRef { 541public: 542 StringPoolRef(); 543 StringPoolRef(const ResStringPool* pool, uint32_t index); 544 545 const char* string8(size_t* outLen) const; 546 const char16_t* string16(size_t* outLen) const; 547 548private: 549 const ResStringPool* mPool; 550 uint32_t mIndex; 551}; 552 553/** ******************************************************************** 554 * XML Tree 555 * 556 * Binary representation of an XML document. This is designed to 557 * express everything in an XML document, in a form that is much 558 * easier to parse on the device. 559 * 560 *********************************************************************** */ 561 562/** 563 * XML tree header. This appears at the front of an XML tree, 564 * describing its content. It is followed by a flat array of 565 * ResXMLTree_node structures; the hierarchy of the XML document 566 * is described by the occurrance of RES_XML_START_ELEMENT_TYPE 567 * and corresponding RES_XML_END_ELEMENT_TYPE nodes in the array. 568 */ 569struct ResXMLTree_header 570{ 571 struct ResChunk_header header; 572}; 573 574/** 575 * Basic XML tree node. A single item in the XML document. Extended info 576 * about the node can be found after header.headerSize. 577 */ 578struct ResXMLTree_node 579{ 580 struct ResChunk_header header; 581 582 // Line number in original source file at which this element appeared. 583 uint32_t lineNumber; 584 585 // Optional XML comment that was associated with this element; -1 if none. 586 struct ResStringPool_ref comment; 587}; 588 589/** 590 * Extended XML tree node for CDATA tags -- includes the CDATA string. 591 * Appears header.headerSize bytes after a ResXMLTree_node. 592 */ 593struct ResXMLTree_cdataExt 594{ 595 // The raw CDATA character data. 596 struct ResStringPool_ref data; 597 598 // The typed value of the character data if this is a CDATA node. 599 struct Res_value typedData; 600}; 601 602/** 603 * Extended XML tree node for namespace start/end nodes. 604 * Appears header.headerSize bytes after a ResXMLTree_node. 605 */ 606struct ResXMLTree_namespaceExt 607{ 608 // The prefix of the namespace. 609 struct ResStringPool_ref prefix; 610 611 // The URI of the namespace. 612 struct ResStringPool_ref uri; 613}; 614 615/** 616 * Extended XML tree node for element start/end nodes. 617 * Appears header.headerSize bytes after a ResXMLTree_node. 618 */ 619struct ResXMLTree_endElementExt 620{ 621 // String of the full namespace of this element. 622 struct ResStringPool_ref ns; 623 624 // String name of this node if it is an ELEMENT; the raw 625 // character data if this is a CDATA node. 626 struct ResStringPool_ref name; 627}; 628 629/** 630 * Extended XML tree node for start tags -- includes attribute 631 * information. 632 * Appears header.headerSize bytes after a ResXMLTree_node. 633 */ 634struct ResXMLTree_attrExt 635{ 636 // String of the full namespace of this element. 637 struct ResStringPool_ref ns; 638 639 // String name of this node if it is an ELEMENT; the raw 640 // character data if this is a CDATA node. 641 struct ResStringPool_ref name; 642 643 // Byte offset from the start of this structure where the attributes start. 644 uint16_t attributeStart; 645 646 // Size of the ResXMLTree_attribute structures that follow. 647 uint16_t attributeSize; 648 649 // Number of attributes associated with an ELEMENT. These are 650 // available as an array of ResXMLTree_attribute structures 651 // immediately following this node. 652 uint16_t attributeCount; 653 654 // Index (1-based) of the "id" attribute. 0 if none. 655 uint16_t idIndex; 656 657 // Index (1-based) of the "class" attribute. 0 if none. 658 uint16_t classIndex; 659 660 // Index (1-based) of the "style" attribute. 0 if none. 661 uint16_t styleIndex; 662}; 663 664struct ResXMLTree_attribute 665{ 666 // Namespace of this attribute. 667 struct ResStringPool_ref ns; 668 669 // Name of this attribute. 670 struct ResStringPool_ref name; 671 672 // The original raw string value of this attribute. 673 struct ResStringPool_ref rawValue; 674 675 // Processesd typed value of this attribute. 676 struct Res_value typedValue; 677}; 678 679class ResXMLTree; 680 681class ResXMLParser 682{ 683public: 684 ResXMLParser(const ResXMLTree& tree); 685 686 enum event_code_t { 687 BAD_DOCUMENT = -1, 688 START_DOCUMENT = 0, 689 END_DOCUMENT = 1, 690 691 FIRST_CHUNK_CODE = RES_XML_FIRST_CHUNK_TYPE, 692 693 START_NAMESPACE = RES_XML_START_NAMESPACE_TYPE, 694 END_NAMESPACE = RES_XML_END_NAMESPACE_TYPE, 695 START_TAG = RES_XML_START_ELEMENT_TYPE, 696 END_TAG = RES_XML_END_ELEMENT_TYPE, 697 TEXT = RES_XML_CDATA_TYPE 698 }; 699 700 struct ResXMLPosition 701 { 702 event_code_t eventCode; 703 const ResXMLTree_node* curNode; 704 const void* curExt; 705 }; 706 707 void restart(); 708 709 const ResStringPool& getStrings() const; 710 711 event_code_t getEventType() const; 712 // Note, unlike XmlPullParser, the first call to next() will return 713 // START_TAG of the first element. 714 event_code_t next(); 715 716 // These are available for all nodes: 717 int32_t getCommentID() const; 718 const char16_t* getComment(size_t* outLen) const; 719 uint32_t getLineNumber() const; 720 721 // This is available for TEXT: 722 int32_t getTextID() const; 723 const char16_t* getText(size_t* outLen) const; 724 ssize_t getTextValue(Res_value* outValue) const; 725 726 // These are available for START_NAMESPACE and END_NAMESPACE: 727 int32_t getNamespacePrefixID() const; 728 const char16_t* getNamespacePrefix(size_t* outLen) const; 729 int32_t getNamespaceUriID() const; 730 const char16_t* getNamespaceUri(size_t* outLen) const; 731 732 // These are available for START_TAG and END_TAG: 733 int32_t getElementNamespaceID() const; 734 const char16_t* getElementNamespace(size_t* outLen) const; 735 int32_t getElementNameID() const; 736 const char16_t* getElementName(size_t* outLen) const; 737 738 // Remaining methods are for retrieving information about attributes 739 // associated with a START_TAG: 740 741 size_t getAttributeCount() const; 742 743 // Returns -1 if no namespace, -2 if idx out of range. 744 int32_t getAttributeNamespaceID(size_t idx) const; 745 const char16_t* getAttributeNamespace(size_t idx, size_t* outLen) const; 746 747 int32_t getAttributeNameID(size_t idx) const; 748 const char16_t* getAttributeName(size_t idx, size_t* outLen) const; 749 uint32_t getAttributeNameResID(size_t idx) const; 750 751 // These will work only if the underlying string pool is UTF-8. 752 const char* getAttributeNamespace8(size_t idx, size_t* outLen) const; 753 const char* getAttributeName8(size_t idx, size_t* outLen) const; 754 755 int32_t getAttributeValueStringID(size_t idx) const; 756 const char16_t* getAttributeStringValue(size_t idx, size_t* outLen) const; 757 758 int32_t getAttributeDataType(size_t idx) const; 759 int32_t getAttributeData(size_t idx) const; 760 ssize_t getAttributeValue(size_t idx, Res_value* outValue) const; 761 762 ssize_t indexOfAttribute(const char* ns, const char* attr) const; 763 ssize_t indexOfAttribute(const char16_t* ns, size_t nsLen, 764 const char16_t* attr, size_t attrLen) const; 765 766 ssize_t indexOfID() const; 767 ssize_t indexOfClass() const; 768 ssize_t indexOfStyle() const; 769 770 void getPosition(ResXMLPosition* pos) const; 771 void setPosition(const ResXMLPosition& pos); 772 773private: 774 friend class ResXMLTree; 775 776 event_code_t nextNode(); 777 778 const ResXMLTree& mTree; 779 event_code_t mEventCode; 780 const ResXMLTree_node* mCurNode; 781 const void* mCurExt; 782}; 783 784class DynamicRefTable; 785 786/** 787 * Convenience class for accessing data in a ResXMLTree resource. 788 */ 789class ResXMLTree : public ResXMLParser 790{ 791public: 792 ResXMLTree(const DynamicRefTable* dynamicRefTable); 793 ResXMLTree(); 794 ~ResXMLTree(); 795 796 status_t setTo(const void* data, size_t size, bool copyData=false); 797 798 status_t getError() const; 799 800 void uninit(); 801 802private: 803 friend class ResXMLParser; 804 805 status_t validateNode(const ResXMLTree_node* node) const; 806 807 const DynamicRefTable* const mDynamicRefTable; 808 809 status_t mError; 810 void* mOwnedData; 811 const ResXMLTree_header* mHeader; 812 size_t mSize; 813 const uint8_t* mDataEnd; 814 ResStringPool mStrings; 815 const uint32_t* mResIds; 816 size_t mNumResIds; 817 const ResXMLTree_node* mRootNode; 818 const void* mRootExt; 819 event_code_t mRootCode; 820}; 821 822/** ******************************************************************** 823 * RESOURCE TABLE 824 * 825 *********************************************************************** */ 826 827/** 828 * Header for a resource table. Its data contains a series of 829 * additional chunks: 830 * * A ResStringPool_header containing all table values. This string pool 831 * contains all of the string values in the entire resource table (not 832 * the names of entries or type identifiers however). 833 * * One or more ResTable_package chunks. 834 * 835 * Specific entries within a resource table can be uniquely identified 836 * with a single integer as defined by the ResTable_ref structure. 837 */ 838struct ResTable_header 839{ 840 struct ResChunk_header header; 841 842 // The number of ResTable_package structures. 843 uint32_t packageCount; 844}; 845 846/** 847 * A collection of resource data types within a package. Followed by 848 * one or more ResTable_type and ResTable_typeSpec structures containing the 849 * entry values for each resource type. 850 */ 851struct ResTable_package 852{ 853 struct ResChunk_header header; 854 855 // If this is a base package, its ID. Package IDs start 856 // at 1 (corresponding to the value of the package bits in a 857 // resource identifier). 0 means this is not a base package. 858 uint32_t id; 859 860 // Actual name of this package, \0-terminated. 861 uint16_t name[128]; 862 863 // Offset to a ResStringPool_header defining the resource 864 // type symbol table. If zero, this package is inheriting from 865 // another base package (overriding specific values in it). 866 uint32_t typeStrings; 867 868 // Last index into typeStrings that is for public use by others. 869 uint32_t lastPublicType; 870 871 // Offset to a ResStringPool_header defining the resource 872 // key symbol table. If zero, this package is inheriting from 873 // another base package (overriding specific values in it). 874 uint32_t keyStrings; 875 876 // Last index into keyStrings that is for public use by others. 877 uint32_t lastPublicKey; 878 879 uint32_t typeIdOffset; 880}; 881 882// The most specific locale can consist of: 883// 884// - a 3 char language code 885// - a 3 char region code prefixed by a 'r' 886// - a 4 char script code prefixed by a 's' 887// - a 8 char variant code prefixed by a 'v' 888// 889// each separated by a single char separator, which sums up to a total of 24 890// chars, (25 include the string terminator) rounded up to 28 to be 4 byte 891// aligned. 892#define RESTABLE_MAX_LOCALE_LEN 28 893 894 895/** 896 * Describes a particular resource configuration. 897 */ 898struct ResTable_config 899{ 900 // Number of bytes in this structure. 901 uint32_t size; 902 903 union { 904 struct { 905 // Mobile country code (from SIM). 0 means "any". 906 uint16_t mcc; 907 // Mobile network code (from SIM). 0 means "any". 908 uint16_t mnc; 909 }; 910 uint32_t imsi; 911 }; 912 913 union { 914 struct { 915 // This field can take three different forms: 916 // - \0\0 means "any". 917 // 918 // - Two 7 bit ascii values interpreted as ISO-639-1 language 919 // codes ('fr', 'en' etc. etc.). The high bit for both bytes is 920 // zero. 921 // 922 // - A single 16 bit little endian packed value representing an 923 // ISO-639-2 3 letter language code. This will be of the form: 924 // 925 // {1, t, t, t, t, t, s, s, s, s, s, f, f, f, f, f} 926 // 927 // bit[0, 4] = first letter of the language code 928 // bit[5, 9] = second letter of the language code 929 // bit[10, 14] = third letter of the language code. 930 // bit[15] = 1 always 931 // 932 // For backwards compatibility, languages that have unambiguous 933 // two letter codes are represented in that format. 934 // 935 // The layout is always bigendian irrespective of the runtime 936 // architecture. 937 char language[2]; 938 939 // This field can take three different forms: 940 // - \0\0 means "any". 941 // 942 // - Two 7 bit ascii values interpreted as 2 letter region 943 // codes ('US', 'GB' etc.). The high bit for both bytes is zero. 944 // 945 // - An UN M.49 3 digit region code. For simplicity, these are packed 946 // in the same manner as the language codes, though we should need 947 // only 10 bits to represent them, instead of the 15. 948 // 949 // The layout is always bigendian irrespective of the runtime 950 // architecture. 951 char country[2]; 952 }; 953 uint32_t locale; 954 }; 955 956 enum { 957 ORIENTATION_ANY = ACONFIGURATION_ORIENTATION_ANY, 958 ORIENTATION_PORT = ACONFIGURATION_ORIENTATION_PORT, 959 ORIENTATION_LAND = ACONFIGURATION_ORIENTATION_LAND, 960 ORIENTATION_SQUARE = ACONFIGURATION_ORIENTATION_SQUARE, 961 }; 962 963 enum { 964 TOUCHSCREEN_ANY = ACONFIGURATION_TOUCHSCREEN_ANY, 965 TOUCHSCREEN_NOTOUCH = ACONFIGURATION_TOUCHSCREEN_NOTOUCH, 966 TOUCHSCREEN_STYLUS = ACONFIGURATION_TOUCHSCREEN_STYLUS, 967 TOUCHSCREEN_FINGER = ACONFIGURATION_TOUCHSCREEN_FINGER, 968 }; 969 970 enum { 971 DENSITY_DEFAULT = ACONFIGURATION_DENSITY_DEFAULT, 972 DENSITY_LOW = ACONFIGURATION_DENSITY_LOW, 973 DENSITY_MEDIUM = ACONFIGURATION_DENSITY_MEDIUM, 974 DENSITY_TV = ACONFIGURATION_DENSITY_TV, 975 DENSITY_HIGH = ACONFIGURATION_DENSITY_HIGH, 976 DENSITY_XHIGH = ACONFIGURATION_DENSITY_XHIGH, 977 DENSITY_XXHIGH = ACONFIGURATION_DENSITY_XXHIGH, 978 DENSITY_XXXHIGH = ACONFIGURATION_DENSITY_XXXHIGH, 979 DENSITY_ANY = ACONFIGURATION_DENSITY_ANY, 980 DENSITY_NONE = ACONFIGURATION_DENSITY_NONE 981 }; 982 983 union { 984 struct { 985 uint8_t orientation; 986 uint8_t touchscreen; 987 uint16_t density; 988 }; 989 uint32_t screenType; 990 }; 991 992 enum { 993 KEYBOARD_ANY = ACONFIGURATION_KEYBOARD_ANY, 994 KEYBOARD_NOKEYS = ACONFIGURATION_KEYBOARD_NOKEYS, 995 KEYBOARD_QWERTY = ACONFIGURATION_KEYBOARD_QWERTY, 996 KEYBOARD_12KEY = ACONFIGURATION_KEYBOARD_12KEY, 997 }; 998 999 enum { 1000 NAVIGATION_ANY = ACONFIGURATION_NAVIGATION_ANY, 1001 NAVIGATION_NONAV = ACONFIGURATION_NAVIGATION_NONAV, 1002 NAVIGATION_DPAD = ACONFIGURATION_NAVIGATION_DPAD, 1003 NAVIGATION_TRACKBALL = ACONFIGURATION_NAVIGATION_TRACKBALL, 1004 NAVIGATION_WHEEL = ACONFIGURATION_NAVIGATION_WHEEL, 1005 }; 1006 1007 enum { 1008 MASK_KEYSHIDDEN = 0x0003, 1009 KEYSHIDDEN_ANY = ACONFIGURATION_KEYSHIDDEN_ANY, 1010 KEYSHIDDEN_NO = ACONFIGURATION_KEYSHIDDEN_NO, 1011 KEYSHIDDEN_YES = ACONFIGURATION_KEYSHIDDEN_YES, 1012 KEYSHIDDEN_SOFT = ACONFIGURATION_KEYSHIDDEN_SOFT, 1013 }; 1014 1015 enum { 1016 MASK_NAVHIDDEN = 0x000c, 1017 SHIFT_NAVHIDDEN = 2, 1018 NAVHIDDEN_ANY = ACONFIGURATION_NAVHIDDEN_ANY << SHIFT_NAVHIDDEN, 1019 NAVHIDDEN_NO = ACONFIGURATION_NAVHIDDEN_NO << SHIFT_NAVHIDDEN, 1020 NAVHIDDEN_YES = ACONFIGURATION_NAVHIDDEN_YES << SHIFT_NAVHIDDEN, 1021 }; 1022 1023 union { 1024 struct { 1025 uint8_t keyboard; 1026 uint8_t navigation; 1027 uint8_t inputFlags; 1028 uint8_t inputPad0; 1029 }; 1030 uint32_t input; 1031 }; 1032 1033 enum { 1034 SCREENWIDTH_ANY = 0 1035 }; 1036 1037 enum { 1038 SCREENHEIGHT_ANY = 0 1039 }; 1040 1041 union { 1042 struct { 1043 uint16_t screenWidth; 1044 uint16_t screenHeight; 1045 }; 1046 uint32_t screenSize; 1047 }; 1048 1049 enum { 1050 SDKVERSION_ANY = 0 1051 }; 1052 1053 enum { 1054 MINORVERSION_ANY = 0 1055 }; 1056 1057 union { 1058 struct { 1059 uint16_t sdkVersion; 1060 // For now minorVersion must always be 0!!! Its meaning 1061 // is currently undefined. 1062 uint16_t minorVersion; 1063 }; 1064 uint32_t version; 1065 }; 1066 1067 enum { 1068 // screenLayout bits for screen size class. 1069 MASK_SCREENSIZE = 0x0f, 1070 SCREENSIZE_ANY = ACONFIGURATION_SCREENSIZE_ANY, 1071 SCREENSIZE_SMALL = ACONFIGURATION_SCREENSIZE_SMALL, 1072 SCREENSIZE_NORMAL = ACONFIGURATION_SCREENSIZE_NORMAL, 1073 SCREENSIZE_LARGE = ACONFIGURATION_SCREENSIZE_LARGE, 1074 SCREENSIZE_XLARGE = ACONFIGURATION_SCREENSIZE_XLARGE, 1075 1076 // screenLayout bits for wide/long screen variation. 1077 MASK_SCREENLONG = 0x30, 1078 SHIFT_SCREENLONG = 4, 1079 SCREENLONG_ANY = ACONFIGURATION_SCREENLONG_ANY << SHIFT_SCREENLONG, 1080 SCREENLONG_NO = ACONFIGURATION_SCREENLONG_NO << SHIFT_SCREENLONG, 1081 SCREENLONG_YES = ACONFIGURATION_SCREENLONG_YES << SHIFT_SCREENLONG, 1082 1083 // screenLayout bits for layout direction. 1084 MASK_LAYOUTDIR = 0xC0, 1085 SHIFT_LAYOUTDIR = 6, 1086 LAYOUTDIR_ANY = ACONFIGURATION_LAYOUTDIR_ANY << SHIFT_LAYOUTDIR, 1087 LAYOUTDIR_LTR = ACONFIGURATION_LAYOUTDIR_LTR << SHIFT_LAYOUTDIR, 1088 LAYOUTDIR_RTL = ACONFIGURATION_LAYOUTDIR_RTL << SHIFT_LAYOUTDIR, 1089 }; 1090 1091 enum { 1092 // uiMode bits for the mode type. 1093 MASK_UI_MODE_TYPE = 0x0f, 1094 UI_MODE_TYPE_ANY = ACONFIGURATION_UI_MODE_TYPE_ANY, 1095 UI_MODE_TYPE_NORMAL = ACONFIGURATION_UI_MODE_TYPE_NORMAL, 1096 UI_MODE_TYPE_DESK = ACONFIGURATION_UI_MODE_TYPE_DESK, 1097 UI_MODE_TYPE_CAR = ACONFIGURATION_UI_MODE_TYPE_CAR, 1098 UI_MODE_TYPE_TELEVISION = ACONFIGURATION_UI_MODE_TYPE_TELEVISION, 1099 UI_MODE_TYPE_APPLIANCE = ACONFIGURATION_UI_MODE_TYPE_APPLIANCE, 1100 UI_MODE_TYPE_WATCH = ACONFIGURATION_UI_MODE_TYPE_WATCH, 1101 1102 // uiMode bits for the night switch. 1103 MASK_UI_MODE_NIGHT = 0x30, 1104 SHIFT_UI_MODE_NIGHT = 4, 1105 UI_MODE_NIGHT_ANY = ACONFIGURATION_UI_MODE_NIGHT_ANY << SHIFT_UI_MODE_NIGHT, 1106 UI_MODE_NIGHT_NO = ACONFIGURATION_UI_MODE_NIGHT_NO << SHIFT_UI_MODE_NIGHT, 1107 UI_MODE_NIGHT_YES = ACONFIGURATION_UI_MODE_NIGHT_YES << SHIFT_UI_MODE_NIGHT, 1108 }; 1109 1110 union { 1111 struct { 1112 uint8_t screenLayout; 1113 uint8_t uiMode; 1114 uint16_t smallestScreenWidthDp; 1115 }; 1116 uint32_t screenConfig; 1117 }; 1118 1119 union { 1120 struct { 1121 uint16_t screenWidthDp; 1122 uint16_t screenHeightDp; 1123 }; 1124 uint32_t screenSizeDp; 1125 }; 1126 1127 // The ISO-15924 short name for the script corresponding to this 1128 // configuration. (eg. Hant, Latn, etc.). Interpreted in conjunction with 1129 // the locale field. 1130 char localeScript[4]; 1131 1132 // A single BCP-47 variant subtag. Will vary in length between 4 and 8 1133 // chars. Interpreted in conjunction with the locale field. 1134 char localeVariant[8]; 1135 1136 enum { 1137 // screenLayout2 bits for round/notround. 1138 MASK_SCREENROUND = 0x03, 1139 SCREENROUND_ANY = ACONFIGURATION_SCREENROUND_ANY, 1140 SCREENROUND_NO = ACONFIGURATION_SCREENROUND_NO, 1141 SCREENROUND_YES = ACONFIGURATION_SCREENROUND_YES, 1142 }; 1143 1144 // An extension of screenConfig. 1145 union { 1146 struct { 1147 uint8_t screenLayout2; // Contains round/notround qualifier. 1148 uint8_t screenConfigPad1; // Reserved padding. 1149 uint16_t screenConfigPad2; // Reserved padding. 1150 }; 1151 uint32_t screenConfig2; 1152 }; 1153 1154 // If true, it means that the script of the locale was explicitly provided. 1155 // If false, it means that the script was automatically computed. 1156 bool localeScriptWasProvided; 1157 1158 void copyFromDeviceNoSwap(const ResTable_config& o); 1159 1160 void copyFromDtoH(const ResTable_config& o); 1161 1162 void swapHtoD(); 1163 1164 int compare(const ResTable_config& o) const; 1165 int compareLogical(const ResTable_config& o) const; 1166 1167 // Flags indicating a set of config values. These flag constants must 1168 // match the corresponding ones in android.content.pm.ActivityInfo and 1169 // attrs_manifest.xml. 1170 enum { 1171 CONFIG_MCC = ACONFIGURATION_MCC, 1172 CONFIG_MNC = ACONFIGURATION_MNC, 1173 CONFIG_LOCALE = ACONFIGURATION_LOCALE, 1174 CONFIG_TOUCHSCREEN = ACONFIGURATION_TOUCHSCREEN, 1175 CONFIG_KEYBOARD = ACONFIGURATION_KEYBOARD, 1176 CONFIG_KEYBOARD_HIDDEN = ACONFIGURATION_KEYBOARD_HIDDEN, 1177 CONFIG_NAVIGATION = ACONFIGURATION_NAVIGATION, 1178 CONFIG_ORIENTATION = ACONFIGURATION_ORIENTATION, 1179 CONFIG_DENSITY = ACONFIGURATION_DENSITY, 1180 CONFIG_SCREEN_SIZE = ACONFIGURATION_SCREEN_SIZE, 1181 CONFIG_SMALLEST_SCREEN_SIZE = ACONFIGURATION_SMALLEST_SCREEN_SIZE, 1182 CONFIG_VERSION = ACONFIGURATION_VERSION, 1183 CONFIG_SCREEN_LAYOUT = ACONFIGURATION_SCREEN_LAYOUT, 1184 CONFIG_UI_MODE = ACONFIGURATION_UI_MODE, 1185 CONFIG_LAYOUTDIR = ACONFIGURATION_LAYOUTDIR, 1186 CONFIG_SCREEN_ROUND = ACONFIGURATION_SCREEN_ROUND, 1187 }; 1188 1189 // Compare two configuration, returning CONFIG_* flags set for each value 1190 // that is different. 1191 int diff(const ResTable_config& o) const; 1192 1193 // Return true if 'this' is more specific than 'o'. 1194 bool isMoreSpecificThan(const ResTable_config& o) const; 1195 1196 // Return true if 'this' is a better match than 'o' for the 'requested' 1197 // configuration. This assumes that match() has already been used to 1198 // remove any configurations that don't match the requested configuration 1199 // at all; if they are not first filtered, non-matching results can be 1200 // considered better than matching ones. 1201 // The general rule per attribute: if the request cares about an attribute 1202 // (it normally does), if the two (this and o) are equal it's a tie. If 1203 // they are not equal then one must be generic because only generic and 1204 // '==requested' will pass the match() call. So if this is not generic, 1205 // it wins. If this IS generic, o wins (return false). 1206 bool isBetterThan(const ResTable_config& o, const ResTable_config* requested) const; 1207 1208 // Return true if 'this' can be considered a match for the parameters in 1209 // 'settings'. 1210 // Note this is asymetric. A default piece of data will match every request 1211 // but a request for the default should not match odd specifics 1212 // (ie, request with no mcc should not match a particular mcc's data) 1213 // settings is the requested settings 1214 bool match(const ResTable_config& settings) const; 1215 1216 // Get the string representation of the locale component of this 1217 // Config. The maximum size of this representation will be 1218 // |RESTABLE_MAX_LOCALE_LEN| (including a terminating '\0'). 1219 // 1220 // Example: en-US, en-Latn-US, en-POSIX. 1221 void getBcp47Locale(char* out) const; 1222 1223 // Append to str the resource-qualifer string representation of the 1224 // locale component of this Config. If the locale is only country 1225 // and language, it will look like en-rUS. If it has scripts and 1226 // variants, it will be a modified bcp47 tag: b+en+Latn+US. 1227 void appendDirLocale(String8& str) const; 1228 1229 // Sets the values of language, region, script and variant to the 1230 // well formed BCP-47 locale contained in |in|. The input locale is 1231 // assumed to be valid and no validation is performed. 1232 void setBcp47Locale(const char* in); 1233 1234 inline void clearLocale() { 1235 locale = 0; 1236 localeScriptWasProvided = false; 1237 memset(localeScript, 0, sizeof(localeScript)); 1238 memset(localeVariant, 0, sizeof(localeVariant)); 1239 } 1240 1241 inline void computeScript() { 1242 localeDataComputeScript(localeScript, language, country); 1243 } 1244 1245 // Get the 2 or 3 letter language code of this configuration. Trailing 1246 // bytes are set to '\0'. 1247 size_t unpackLanguage(char language[4]) const; 1248 // Get the 2 or 3 letter language code of this configuration. Trailing 1249 // bytes are set to '\0'. 1250 size_t unpackRegion(char region[4]) const; 1251 1252 // Sets the language code of this configuration to the first three 1253 // chars at |language|. 1254 // 1255 // If |language| is a 2 letter code, the trailing byte must be '\0' or 1256 // the BCP-47 separator '-'. 1257 void packLanguage(const char* language); 1258 // Sets the region code of this configuration to the first three bytes 1259 // at |region|. If |region| is a 2 letter code, the trailing byte must be '\0' 1260 // or the BCP-47 separator '-'. 1261 void packRegion(const char* region); 1262 1263 // Returns a positive integer if this config is more specific than |o| 1264 // with respect to their locales, a negative integer if |o| is more specific 1265 // and 0 if they're equally specific. 1266 int isLocaleMoreSpecificThan(const ResTable_config &o) const; 1267 1268 // Return true if 'this' is a better locale match than 'o' for the 1269 // 'requested' configuration. Similar to isBetterThan(), this assumes that 1270 // match() has already been used to remove any configurations that don't 1271 // match the requested configuration at all. 1272 bool isLocaleBetterThan(const ResTable_config& o, const ResTable_config* requested) const; 1273 1274 String8 toString() const; 1275}; 1276 1277/** 1278 * A specification of the resources defined by a particular type. 1279 * 1280 * There should be one of these chunks for each resource type. 1281 * 1282 * This structure is followed by an array of integers providing the set of 1283 * configuration change flags (ResTable_config::CONFIG_*) that have multiple 1284 * resources for that configuration. In addition, the high bit is set if that 1285 * resource has been made public. 1286 */ 1287struct ResTable_typeSpec 1288{ 1289 struct ResChunk_header header; 1290 1291 // The type identifier this chunk is holding. Type IDs start 1292 // at 1 (corresponding to the value of the type bits in a 1293 // resource identifier). 0 is invalid. 1294 uint8_t id; 1295 1296 // Must be 0. 1297 uint8_t res0; 1298 // Must be 0. 1299 uint16_t res1; 1300 1301 // Number of uint32_t entry configuration masks that follow. 1302 uint32_t entryCount; 1303 1304 enum { 1305 // Additional flag indicating an entry is public. 1306 SPEC_PUBLIC = 0x40000000 1307 }; 1308}; 1309 1310/** 1311 * A collection of resource entries for a particular resource data 1312 * type. Followed by an array of uint32_t defining the resource 1313 * values, corresponding to the array of type strings in the 1314 * ResTable_package::typeStrings string block. Each of these hold an 1315 * index from entriesStart; a value of NO_ENTRY means that entry is 1316 * not defined. 1317 * 1318 * There may be multiple of these chunks for a particular resource type, 1319 * supply different configuration variations for the resource values of 1320 * that type. 1321 * 1322 * It would be nice to have an additional ordered index of entries, so 1323 * we can do a binary search if trying to find a resource by string name. 1324 */ 1325struct ResTable_type 1326{ 1327 struct ResChunk_header header; 1328 1329 enum { 1330 NO_ENTRY = 0xFFFFFFFF 1331 }; 1332 1333 // The type identifier this chunk is holding. Type IDs start 1334 // at 1 (corresponding to the value of the type bits in a 1335 // resource identifier). 0 is invalid. 1336 uint8_t id; 1337 1338 // Must be 0. 1339 uint8_t res0; 1340 // Must be 0. 1341 uint16_t res1; 1342 1343 // Number of uint32_t entry indices that follow. 1344 uint32_t entryCount; 1345 1346 // Offset from header where ResTable_entry data starts. 1347 uint32_t entriesStart; 1348 1349 // Configuration this collection of entries is designed for. 1350 ResTable_config config; 1351}; 1352 1353/** 1354 * This is the beginning of information about an entry in the resource 1355 * table. It holds the reference to the name of this entry, and is 1356 * immediately followed by one of: 1357 * * A Res_value structure, if FLAG_COMPLEX is -not- set. 1358 * * An array of ResTable_map structures, if FLAG_COMPLEX is set. 1359 * These supply a set of name/value mappings of data. 1360 */ 1361struct ResTable_entry 1362{ 1363 // Number of bytes in this structure. 1364 uint16_t size; 1365 1366 enum { 1367 // If set, this is a complex entry, holding a set of name/value 1368 // mappings. It is followed by an array of ResTable_map structures. 1369 FLAG_COMPLEX = 0x0001, 1370 // If set, this resource has been declared public, so libraries 1371 // are allowed to reference it. 1372 FLAG_PUBLIC = 0x0002, 1373 // If set, this is a weak resource and may be overriden by strong 1374 // resources of the same name/type. This is only useful during 1375 // linking with other resource tables. 1376 FLAG_WEAK = 0x0004 1377 }; 1378 uint16_t flags; 1379 1380 // Reference into ResTable_package::keyStrings identifying this entry. 1381 struct ResStringPool_ref key; 1382}; 1383 1384/** 1385 * Extended form of a ResTable_entry for map entries, defining a parent map 1386 * resource from which to inherit values. 1387 */ 1388struct ResTable_map_entry : public ResTable_entry 1389{ 1390 // Resource identifier of the parent mapping, or 0 if there is none. 1391 // This is always treated as a TYPE_DYNAMIC_REFERENCE. 1392 ResTable_ref parent; 1393 // Number of name/value pairs that follow for FLAG_COMPLEX. 1394 uint32_t count; 1395}; 1396 1397/** 1398 * A single name/value mapping that is part of a complex resource 1399 * entry. 1400 */ 1401struct ResTable_map 1402{ 1403 // The resource identifier defining this mapping's name. For attribute 1404 // resources, 'name' can be one of the following special resource types 1405 // to supply meta-data about the attribute; for all other resource types 1406 // it must be an attribute resource. 1407 ResTable_ref name; 1408 1409 // Special values for 'name' when defining attribute resources. 1410 enum { 1411 // This entry holds the attribute's type code. 1412 ATTR_TYPE = Res_MAKEINTERNAL(0), 1413 1414 // For integral attributes, this is the minimum value it can hold. 1415 ATTR_MIN = Res_MAKEINTERNAL(1), 1416 1417 // For integral attributes, this is the maximum value it can hold. 1418 ATTR_MAX = Res_MAKEINTERNAL(2), 1419 1420 // Localization of this resource is can be encouraged or required with 1421 // an aapt flag if this is set 1422 ATTR_L10N = Res_MAKEINTERNAL(3), 1423 1424 // for plural support, see android.content.res.PluralRules#attrForQuantity(int) 1425 ATTR_OTHER = Res_MAKEINTERNAL(4), 1426 ATTR_ZERO = Res_MAKEINTERNAL(5), 1427 ATTR_ONE = Res_MAKEINTERNAL(6), 1428 ATTR_TWO = Res_MAKEINTERNAL(7), 1429 ATTR_FEW = Res_MAKEINTERNAL(8), 1430 ATTR_MANY = Res_MAKEINTERNAL(9) 1431 1432 }; 1433 1434 // Bit mask of allowed types, for use with ATTR_TYPE. 1435 enum { 1436 // No type has been defined for this attribute, use generic 1437 // type handling. The low 16 bits are for types that can be 1438 // handled generically; the upper 16 require additional information 1439 // in the bag so can not be handled generically for TYPE_ANY. 1440 TYPE_ANY = 0x0000FFFF, 1441 1442 // Attribute holds a references to another resource. 1443 TYPE_REFERENCE = 1<<0, 1444 1445 // Attribute holds a generic string. 1446 TYPE_STRING = 1<<1, 1447 1448 // Attribute holds an integer value. ATTR_MIN and ATTR_MIN can 1449 // optionally specify a constrained range of possible integer values. 1450 TYPE_INTEGER = 1<<2, 1451 1452 // Attribute holds a boolean integer. 1453 TYPE_BOOLEAN = 1<<3, 1454 1455 // Attribute holds a color value. 1456 TYPE_COLOR = 1<<4, 1457 1458 // Attribute holds a floating point value. 1459 TYPE_FLOAT = 1<<5, 1460 1461 // Attribute holds a dimension value, such as "20px". 1462 TYPE_DIMENSION = 1<<6, 1463 1464 // Attribute holds a fraction value, such as "20%". 1465 TYPE_FRACTION = 1<<7, 1466 1467 // Attribute holds an enumeration. The enumeration values are 1468 // supplied as additional entries in the map. 1469 TYPE_ENUM = 1<<16, 1470 1471 // Attribute holds a bitmaks of flags. The flag bit values are 1472 // supplied as additional entries in the map. 1473 TYPE_FLAGS = 1<<17 1474 }; 1475 1476 // Enum of localization modes, for use with ATTR_L10N. 1477 enum { 1478 L10N_NOT_REQUIRED = 0, 1479 L10N_SUGGESTED = 1 1480 }; 1481 1482 // This mapping's value. 1483 Res_value value; 1484}; 1485 1486/** 1487 * A package-id to package name mapping for any shared libraries used 1488 * in this resource table. The package-id's encoded in this resource 1489 * table may be different than the id's assigned at runtime. We must 1490 * be able to translate the package-id's based on the package name. 1491 */ 1492struct ResTable_lib_header 1493{ 1494 struct ResChunk_header header; 1495 1496 // The number of shared libraries linked in this resource table. 1497 uint32_t count; 1498}; 1499 1500/** 1501 * A shared library package-id to package name entry. 1502 */ 1503struct ResTable_lib_entry 1504{ 1505 // The package-id this shared library was assigned at build time. 1506 // We use a uint32 to keep the structure aligned on a uint32 boundary. 1507 uint32_t packageId; 1508 1509 // The package name of the shared library. \0 terminated. 1510 uint16_t packageName[128]; 1511}; 1512 1513/** 1514 * Holds the shared library ID table. Shared libraries are assigned package IDs at 1515 * build time, but they may be loaded in a different order, so we need to maintain 1516 * a mapping of build-time package ID to run-time assigned package ID. 1517 * 1518 * Dynamic references are not currently supported in overlays. Only the base package 1519 * may have dynamic references. 1520 */ 1521class DynamicRefTable 1522{ 1523public: 1524 DynamicRefTable(uint8_t packageId, bool appAsLib); 1525 1526 // Loads an unmapped reference table from the package. 1527 status_t load(const ResTable_lib_header* const header); 1528 1529 // Adds mappings from the other DynamicRefTable 1530 status_t addMappings(const DynamicRefTable& other); 1531 1532 // Creates a mapping from build-time package ID to run-time package ID for 1533 // the given package. 1534 status_t addMapping(const String16& packageName, uint8_t packageId); 1535 1536 // Performs the actual conversion of build-time resource ID to run-time 1537 // resource ID. 1538 inline status_t lookupResourceId(uint32_t* resId) const; 1539 inline status_t lookupResourceValue(Res_value* value) const; 1540 1541 inline const KeyedVector<String16, uint8_t>& entries() const { 1542 return mEntries; 1543 } 1544 1545private: 1546 const uint8_t mAssignedPackageId; 1547 uint8_t mLookupTable[256]; 1548 KeyedVector<String16, uint8_t> mEntries; 1549 bool mAppAsLib; 1550}; 1551 1552bool U16StringToInt(const char16_t* s, size_t len, Res_value* outValue); 1553 1554/** 1555 * Convenience class for accessing data in a ResTable resource. 1556 */ 1557class ResTable 1558{ 1559public: 1560 ResTable(); 1561 ResTable(const void* data, size_t size, const int32_t cookie, 1562 bool copyData=false); 1563 ~ResTable(); 1564 1565 status_t add(const void* data, size_t size, const int32_t cookie=-1, bool copyData=false); 1566 status_t add(const void* data, size_t size, const void* idmapData, size_t idmapDataSize, 1567 const int32_t cookie=-1, bool copyData=false, bool appAsLib=false); 1568 1569 status_t add(Asset* asset, const int32_t cookie=-1, bool copyData=false); 1570 status_t add(Asset* asset, Asset* idmapAsset, const int32_t cookie=-1, bool copyData=false, 1571 bool appAsLib=false, bool isSystemAsset=false); 1572 1573 status_t add(ResTable* src, bool isSystemAsset=false); 1574 status_t addEmpty(const int32_t cookie); 1575 1576 status_t getError() const; 1577 1578 void uninit(); 1579 1580 struct resource_name 1581 { 1582 const char16_t* package; 1583 size_t packageLen; 1584 const char16_t* type; 1585 const char* type8; 1586 size_t typeLen; 1587 const char16_t* name; 1588 const char* name8; 1589 size_t nameLen; 1590 }; 1591 1592 bool getResourceName(uint32_t resID, bool allowUtf8, resource_name* outName) const; 1593 1594 bool getResourceFlags(uint32_t resID, uint32_t* outFlags) const; 1595 1596 /** 1597 * Retrieve the value of a resource. If the resource is found, returns a 1598 * value >= 0 indicating the table it is in (for use with 1599 * getTableStringBlock() and getTableCookie()) and fills in 'outValue'. If 1600 * not found, returns a negative error code. 1601 * 1602 * Note that this function does not do reference traversal. If you want 1603 * to follow references to other resources to get the "real" value to 1604 * use, you need to call resolveReference() after this function. 1605 * 1606 * @param resID The desired resoruce identifier. 1607 * @param outValue Filled in with the resource data that was found. 1608 * 1609 * @return ssize_t Either a >= 0 table index or a negative error code. 1610 */ 1611 ssize_t getResource(uint32_t resID, Res_value* outValue, bool mayBeBag = false, 1612 uint16_t density = 0, 1613 uint32_t* outSpecFlags = NULL, 1614 ResTable_config* outConfig = NULL) const; 1615 1616 inline ssize_t getResource(const ResTable_ref& res, Res_value* outValue, 1617 uint32_t* outSpecFlags=NULL) const { 1618 return getResource(res.ident, outValue, false, 0, outSpecFlags, NULL); 1619 } 1620 1621 ssize_t resolveReference(Res_value* inOutValue, 1622 ssize_t blockIndex, 1623 uint32_t* outLastRef = NULL, 1624 uint32_t* inoutTypeSpecFlags = NULL, 1625 ResTable_config* outConfig = NULL) const; 1626 1627 enum { 1628 TMP_BUFFER_SIZE = 16 1629 }; 1630 const char16_t* valueToString(const Res_value* value, size_t stringBlock, 1631 char16_t tmpBuffer[TMP_BUFFER_SIZE], 1632 size_t* outLen) const; 1633 1634 struct bag_entry { 1635 ssize_t stringBlock; 1636 ResTable_map map; 1637 }; 1638 1639 /** 1640 * Retrieve the bag of a resource. If the resoruce is found, returns the 1641 * number of bags it contains and 'outBag' points to an array of their 1642 * values. If not found, a negative error code is returned. 1643 * 1644 * Note that this function -does- do reference traversal of the bag data. 1645 * 1646 * @param resID The desired resource identifier. 1647 * @param outBag Filled inm with a pointer to the bag mappings. 1648 * 1649 * @return ssize_t Either a >= 0 bag count of negative error code. 1650 */ 1651 ssize_t lockBag(uint32_t resID, const bag_entry** outBag) const; 1652 1653 void unlockBag(const bag_entry* bag) const; 1654 1655 void lock() const; 1656 1657 ssize_t getBagLocked(uint32_t resID, const bag_entry** outBag, 1658 uint32_t* outTypeSpecFlags=NULL) const; 1659 1660 void unlock() const; 1661 1662 class Theme { 1663 public: 1664 Theme(const ResTable& table); 1665 ~Theme(); 1666 1667 inline const ResTable& getResTable() const { return mTable; } 1668 1669 status_t applyStyle(uint32_t resID, bool force=false); 1670 status_t setTo(const Theme& other); 1671 status_t clear(); 1672 1673 /** 1674 * Retrieve a value in the theme. If the theme defines this 1675 * value, returns a value >= 0 indicating the table it is in 1676 * (for use with getTableStringBlock() and getTableCookie) and 1677 * fills in 'outValue'. If not found, returns a negative error 1678 * code. 1679 * 1680 * Note that this function does not do reference traversal. If you want 1681 * to follow references to other resources to get the "real" value to 1682 * use, you need to call resolveReference() after this function. 1683 * 1684 * @param resID A resource identifier naming the desired theme 1685 * attribute. 1686 * @param outValue Filled in with the theme value that was 1687 * found. 1688 * 1689 * @return ssize_t Either a >= 0 table index or a negative error code. 1690 */ 1691 ssize_t getAttribute(uint32_t resID, Res_value* outValue, 1692 uint32_t* outTypeSpecFlags = NULL) const; 1693 1694 /** 1695 * This is like ResTable::resolveReference(), but also takes 1696 * care of resolving attribute references to the theme. 1697 */ 1698 ssize_t resolveAttributeReference(Res_value* inOutValue, 1699 ssize_t blockIndex, uint32_t* outLastRef = NULL, 1700 uint32_t* inoutTypeSpecFlags = NULL, 1701 ResTable_config* inoutConfig = NULL) const; 1702 1703 /** 1704 * Returns a bit mask of configuration changes that will impact this 1705 * theme (and thus require completely reloading it). 1706 */ 1707 uint32_t getChangingConfigurations() const; 1708 1709 void dumpToLog() const; 1710 1711 private: 1712 Theme(const Theme&); 1713 Theme& operator=(const Theme&); 1714 1715 struct theme_entry { 1716 ssize_t stringBlock; 1717 uint32_t typeSpecFlags; 1718 Res_value value; 1719 }; 1720 1721 struct type_info { 1722 size_t numEntries; 1723 theme_entry* entries; 1724 }; 1725 1726 struct package_info { 1727 type_info types[Res_MAXTYPE + 1]; 1728 }; 1729 1730 void free_package(package_info* pi); 1731 package_info* copy_package(package_info* pi); 1732 1733 const ResTable& mTable; 1734 package_info* mPackages[Res_MAXPACKAGE]; 1735 uint32_t mTypeSpecFlags; 1736 }; 1737 1738 void setParameters(const ResTable_config* params); 1739 void getParameters(ResTable_config* params) const; 1740 1741 // Retrieve an identifier (which can be passed to getResource) 1742 // for a given resource name. The 'name' can be fully qualified 1743 // (<package>:<type>.<basename>) or the package or type components 1744 // can be dropped if default values are supplied here. 1745 // 1746 // Returns 0 if no such resource was found, else a valid resource ID. 1747 uint32_t identifierForName(const char16_t* name, size_t nameLen, 1748 const char16_t* type = 0, size_t typeLen = 0, 1749 const char16_t* defPackage = 0, 1750 size_t defPackageLen = 0, 1751 uint32_t* outTypeSpecFlags = NULL) const; 1752 1753 static bool expandResourceRef(const char16_t* refStr, size_t refLen, 1754 String16* outPackage, 1755 String16* outType, 1756 String16* outName, 1757 const String16* defType = NULL, 1758 const String16* defPackage = NULL, 1759 const char** outErrorMsg = NULL, 1760 bool* outPublicOnly = NULL); 1761 1762 static bool stringToInt(const char16_t* s, size_t len, Res_value* outValue); 1763 static bool stringToFloat(const char16_t* s, size_t len, Res_value* outValue); 1764 1765 // Used with stringToValue. 1766 class Accessor 1767 { 1768 public: 1769 inline virtual ~Accessor() { } 1770 1771 virtual const String16& getAssetsPackage() const = 0; 1772 1773 virtual uint32_t getCustomResource(const String16& package, 1774 const String16& type, 1775 const String16& name) const = 0; 1776 virtual uint32_t getCustomResourceWithCreation(const String16& package, 1777 const String16& type, 1778 const String16& name, 1779 const bool createIfNeeded = false) = 0; 1780 virtual uint32_t getRemappedPackage(uint32_t origPackage) const = 0; 1781 virtual bool getAttributeType(uint32_t attrID, uint32_t* outType) = 0; 1782 virtual bool getAttributeMin(uint32_t attrID, uint32_t* outMin) = 0; 1783 virtual bool getAttributeMax(uint32_t attrID, uint32_t* outMax) = 0; 1784 virtual bool getAttributeEnum(uint32_t attrID, 1785 const char16_t* name, size_t nameLen, 1786 Res_value* outValue) = 0; 1787 virtual bool getAttributeFlags(uint32_t attrID, 1788 const char16_t* name, size_t nameLen, 1789 Res_value* outValue) = 0; 1790 virtual uint32_t getAttributeL10N(uint32_t attrID) = 0; 1791 virtual bool getLocalizationSetting() = 0; 1792 virtual void reportError(void* accessorCookie, const char* fmt, ...) = 0; 1793 }; 1794 1795 // Convert a string to a resource value. Handles standard "@res", 1796 // "#color", "123", and "0x1bd" types; performs escaping of strings. 1797 // The resulting value is placed in 'outValue'; if it is a string type, 1798 // 'outString' receives the string. If 'attrID' is supplied, the value is 1799 // type checked against this attribute and it is used to perform enum 1800 // evaluation. If 'acccessor' is supplied, it will be used to attempt to 1801 // resolve resources that do not exist in this ResTable. If 'attrType' is 1802 // supplied, the value will be type checked for this format if 'attrID' 1803 // is not supplied or found. 1804 bool stringToValue(Res_value* outValue, String16* outString, 1805 const char16_t* s, size_t len, 1806 bool preserveSpaces, bool coerceType, 1807 uint32_t attrID = 0, 1808 const String16* defType = NULL, 1809 const String16* defPackage = NULL, 1810 Accessor* accessor = NULL, 1811 void* accessorCookie = NULL, 1812 uint32_t attrType = ResTable_map::TYPE_ANY, 1813 bool enforcePrivate = true) const; 1814 1815 // Perform processing of escapes and quotes in a string. 1816 static bool collectString(String16* outString, 1817 const char16_t* s, size_t len, 1818 bool preserveSpaces, 1819 const char** outErrorMsg = NULL, 1820 bool append = false); 1821 1822 size_t getBasePackageCount() const; 1823 const String16 getBasePackageName(size_t idx) const; 1824 uint32_t getBasePackageId(size_t idx) const; 1825 uint32_t getLastTypeIdForPackage(size_t idx) const; 1826 1827 // Return the number of resource tables that the object contains. 1828 size_t getTableCount() const; 1829 // Return the values string pool for the resource table at the given 1830 // index. This string pool contains all of the strings for values 1831 // contained in the resource table -- that is the item values themselves, 1832 // but not the names their entries or types. 1833 const ResStringPool* getTableStringBlock(size_t index) const; 1834 // Return unique cookie identifier for the given resource table. 1835 int32_t getTableCookie(size_t index) const; 1836 1837 const DynamicRefTable* getDynamicRefTableForCookie(int32_t cookie) const; 1838 1839 // Return the configurations (ResTable_config) that we know about 1840 void getConfigurations(Vector<ResTable_config>* configs, bool ignoreMipmap=false, 1841 bool ignoreAndroidPackage=false, bool includeSystemConfigs=true) const; 1842 1843 void getLocales(Vector<String8>* locales, bool includeSystemLocales=true) const; 1844 1845 // Generate an idmap. 1846 // 1847 // Return value: on success: NO_ERROR; caller is responsible for free-ing 1848 // outData (using free(3)). On failure, any status_t value other than 1849 // NO_ERROR; the caller should not free outData. 1850 status_t createIdmap(const ResTable& overlay, 1851 uint32_t targetCrc, uint32_t overlayCrc, 1852 const char* targetPath, const char* overlayPath, 1853 void** outData, size_t* outSize) const; 1854 1855 static const size_t IDMAP_HEADER_SIZE_BYTES = 4 * sizeof(uint32_t) + 2 * 256; 1856 1857 // Retrieve idmap meta-data. 1858 // 1859 // This function only requires the idmap header (the first 1860 // IDMAP_HEADER_SIZE_BYTES) bytes of an idmap file. 1861 static bool getIdmapInfo(const void* idmap, size_t size, 1862 uint32_t* pVersion, 1863 uint32_t* pTargetCrc, uint32_t* pOverlayCrc, 1864 String8* pTargetPath, String8* pOverlayPath); 1865 1866 void print(bool inclValues) const; 1867 static String8 normalizeForOutput(const char* input); 1868 1869private: 1870 struct Header; 1871 struct Type; 1872 struct Entry; 1873 struct Package; 1874 struct PackageGroup; 1875 struct bag_set; 1876 typedef Vector<Type*> TypeList; 1877 1878 status_t addInternal(const void* data, size_t size, const void* idmapData, size_t idmapDataSize, 1879 bool appAsLib, const int32_t cookie, bool copyData, bool isSystemAsset=false); 1880 1881 ssize_t getResourcePackageIndex(uint32_t resID) const; 1882 1883 status_t getEntry( 1884 const PackageGroup* packageGroup, int typeIndex, int entryIndex, 1885 const ResTable_config* config, 1886 Entry* outEntry) const; 1887 1888 uint32_t findEntry(const PackageGroup* group, ssize_t typeIndex, const char16_t* name, 1889 size_t nameLen, uint32_t* outTypeSpecFlags) const; 1890 1891 status_t parsePackage( 1892 const ResTable_package* const pkg, const Header* const header, 1893 bool appAsLib, bool isSystemAsset); 1894 1895 void print_value(const Package* pkg, const Res_value& value) const; 1896 1897 mutable Mutex mLock; 1898 1899 // Mutex that controls access to the list of pre-filtered configurations 1900 // to check when looking up entries. 1901 // When iterating over a bag, the mLock mutex is locked. While mLock is locked, 1902 // we do resource lookups. 1903 // Mutex is not reentrant, so we must use a different lock than mLock. 1904 mutable Mutex mFilteredConfigLock; 1905 1906 status_t mError; 1907 1908 ResTable_config mParams; 1909 1910 // Array of all resource tables. 1911 Vector<Header*> mHeaders; 1912 1913 // Array of packages in all resource tables. 1914 Vector<PackageGroup*> mPackageGroups; 1915 1916 // Mapping from resource package IDs to indices into the internal 1917 // package array. 1918 uint8_t mPackageMap[256]; 1919 1920 uint8_t mNextPackageId; 1921}; 1922 1923} // namespace android 1924 1925#endif // _LIBS_UTILS_RESOURCE_TYPES_H 1926