blob: a845908f9ec81d8cb8430a35d9f1f80b3b0963b9 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 <utils/Asset.h>
24#include <utils/ByteOrder.h>
25#include <utils/Errors.h>
26#include <utils/String16.h>
27#include <utils/Vector.h>
28
29#include <utils/threads.h>
30
31#include <stdint.h>
32#include <sys/types.h>
33
34namespace android {
35
36/** ********************************************************************
37 * PNG Extensions
38 *
39 * New private chunks that may be placed in PNG images.
40 *
41 *********************************************************************** */
42
43/**
44 * This chunk specifies how to split an image into segments for
45 * scaling.
46 *
47 * There are J horizontal and K vertical segments. These segments divide
48 * the image into J*K regions as follows (where J=4 and K=3):
49 *
50 * F0 S0 F1 S1
51 * +-----+----+------+-------+
52 * S2| 0 | 1 | 2 | 3 |
53 * +-----+----+------+-------+
54 * | | | | |
55 * | | | | |
56 * F2| 4 | 5 | 6 | 7 |
57 * | | | | |
58 * | | | | |
59 * +-----+----+------+-------+
60 * S3| 8 | 9 | 10 | 11 |
61 * +-----+----+------+-------+
62 *
63 * Each horizontal and vertical segment is considered to by either
64 * stretchable (marked by the Sx labels) or fixed (marked by the Fy
65 * labels), in the horizontal or vertical axis, respectively. In the
66 * above example, the first is horizontal segment (F0) is fixed, the
67 * next is stretchable and then they continue to alternate. Note that
68 * the segment list for each axis can begin or end with a stretchable
69 * or fixed segment.
70 *
71 * The relative sizes of the stretchy segments indicates the relative
72 * amount of stretchiness of the regions bordered by the segments. For
73 * example, regions 3, 7 and 11 above will take up more horizontal space
Mathias Agopian5f910972009-06-22 02:35:32 -070074 * than regions 1, 5 and 9 since the horizontal segment associated with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 * the first set of regions is larger than the other set of regions. The
76 * ratios of the amount of horizontal (or vertical) space taken by any
77 * two stretchable slices is exactly the ratio of their corresponding
78 * segment lengths.
79 *
80 * xDivs and yDivs point to arrays of horizontal and vertical pixel
81 * indices. The first pair of Divs (in either array) indicate the
82 * starting and ending points of the first stretchable segment in that
83 * axis. The next pair specifies the next stretchable segment, etc. So
84 * in the above example xDiv[0] and xDiv[1] specify the horizontal
85 * coordinates for the regions labeled 1, 5 and 9. xDiv[2] and
86 * xDiv[3] specify the coordinates for regions 3, 7 and 11. Note that
87 * the leftmost slices always start at x=0 and the rightmost slices
88 * always end at the end of the image. So, for example, the regions 0,
89 * 4 and 8 (which are fixed along the X axis) start at x value 0 and
Mathias Agopian5f910972009-06-22 02:35:32 -070090 * go to xDiv[0] and slices 2, 6 and 10 start at xDiv[1] and end at
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 * xDiv[2].
92 *
93 * The array pointed to by the colors field lists contains hints for
94 * each of the regions. They are ordered according left-to-right and
95 * top-to-bottom as indicated above. For each segment that is a solid
96 * color the array entry will contain that color value; otherwise it
97 * will contain NO_COLOR. Segments that are completely transparent
98 * will always have the value TRANSPARENT_COLOR.
99 *
100 * The PNG chunk type is "npTc".
101 */
102struct Res_png_9patch
103{
104 Res_png_9patch() : wasDeserialized(false), xDivs(NULL),
105 yDivs(NULL), colors(NULL) { }
106
107 int8_t wasDeserialized;
108 int8_t numXDivs;
109 int8_t numYDivs;
110 int8_t numColors;
111
112 // These tell where the next section of a patch starts.
113 // For example, the first patch includes the pixels from
114 // 0 to xDivs[0]-1 and the second patch includes the pixels
115 // from xDivs[0] to xDivs[1]-1.
116 // Note: allocation/free of these pointers is left to the caller.
117 int32_t* xDivs;
118 int32_t* yDivs;
119
120 int32_t paddingLeft, paddingRight;
121 int32_t paddingTop, paddingBottom;
122
123 enum {
124 // The 9 patch segment is not a solid color.
125 NO_COLOR = 0x00000001,
126
127 // The 9 patch segment is completely transparent.
128 TRANSPARENT_COLOR = 0x00000000
129 };
130 // Note: allocation/free of this pointer is left to the caller.
131 uint32_t* colors;
132
133 // Convert data from device representation to PNG file representation.
134 void deviceToFile();
135 // Convert data from PNG file representation to device representation.
136 void fileToDevice();
137 // Serialize/Marshall the patch data into a newly malloc-ed block
138 void* serialize();
139 // Serialize/Marshall the patch data
140 void serialize(void* outData);
141 // Deserialize/Unmarshall the patch data
142 static Res_png_9patch* deserialize(const void* data);
143 // Compute the size of the serialized data structure
144 size_t serializedSize();
145};
146
147/** ********************************************************************
148 * Base Types
149 *
150 * These are standard types that are shared between multiple specific
151 * resource types.
152 *
153 *********************************************************************** */
154
155/**
156 * Header that appears at the front of every data chunk in a resource.
157 */
158struct ResChunk_header
159{
160 // Type identifier for this chunk. The meaning of this value depends
161 // on the containing chunk.
162 uint16_t type;
163
164 // Size of the chunk header (in bytes). Adding this value to
165 // the address of the chunk allows you to find its associated data
166 // (if any).
167 uint16_t headerSize;
168
169 // Total size of this chunk (in bytes). This is the chunkSize plus
170 // the size of any data associated with the chunk. Adding this value
171 // to the chunk allows you to completely skip its contents (including
172 // any child chunks). If this value is the same as chunkSize, there is
173 // no data associated with the chunk.
174 uint32_t size;
175};
176
177enum {
178 RES_NULL_TYPE = 0x0000,
179 RES_STRING_POOL_TYPE = 0x0001,
180 RES_TABLE_TYPE = 0x0002,
181 RES_XML_TYPE = 0x0003,
182
183 // Chunk types in RES_XML_TYPE
184 RES_XML_FIRST_CHUNK_TYPE = 0x0100,
185 RES_XML_START_NAMESPACE_TYPE= 0x0100,
186 RES_XML_END_NAMESPACE_TYPE = 0x0101,
187 RES_XML_START_ELEMENT_TYPE = 0x0102,
188 RES_XML_END_ELEMENT_TYPE = 0x0103,
189 RES_XML_CDATA_TYPE = 0x0104,
190 RES_XML_LAST_CHUNK_TYPE = 0x017f,
191 // This contains a uint32_t array mapping strings in the string
192 // pool back to resource identifiers. It is optional.
193 RES_XML_RESOURCE_MAP_TYPE = 0x0180,
194
195 // Chunk types in RES_TABLE_TYPE
196 RES_TABLE_PACKAGE_TYPE = 0x0200,
197 RES_TABLE_TYPE_TYPE = 0x0201,
198 RES_TABLE_TYPE_SPEC_TYPE = 0x0202
199};
200
201/**
202 * Macros for building/splitting resource identifiers.
203 */
204#define Res_VALIDID(resid) (resid != 0)
205#define Res_CHECKID(resid) ((resid&0xFFFF0000) != 0)
206#define Res_MAKEID(package, type, entry) \
207 (((package+1)<<24) | (((type+1)&0xFF)<<16) | (entry&0xFFFF))
208#define Res_GETPACKAGE(id) ((id>>24)-1)
209#define Res_GETTYPE(id) (((id>>16)&0xFF)-1)
210#define Res_GETENTRY(id) (id&0xFFFF)
211
212#define Res_INTERNALID(resid) ((resid&0xFFFF0000) != 0 && (resid&0xFF0000) == 0)
213#define Res_MAKEINTERNAL(entry) (0x01000000 | (entry&0xFFFF))
214#define Res_MAKEARRAY(entry) (0x02000000 | (entry&0xFFFF))
215
216#define Res_MAXPACKAGE 255
217
218/**
219 * Representation of a value in a resource, supplying type
220 * information.
221 */
222struct Res_value
223{
224 // Number of bytes in this structure.
225 uint16_t size;
226
227 // Always set to 0.
228 uint8_t res0;
229
230 // Type of the data value.
231 enum {
232 // Contains no data.
233 TYPE_NULL = 0x00,
234 // The 'data' holds a ResTable_ref, a reference to another resource
235 // table entry.
236 TYPE_REFERENCE = 0x01,
237 // The 'data' holds an attribute resource identifier.
238 TYPE_ATTRIBUTE = 0x02,
239 // The 'data' holds an index into the containing resource table's
240 // global value string pool.
241 TYPE_STRING = 0x03,
242 // The 'data' holds a single-precision floating point number.
243 TYPE_FLOAT = 0x04,
244 // The 'data' holds a complex number encoding a dimension value,
245 // such as "100in".
246 TYPE_DIMENSION = 0x05,
247 // The 'data' holds a complex number encoding a fraction of a
248 // container.
249 TYPE_FRACTION = 0x06,
250
251 // Beginning of integer flavors...
252 TYPE_FIRST_INT = 0x10,
253
254 // The 'data' is a raw integer value of the form n..n.
255 TYPE_INT_DEC = 0x10,
256 // The 'data' is a raw integer value of the form 0xn..n.
257 TYPE_INT_HEX = 0x11,
258 // The 'data' is either 0 or 1, for input "false" or "true" respectively.
259 TYPE_INT_BOOLEAN = 0x12,
260
261 // Beginning of color integer flavors...
262 TYPE_FIRST_COLOR_INT = 0x1c,
263
264 // The 'data' is a raw integer value of the form #aarrggbb.
265 TYPE_INT_COLOR_ARGB8 = 0x1c,
266 // The 'data' is a raw integer value of the form #rrggbb.
267 TYPE_INT_COLOR_RGB8 = 0x1d,
268 // The 'data' is a raw integer value of the form #argb.
269 TYPE_INT_COLOR_ARGB4 = 0x1e,
270 // The 'data' is a raw integer value of the form #rgb.
271 TYPE_INT_COLOR_RGB4 = 0x1f,
272
273 // ...end of integer flavors.
274 TYPE_LAST_COLOR_INT = 0x1f,
275
276 // ...end of integer flavors.
277 TYPE_LAST_INT = 0x1f
278 };
279 uint8_t dataType;
280
281 // Structure of complex data values (TYPE_UNIT and TYPE_FRACTION)
282 enum {
283 // Where the unit type information is. This gives us 16 possible
284 // types, as defined below.
285 COMPLEX_UNIT_SHIFT = 0,
286 COMPLEX_UNIT_MASK = 0xf,
287
288 // TYPE_DIMENSION: Value is raw pixels.
289 COMPLEX_UNIT_PX = 0,
290 // TYPE_DIMENSION: Value is Device Independent Pixels.
291 COMPLEX_UNIT_DIP = 1,
292 // TYPE_DIMENSION: Value is a Scaled device independent Pixels.
293 COMPLEX_UNIT_SP = 2,
294 // TYPE_DIMENSION: Value is in points.
295 COMPLEX_UNIT_PT = 3,
296 // TYPE_DIMENSION: Value is in inches.
297 COMPLEX_UNIT_IN = 4,
298 // TYPE_DIMENSION: Value is in millimeters.
299 COMPLEX_UNIT_MM = 5,
300
301 // TYPE_FRACTION: A basic fraction of the overall size.
302 COMPLEX_UNIT_FRACTION = 0,
303 // TYPE_FRACTION: A fraction of the parent size.
304 COMPLEX_UNIT_FRACTION_PARENT = 1,
305
306 // Where the radix information is, telling where the decimal place
307 // appears in the mantissa. This give us 4 possible fixed point
308 // representations as defined below.
309 COMPLEX_RADIX_SHIFT = 4,
310 COMPLEX_RADIX_MASK = 0x3,
311
312 // The mantissa is an integral number -- i.e., 0xnnnnnn.0
313 COMPLEX_RADIX_23p0 = 0,
314 // The mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn
315 COMPLEX_RADIX_16p7 = 1,
316 // The mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn
317 COMPLEX_RADIX_8p15 = 2,
318 // The mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn
319 COMPLEX_RADIX_0p23 = 3,
320
321 // Where the actual value is. This gives us 23 bits of
322 // precision. The top bit is the sign.
323 COMPLEX_MANTISSA_SHIFT = 8,
324 COMPLEX_MANTISSA_MASK = 0xffffff
325 };
326
327 // The data for this item, as interpreted according to dataType.
328 uint32_t data;
329
330 void copyFrom_dtoh(const Res_value& src);
331};
332
333/**
334 * This is a reference to a unique entry (a ResTable_entry structure)
335 * in a resource table. The value is structured as: 0xpptteeee,
336 * where pp is the package index, tt is the type index in that
337 * package, and eeee is the entry index in that type. The package
338 * and type values start at 1 for the first item, to help catch cases
339 * where they have not been supplied.
340 */
341struct ResTable_ref
342{
343 uint32_t ident;
344};
345
346/**
347 * Reference to a string in a string pool.
348 */
349struct ResStringPool_ref
350{
351 // Index into the string pool table (uint32_t-offset from the indices
352 // immediately after ResStringPool_header) at which to find the location
353 // of the string data in the pool.
354 uint32_t index;
355};
356
357/** ********************************************************************
358 * String Pool
359 *
360 * A set of strings that can be references by others through a
361 * ResStringPool_ref.
362 *
363 *********************************************************************** */
364
365/**
366 * Definition for a pool of strings. The data of this chunk is an
367 * array of uint32_t providing indices into the pool, relative to
368 * stringsStart. At stringsStart are all of the UTF-16 strings
369 * concatenated together; each starts with a uint16_t of the string's
370 * length and each ends with a 0x0000 terminator. If a string is >
371 * 32767 characters, the high bit of the length is set meaning to take
372 * those 15 bits as a high word and it will be followed by another
373 * uint16_t containing the low word.
374 *
375 * If styleCount is not zero, then immediately following the array of
376 * uint32_t indices into the string table is another array of indices
377 * into a style table starting at stylesStart. Each entry in the
378 * style table is an array of ResStringPool_span structures.
379 */
380struct ResStringPool_header
381{
382 struct ResChunk_header header;
383
384 // Number of strings in this pool (number of uint32_t indices that follow
385 // in the data).
386 uint32_t stringCount;
387
388 // Number of style span arrays in the pool (number of uint32_t indices
389 // follow the string indices).
390 uint32_t styleCount;
391
392 // Flags.
393 enum {
394 // If set, the string index is sorted by the string values (based
395 // on strcmp16()).
Kenny Root19138462009-12-04 09:38:48 -0800396 SORTED_FLAG = 1<<0,
397
398 // String pool is encoded in UTF-8
399 UTF8_FLAG = 1<<8
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 };
401 uint32_t flags;
402
403 // Index from header of the string data.
404 uint32_t stringsStart;
405
406 // Index from header of the style data.
407 uint32_t stylesStart;
408};
409
410/**
411 * This structure defines a span of style information associated with
412 * a string in the pool.
413 */
414struct ResStringPool_span
415{
416 enum {
417 END = 0xFFFFFFFF
418 };
419
420 // This is the name of the span -- that is, the name of the XML
421 // tag that defined it. The special value END (0xFFFFFFFF) indicates
422 // the end of an array of spans.
423 ResStringPool_ref name;
424
425 // The range of characters in the string that this span applies to.
426 uint32_t firstChar, lastChar;
427};
428
429/**
430 * Convenience class for accessing data in a ResStringPool resource.
431 */
432class ResStringPool
433{
434public:
435 ResStringPool();
436 ResStringPool(const void* data, size_t size, bool copyData=false);
437 ~ResStringPool();
438
439 status_t setTo(const void* data, size_t size, bool copyData=false);
440
441 status_t getError() const;
442
443 void uninit();
444
445 inline const char16_t* stringAt(const ResStringPool_ref& ref, size_t* outLen) const {
446 return stringAt(ref.index, outLen);
447 }
448 const char16_t* stringAt(size_t idx, size_t* outLen) const;
449
450 const ResStringPool_span* styleAt(const ResStringPool_ref& ref) const;
451 const ResStringPool_span* styleAt(size_t idx) const;
452
453 ssize_t indexOfString(const char16_t* str, size_t strLen) const;
454
455 size_t size() const;
456
457private:
458 status_t mError;
459 void* mOwnedData;
460 const ResStringPool_header* mHeader;
461 size_t mSize;
Kenny Root19138462009-12-04 09:38:48 -0800462 mutable Mutex mDecodeLock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 const uint32_t* mEntries;
464 const uint32_t* mEntryStyles;
Kenny Root19138462009-12-04 09:38:48 -0800465 const void* mStrings;
466 char16_t** mCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 uint32_t mStringPoolSize; // number of uint16_t
468 const uint32_t* mStyles;
469 uint32_t mStylePoolSize; // number of uint32_t
470};
471
472/** ********************************************************************
473 * XML Tree
474 *
475 * Binary representation of an XML document. This is designed to
476 * express everything in an XML document, in a form that is much
477 * easier to parse on the device.
478 *
479 *********************************************************************** */
480
481/**
482 * XML tree header. This appears at the front of an XML tree,
483 * describing its content. It is followed by a flat array of
484 * ResXMLTree_node structures; the hierarchy of the XML document
485 * is described by the occurrance of RES_XML_START_ELEMENT_TYPE
486 * and corresponding RES_XML_END_ELEMENT_TYPE nodes in the array.
487 */
488struct ResXMLTree_header
489{
490 struct ResChunk_header header;
491};
492
493/**
494 * Basic XML tree node. A single item in the XML document. Extended info
495 * about the node can be found after header.headerSize.
496 */
497struct ResXMLTree_node
498{
499 struct ResChunk_header header;
500
501 // Line number in original source file at which this element appeared.
502 uint32_t lineNumber;
503
504 // Optional XML comment that was associated with this element; -1 if none.
505 struct ResStringPool_ref comment;
506};
507
508/**
509 * Extended XML tree node for CDATA tags -- includes the CDATA string.
510 * Appears header.headerSize bytes after a ResXMLTree_node.
511 */
512struct ResXMLTree_cdataExt
513{
514 // The raw CDATA character data.
515 struct ResStringPool_ref data;
516
517 // The typed value of the character data if this is a CDATA node.
518 struct Res_value typedData;
519};
520
521/**
522 * Extended XML tree node for namespace start/end nodes.
523 * Appears header.headerSize bytes after a ResXMLTree_node.
524 */
525struct ResXMLTree_namespaceExt
526{
527 // The prefix of the namespace.
528 struct ResStringPool_ref prefix;
529
530 // The URI of the namespace.
531 struct ResStringPool_ref uri;
532};
533
534/**
535 * Extended XML tree node for element start/end nodes.
536 * Appears header.headerSize bytes after a ResXMLTree_node.
537 */
538struct ResXMLTree_endElementExt
539{
540 // String of the full namespace of this element.
541 struct ResStringPool_ref ns;
542
543 // String name of this node if it is an ELEMENT; the raw
544 // character data if this is a CDATA node.
545 struct ResStringPool_ref name;
546};
547
548/**
549 * Extended XML tree node for start tags -- includes attribute
550 * information.
551 * Appears header.headerSize bytes after a ResXMLTree_node.
552 */
553struct ResXMLTree_attrExt
554{
555 // String of the full namespace of this element.
556 struct ResStringPool_ref ns;
557
558 // String name of this node if it is an ELEMENT; the raw
559 // character data if this is a CDATA node.
560 struct ResStringPool_ref name;
561
562 // Byte offset from the start of this structure where the attributes start.
563 uint16_t attributeStart;
564
565 // Size of the ResXMLTree_attribute structures that follow.
566 uint16_t attributeSize;
567
568 // Number of attributes associated with an ELEMENT. These are
569 // available as an array of ResXMLTree_attribute structures
570 // immediately following this node.
571 uint16_t attributeCount;
572
573 // Index (1-based) of the "id" attribute. 0 if none.
574 uint16_t idIndex;
575
576 // Index (1-based) of the "class" attribute. 0 if none.
577 uint16_t classIndex;
578
579 // Index (1-based) of the "style" attribute. 0 if none.
580 uint16_t styleIndex;
581};
582
583struct ResXMLTree_attribute
584{
585 // Namespace of this attribute.
586 struct ResStringPool_ref ns;
587
588 // Name of this attribute.
589 struct ResStringPool_ref name;
590
591 // The original raw string value of this attribute.
592 struct ResStringPool_ref rawValue;
593
594 // Processesd typed value of this attribute.
595 struct Res_value typedValue;
596};
597
598class ResXMLTree;
599
600class ResXMLParser
601{
602public:
603 ResXMLParser(const ResXMLTree& tree);
604
605 enum event_code_t {
606 BAD_DOCUMENT = -1,
607 START_DOCUMENT = 0,
608 END_DOCUMENT = 1,
609
610 FIRST_CHUNK_CODE = RES_XML_FIRST_CHUNK_TYPE,
611
612 START_NAMESPACE = RES_XML_START_NAMESPACE_TYPE,
613 END_NAMESPACE = RES_XML_END_NAMESPACE_TYPE,
614 START_TAG = RES_XML_START_ELEMENT_TYPE,
615 END_TAG = RES_XML_END_ELEMENT_TYPE,
616 TEXT = RES_XML_CDATA_TYPE
617 };
618
619 struct ResXMLPosition
620 {
621 event_code_t eventCode;
622 const ResXMLTree_node* curNode;
623 const void* curExt;
624 };
625
626 void restart();
627
628 event_code_t getEventType() const;
629 // Note, unlike XmlPullParser, the first call to next() will return
630 // START_TAG of the first element.
631 event_code_t next();
632
633 // These are available for all nodes:
Mathias Agopian5f910972009-06-22 02:35:32 -0700634 int32_t getCommentID() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 const uint16_t* getComment(size_t* outLen) const;
Mathias Agopian5f910972009-06-22 02:35:32 -0700636 uint32_t getLineNumber() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637
638 // This is available for TEXT:
Mathias Agopian5f910972009-06-22 02:35:32 -0700639 int32_t getTextID() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 const uint16_t* getText(size_t* outLen) const;
641 ssize_t getTextValue(Res_value* outValue) const;
642
643 // These are available for START_NAMESPACE and END_NAMESPACE:
Mathias Agopian5f910972009-06-22 02:35:32 -0700644 int32_t getNamespacePrefixID() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 const uint16_t* getNamespacePrefix(size_t* outLen) const;
Mathias Agopian5f910972009-06-22 02:35:32 -0700646 int32_t getNamespaceUriID() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 const uint16_t* getNamespaceUri(size_t* outLen) const;
648
649 // These are available for START_TAG and END_TAG:
Mathias Agopian5f910972009-06-22 02:35:32 -0700650 int32_t getElementNamespaceID() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 const uint16_t* getElementNamespace(size_t* outLen) const;
Mathias Agopian5f910972009-06-22 02:35:32 -0700652 int32_t getElementNameID() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 const uint16_t* getElementName(size_t* outLen) const;
654
655 // Remaining methods are for retrieving information about attributes
656 // associated with a START_TAG:
657
658 size_t getAttributeCount() const;
659
660 // Returns -1 if no namespace, -2 if idx out of range.
Mathias Agopian5f910972009-06-22 02:35:32 -0700661 int32_t getAttributeNamespaceID(size_t idx) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 const uint16_t* getAttributeNamespace(size_t idx, size_t* outLen) const;
663
Mathias Agopian5f910972009-06-22 02:35:32 -0700664 int32_t getAttributeNameID(size_t idx) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 const uint16_t* getAttributeName(size_t idx, size_t* outLen) const;
Mathias Agopian5f910972009-06-22 02:35:32 -0700666 uint32_t getAttributeNameResID(size_t idx) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667
Mathias Agopian5f910972009-06-22 02:35:32 -0700668 int32_t getAttributeValueStringID(size_t idx) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 const uint16_t* getAttributeStringValue(size_t idx, size_t* outLen) const;
670
671 int32_t getAttributeDataType(size_t idx) const;
672 int32_t getAttributeData(size_t idx) const;
673 ssize_t getAttributeValue(size_t idx, Res_value* outValue) const;
674
675 ssize_t indexOfAttribute(const char* ns, const char* attr) const;
676 ssize_t indexOfAttribute(const char16_t* ns, size_t nsLen,
677 const char16_t* attr, size_t attrLen) const;
678
679 ssize_t indexOfID() const;
680 ssize_t indexOfClass() const;
681 ssize_t indexOfStyle() const;
682
683 void getPosition(ResXMLPosition* pos) const;
684 void setPosition(const ResXMLPosition& pos);
685
686private:
687 friend class ResXMLTree;
688
689 event_code_t nextNode();
690
691 const ResXMLTree& mTree;
692 event_code_t mEventCode;
693 const ResXMLTree_node* mCurNode;
694 const void* mCurExt;
695};
696
697/**
698 * Convenience class for accessing data in a ResXMLTree resource.
699 */
700class ResXMLTree : public ResXMLParser
701{
702public:
703 ResXMLTree();
704 ResXMLTree(const void* data, size_t size, bool copyData=false);
705 ~ResXMLTree();
706
707 status_t setTo(const void* data, size_t size, bool copyData=false);
708
709 status_t getError() const;
710
711 void uninit();
712
713 const ResStringPool& getStrings() const;
714
715private:
716 friend class ResXMLParser;
717
718 status_t validateNode(const ResXMLTree_node* node) const;
719
720 status_t mError;
721 void* mOwnedData;
722 const ResXMLTree_header* mHeader;
723 size_t mSize;
724 const uint8_t* mDataEnd;
725 ResStringPool mStrings;
726 const uint32_t* mResIds;
727 size_t mNumResIds;
728 const ResXMLTree_node* mRootNode;
729 const void* mRootExt;
730 event_code_t mRootCode;
731};
732
733/** ********************************************************************
734 * RESOURCE TABLE
735 *
736 *********************************************************************** */
737
738/**
739 * Header for a resource table. Its data contains a series of
740 * additional chunks:
741 * * A ResStringPool_header containing all table values.
742 * * One or more ResTable_package chunks.
743 *
744 * Specific entries within a resource table can be uniquely identified
745 * with a single integer as defined by the ResTable_ref structure.
746 */
747struct ResTable_header
748{
749 struct ResChunk_header header;
750
751 // The number of ResTable_package structures.
752 uint32_t packageCount;
753};
754
755/**
756 * A collection of resource data types within a package. Followed by
757 * one or more ResTable_type and ResTable_typeSpec structures containing the
758 * entry values for each resource type.
759 */
760struct ResTable_package
761{
762 struct ResChunk_header header;
763
764 // If this is a base package, its ID. Package IDs start
765 // at 1 (corresponding to the value of the package bits in a
766 // resource identifier). 0 means this is not a base package.
767 uint32_t id;
768
769 // Actual name of this package, \0-terminated.
770 char16_t name[128];
771
772 // Offset to a ResStringPool_header defining the resource
773 // type symbol table. If zero, this package is inheriting from
774 // another base package (overriding specific values in it).
775 uint32_t typeStrings;
776
777 // Last index into typeStrings that is for public use by others.
778 uint32_t lastPublicType;
779
780 // Offset to a ResStringPool_header defining the resource
781 // key symbol table. If zero, this package is inheriting from
782 // another base package (overriding specific values in it).
783 uint32_t keyStrings;
784
785 // Last index into keyStrings that is for public use by others.
786 uint32_t lastPublicKey;
787};
788
789/**
790 * Describes a particular resource configuration.
791 */
792struct ResTable_config
793{
794 // Number of bytes in this structure.
795 uint32_t size;
796
797 union {
798 struct {
799 // Mobile country code (from SIM). 0 means "any".
800 uint16_t mcc;
801 // Mobile network code (from SIM). 0 means "any".
802 uint16_t mnc;
803 };
804 uint32_t imsi;
805 };
806
807 union {
808 struct {
809 // \0\0 means "any". Otherwise, en, fr, etc.
810 char language[2];
811
812 // \0\0 means "any". Otherwise, US, CA, etc.
813 char country[2];
814 };
815 uint32_t locale;
816 };
817
818 enum {
819 ORIENTATION_ANY = 0x0000,
820 ORIENTATION_PORT = 0x0001,
821 ORIENTATION_LAND = 0x0002,
The Android Open Source Project10592532009-03-18 17:39:46 -0700822 ORIENTATION_SQUARE = 0x0003,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 };
824
825 enum {
826 TOUCHSCREEN_ANY = 0x0000,
827 TOUCHSCREEN_NOTOUCH = 0x0001,
828 TOUCHSCREEN_STYLUS = 0x0002,
829 TOUCHSCREEN_FINGER = 0x0003,
830 };
831
832 enum {
Dianne Hackborna53b8282009-07-17 11:13:48 -0700833 DENSITY_DEFAULT = 0,
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700834 DENSITY_LOW = 120,
835 DENSITY_MEDIUM = 160,
836 DENSITY_HIGH = 240,
Dianne Hackborna53b8282009-07-17 11:13:48 -0700837 DENSITY_NONE = 0xffff
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 };
839
840 union {
841 struct {
842 uint8_t orientation;
843 uint8_t touchscreen;
844 uint16_t density;
845 };
846 uint32_t screenType;
847 };
848
849 enum {
850 KEYBOARD_ANY = 0x0000,
851 KEYBOARD_NOKEYS = 0x0001,
852 KEYBOARD_QWERTY = 0x0002,
853 KEYBOARD_12KEY = 0x0003,
854 };
855
856 enum {
857 NAVIGATION_ANY = 0x0000,
858 NAVIGATION_NONAV = 0x0001,
859 NAVIGATION_DPAD = 0x0002,
860 NAVIGATION_TRACKBALL = 0x0003,
861 NAVIGATION_WHEEL = 0x0004,
862 };
863
864 enum {
865 MASK_KEYSHIDDEN = 0x0003,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 KEYSHIDDEN_ANY = 0x0000,
867 KEYSHIDDEN_NO = 0x0001,
868 KEYSHIDDEN_YES = 0x0002,
869 KEYSHIDDEN_SOFT = 0x0003,
870 };
871
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700872 enum {
873 MASK_NAVHIDDEN = 0x000c,
874 NAVHIDDEN_ANY = 0x0000,
875 NAVHIDDEN_NO = 0x0004,
876 NAVHIDDEN_YES = 0x0008,
877 };
878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 union {
880 struct {
881 uint8_t keyboard;
882 uint8_t navigation;
883 uint8_t inputFlags;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700884 uint8_t inputPad0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 };
886 uint32_t input;
887 };
888
889 enum {
890 SCREENWIDTH_ANY = 0
891 };
892
893 enum {
894 SCREENHEIGHT_ANY = 0
895 };
896
897 union {
898 struct {
899 uint16_t screenWidth;
900 uint16_t screenHeight;
901 };
902 uint32_t screenSize;
903 };
904
905 enum {
906 SDKVERSION_ANY = 0
907 };
908
909 enum {
910 MINORVERSION_ANY = 0
911 };
912
913 union {
914 struct {
915 uint16_t sdkVersion;
916 // For now minorVersion must always be 0!!! Its meaning
917 // is currently undefined.
918 uint16_t minorVersion;
919 };
920 uint32_t version;
921 };
922
Dianne Hackborn723738c2009-06-25 19:48:04 -0700923 enum {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700924 // screenLayout bits for screen size class.
925 MASK_SCREENSIZE = 0x0f,
926 SCREENSIZE_ANY = 0x00,
927 SCREENSIZE_SMALL = 0x01,
928 SCREENSIZE_NORMAL = 0x02,
929 SCREENSIZE_LARGE = 0x03,
930
931 // screenLayout bits for wide/long screen variation.
932 MASK_SCREENLONG = 0x30,
933 SCREENLONG_ANY = 0x00,
934 SCREENLONG_NO = 0x10,
935 SCREENLONG_YES = 0x20,
Dianne Hackborn723738c2009-06-25 19:48:04 -0700936 };
937
938 union {
939 struct {
940 uint8_t screenLayout;
941 uint8_t screenConfigPad0;
942 uint8_t screenConfigPad1;
943 uint8_t screenConfigPad2;
944 };
945 uint32_t screenConfig;
946 };
947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 inline void copyFromDeviceNoSwap(const ResTable_config& o) {
949 const size_t size = dtohl(o.size);
950 if (size >= sizeof(ResTable_config)) {
951 *this = o;
952 } else {
953 memcpy(this, &o, size);
954 memset(((uint8_t*)this)+size, 0, sizeof(ResTable_config)-size);
955 }
956 }
957
958 inline void copyFromDtoH(const ResTable_config& o) {
959 copyFromDeviceNoSwap(o);
960 size = sizeof(ResTable_config);
961 mcc = dtohs(mcc);
962 mnc = dtohs(mnc);
963 density = dtohs(density);
964 screenWidth = dtohs(screenWidth);
965 screenHeight = dtohs(screenHeight);
966 sdkVersion = dtohs(sdkVersion);
967 minorVersion = dtohs(minorVersion);
968 }
969
970 inline void swapHtoD() {
971 size = htodl(size);
972 mcc = htods(mcc);
973 mnc = htods(mnc);
974 density = htods(density);
975 screenWidth = htods(screenWidth);
976 screenHeight = htods(screenHeight);
977 sdkVersion = htods(sdkVersion);
978 minorVersion = htods(minorVersion);
979 }
980
981 inline int compare(const ResTable_config& o) const {
982 int32_t diff = (int32_t)(imsi - o.imsi);
983 if (diff != 0) return diff;
984 diff = (int32_t)(locale - o.locale);
985 if (diff != 0) return diff;
986 diff = (int32_t)(screenType - o.screenType);
987 if (diff != 0) return diff;
988 diff = (int32_t)(input - o.input);
989 if (diff != 0) return diff;
990 diff = (int32_t)(screenSize - o.screenSize);
991 if (diff != 0) return diff;
992 diff = (int32_t)(version - o.version);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700993 if (diff != 0) return diff;
994 diff = (int32_t)(screenLayout - o.screenLayout);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 return (int)diff;
996 }
997
998 // Flags indicating a set of config values. These flag constants must
999 // match the corresponding ones in android.content.pm.ActivityInfo and
1000 // attrs_manifest.xml.
1001 enum {
1002 CONFIG_MCC = 0x0001,
1003 CONFIG_MNC = 0x0002,
1004 CONFIG_LOCALE = 0x0004,
1005 CONFIG_TOUCHSCREEN = 0x0008,
1006 CONFIG_KEYBOARD = 0x0010,
1007 CONFIG_KEYBOARD_HIDDEN = 0x0020,
1008 CONFIG_NAVIGATION = 0x0040,
1009 CONFIG_ORIENTATION = 0x0080,
1010 CONFIG_DENSITY = 0x0100,
1011 CONFIG_SCREEN_SIZE = 0x0200,
Dianne Hackborn723738c2009-06-25 19:48:04 -07001012 CONFIG_VERSION = 0x0400,
1013 CONFIG_SCREEN_LAYOUT = 0x0800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 };
1015
1016 // Compare two configuration, returning CONFIG_* flags set for each value
1017 // that is different.
1018 inline int diff(const ResTable_config& o) const {
1019 int diffs = 0;
1020 if (mcc != o.mcc) diffs |= CONFIG_MCC;
1021 if (mnc != o.mnc) diffs |= CONFIG_MNC;
1022 if (locale != o.locale) diffs |= CONFIG_LOCALE;
1023 if (orientation != o.orientation) diffs |= CONFIG_ORIENTATION;
1024 if (density != o.density) diffs |= CONFIG_DENSITY;
1025 if (touchscreen != o.touchscreen) diffs |= CONFIG_TOUCHSCREEN;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001026 if (((inputFlags^o.inputFlags)&(MASK_KEYSHIDDEN|MASK_NAVHIDDEN)) != 0)
1027 diffs |= CONFIG_KEYBOARD_HIDDEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 if (keyboard != o.keyboard) diffs |= CONFIG_KEYBOARD;
1029 if (navigation != o.navigation) diffs |= CONFIG_NAVIGATION;
1030 if (screenSize != o.screenSize) diffs |= CONFIG_SCREEN_SIZE;
1031 if (version != o.version) diffs |= CONFIG_VERSION;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001032 if (screenLayout != o.screenLayout) diffs |= CONFIG_SCREEN_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 return diffs;
1034 }
1035
Robert Greenwalt96e20402009-04-22 14:35:11 -07001036 // Return true if 'this' is more specific than 'o'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 inline bool
Robert Greenwalt96e20402009-04-22 14:35:11 -07001038 isMoreSpecificThan(const ResTable_config& o) const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 // The order of the following tests defines the importance of one
1040 // configuration parameter over another. Those tests first are more
1041 // important, trumping any values in those following them.
Robert Greenwalt96e20402009-04-22 14:35:11 -07001042 if (imsi || o.imsi) {
1043 if (mcc != o.mcc) {
1044 if (!mcc) return false;
1045 if (!o.mcc) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001047
1048 if (mnc != o.mnc) {
1049 if (!mnc) return false;
1050 if (!o.mnc) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 }
1052 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001053
1054 if (locale || o.locale) {
1055 if (language[0] != o.language[0]) {
1056 if (!language[0]) return false;
1057 if (!o.language[0]) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001059
1060 if (country[0] != o.country[0]) {
1061 if (!country[0]) return false;
1062 if (!o.country[0]) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 }
1064 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001065
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001066 if (screenConfig || o.screenConfig) {
1067 if (((screenLayout^o.screenLayout) & MASK_SCREENSIZE) != 0) {
1068 if (!(screenLayout & MASK_SCREENSIZE)) return false;
1069 if (!(o.screenLayout & MASK_SCREENSIZE)) return true;
1070 }
1071 if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0) {
1072 if (!(screenLayout & MASK_SCREENLONG)) return false;
1073 if (!(o.screenLayout & MASK_SCREENLONG)) return true;
1074 }
1075 }
1076
Robert Greenwalt96e20402009-04-22 14:35:11 -07001077 if (screenType || o.screenType) {
1078 if (orientation != o.orientation) {
1079 if (!orientation) return false;
1080 if (!o.orientation) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001082
1083 // density is never 'more specific'
1084 // as the default just equals 160
1085
1086 if (touchscreen != o.touchscreen) {
1087 if (!touchscreen) return false;
1088 if (!o.touchscreen) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 }
1090 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001091
1092 if (input || o.input) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001093 if (((inputFlags^o.inputFlags) & MASK_KEYSHIDDEN) != 0) {
Robert Greenwalt96e20402009-04-22 14:35:11 -07001094 if (!(inputFlags & MASK_KEYSHIDDEN)) return false;
1095 if (!(o.inputFlags & MASK_KEYSHIDDEN)) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001097
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001098 if (((inputFlags^o.inputFlags) & MASK_NAVHIDDEN) != 0) {
1099 if (!(inputFlags & MASK_NAVHIDDEN)) return false;
1100 if (!(o.inputFlags & MASK_NAVHIDDEN)) return true;
1101 }
1102
Robert Greenwalt96e20402009-04-22 14:35:11 -07001103 if (keyboard != o.keyboard) {
1104 if (!keyboard) return false;
1105 if (!o.keyboard) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001107
1108 if (navigation != o.navigation) {
1109 if (!navigation) return false;
1110 if (!o.navigation) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 }
1112 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001113
1114 if (screenSize || o.screenSize) {
1115 if (screenWidth != o.screenWidth) {
1116 if (!screenWidth) return false;
1117 if (!o.screenWidth) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001119
1120 if (screenHeight != o.screenHeight) {
1121 if (!screenHeight) return false;
1122 if (!o.screenHeight) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 }
1124 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001125
1126 if (version || o.version) {
1127 if (sdkVersion != o.sdkVersion) {
1128 if (!sdkVersion) return false;
1129 if (!o.sdkVersion) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001131
1132 if (minorVersion != o.minorVersion) {
1133 if (!minorVersion) return false;
1134 if (!o.minorVersion) return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 }
1136 }
1137 return false;
1138 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001139
1140 // Return true if 'this' is a better match than 'o' for the 'requested'
1141 // configuration. This assumes that match() has already been used to
1142 // remove any configurations that don't match the requested configuration
1143 // at all; if they are not first filtered, non-matching results can be
1144 // considered better than matching ones.
1145 // The general rule per attribute: if the request cares about an attribute
1146 // (it normally does), if the two (this and o) are equal it's a tie. If
1147 // they are not equal then one must be generic because only generic and
1148 // '==requested' will pass the match() call. So if this is not generic,
1149 // it wins. If this IS generic, o wins (return false).
1150 inline bool
1151 isBetterThan(const ResTable_config& o,
1152 const ResTable_config* requested) const {
1153 if (requested) {
1154 if (imsi || o.imsi) {
1155 if ((mcc != o.mcc) && requested->mcc) {
1156 return (mcc);
1157 }
1158
1159 if ((mnc != o.mnc) && requested->mnc) {
1160 return (mnc);
1161 }
1162 }
1163
1164 if (locale || o.locale) {
1165 if ((language[0] != o.language[0]) && requested->language[0]) {
1166 return (language[0]);
1167 }
1168
1169 if ((country[0] != o.country[0]) && requested->country[0]) {
1170 return (country[0]);
1171 }
1172 }
1173
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001174 if (screenConfig || o.screenConfig) {
1175 if (((screenLayout^o.screenLayout) & MASK_SCREENSIZE) != 0
1176 && (requested->screenLayout & MASK_SCREENSIZE)) {
1177 return (screenLayout & MASK_SCREENSIZE);
1178 }
1179 if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0
1180 && (requested->screenLayout & MASK_SCREENLONG)) {
1181 return (screenLayout & MASK_SCREENLONG);
1182 }
1183 }
1184
Robert Greenwalt96e20402009-04-22 14:35:11 -07001185 if (screenType || o.screenType) {
1186 if ((orientation != o.orientation) && requested->orientation) {
1187 return (orientation);
1188 }
1189
1190 if (density != o.density) {
1191 // density is tough. Any density is potentially useful
1192 // because the system will scale it. Scaling down
1193 // is generally better than scaling up.
1194 // Default density counts as 160dpi (the system default)
1195 // TODO - remove 160 constants
1196 int h = (density?density:160);
1197 int l = (o.density?o.density:160);
1198 bool bImBigger = true;
1199 if (l > h) {
1200 int t = h;
1201 h = l;
1202 l = t;
1203 bImBigger = false;
1204 }
1205
1206 int reqValue = (requested->density?requested->density:160);
1207 if (reqValue >= h) {
1208 // requested value higher than both l and h, give h
1209 return bImBigger;
1210 }
1211 if (l >= reqValue) {
1212 // requested value lower than both l and h, give l
1213 return !bImBigger;
1214 }
1215 // saying that scaling down is 2x better than up
1216 if (((2 * l) - reqValue) * h > reqValue * reqValue) {
1217 return !bImBigger;
1218 } else {
1219 return bImBigger;
1220 }
1221 }
1222
1223 if ((touchscreen != o.touchscreen) && requested->touchscreen) {
1224 return (touchscreen);
1225 }
1226 }
1227
1228 if (input || o.input) {
1229 const int keysHidden = inputFlags & MASK_KEYSHIDDEN;
1230 const int oKeysHidden = o.inputFlags & MASK_KEYSHIDDEN;
1231 if (keysHidden != oKeysHidden) {
1232 const int reqKeysHidden =
1233 requested->inputFlags & MASK_KEYSHIDDEN;
1234 if (reqKeysHidden) {
1235
1236 if (!keysHidden) return false;
1237 if (!oKeysHidden) return true;
1238 // For compatibility, we count KEYSHIDDEN_NO as being
1239 // the same as KEYSHIDDEN_SOFT. Here we disambiguate
1240 // these by making an exact match more specific.
1241 if (reqKeysHidden == keysHidden) return true;
1242 if (reqKeysHidden == oKeysHidden) return false;
1243 }
1244 }
1245
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001246 const int navHidden = inputFlags & MASK_NAVHIDDEN;
1247 const int oNavHidden = o.inputFlags & MASK_NAVHIDDEN;
1248 if (navHidden != oNavHidden) {
1249 const int reqNavHidden =
1250 requested->inputFlags & MASK_NAVHIDDEN;
1251 if (reqNavHidden) {
1252
1253 if (!navHidden) return false;
1254 if (!oNavHidden) return true;
1255 }
1256 }
1257
Robert Greenwalt96e20402009-04-22 14:35:11 -07001258 if ((keyboard != o.keyboard) && requested->keyboard) {
1259 return (keyboard);
1260 }
1261
1262 if ((navigation != o.navigation) && requested->navigation) {
1263 return (navigation);
1264 }
1265 }
1266
1267 if (screenSize || o.screenSize) {
1268 if ((screenWidth != o.screenWidth) && requested->screenWidth) {
1269 return (screenWidth);
1270 }
1271
1272 if ((screenHeight != o.screenHeight) &&
1273 requested->screenHeight) {
1274 return (screenHeight);
1275 }
1276 }
1277
1278 if (version || o.version) {
1279 if ((sdkVersion != o.sdkVersion) && requested->sdkVersion) {
Dianne Hackborn55339952009-11-01 21:16:59 -08001280 return (sdkVersion > o.sdkVersion);
Robert Greenwalt96e20402009-04-22 14:35:11 -07001281 }
1282
1283 if ((minorVersion != o.minorVersion) &&
1284 requested->minorVersion) {
1285 return (minorVersion);
1286 }
1287 }
1288
1289 return false;
1290 }
1291 return isMoreSpecificThan(o);
1292 }
1293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 // Return true if 'this' can be considered a match for the parameters in
1295 // 'settings'.
1296 // Note this is asymetric. A default piece of data will match every request
1297 // but a request for the default should not match odd specifics
1298 // (ie, request with no mcc should not match a particular mcc's data)
1299 // settings is the requested settings
1300 inline bool match(const ResTable_config& settings) const {
1301 if (imsi != 0) {
1302 if ((settings.mcc != 0 && mcc != 0
1303 && mcc != settings.mcc) ||
1304 (settings.mcc == 0 && mcc != 0)) {
1305 return false;
1306 }
1307 if ((settings.mnc != 0 && mnc != 0
1308 && mnc != settings.mnc) ||
1309 (settings.mnc == 0 && mnc != 0)) {
1310 return false;
1311 }
1312 }
1313 if (locale != 0) {
1314 if (settings.language[0] != 0 && language[0] != 0
1315 && (language[0] != settings.language[0]
1316 || language[1] != settings.language[1])) {
1317 return false;
1318 }
1319 if (settings.country[0] != 0 && country[0] != 0
1320 && (country[0] != settings.country[0]
1321 || country[1] != settings.country[1])) {
1322 return false;
1323 }
1324 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001325 if (screenConfig != 0) {
1326 const int screenSize = screenLayout&MASK_SCREENSIZE;
1327 const int setScreenSize = settings.screenLayout&MASK_SCREENSIZE;
1328 if (setScreenSize != 0 && screenSize != 0
1329 && screenSize != setScreenSize) {
1330 return false;
1331 }
1332
1333 const int screenLong = screenLayout&MASK_SCREENLONG;
1334 const int setScreenLong = settings.screenLayout&MASK_SCREENLONG;
1335 if (setScreenLong != 0 && screenLong != 0
1336 && screenLong != setScreenLong) {
1337 return false;
1338 }
1339 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 if (screenType != 0) {
1341 if (settings.orientation != 0 && orientation != 0
1342 && orientation != settings.orientation) {
1343 return false;
1344 }
Robert Greenwalt96e20402009-04-22 14:35:11 -07001345 // density always matches - we can scale it. See isBetterThan
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 if (settings.touchscreen != 0 && touchscreen != 0
1347 && touchscreen != settings.touchscreen) {
1348 return false;
1349 }
1350 }
1351 if (input != 0) {
1352 const int keysHidden = inputFlags&MASK_KEYSHIDDEN;
1353 const int setKeysHidden = settings.inputFlags&MASK_KEYSHIDDEN;
1354 if (setKeysHidden != 0 && keysHidden != 0
1355 && keysHidden != setKeysHidden) {
1356 // For compatibility, we count a request for KEYSHIDDEN_NO as also
1357 // matching the more recent KEYSHIDDEN_SOFT. Basically
1358 // KEYSHIDDEN_NO means there is some kind of keyboard available.
1359 //LOGI("Matching keysHidden: have=%d, config=%d\n", keysHidden, setKeysHidden);
1360 if (keysHidden != KEYSHIDDEN_NO || setKeysHidden != KEYSHIDDEN_SOFT) {
1361 //LOGI("No match!");
1362 return false;
1363 }
1364 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001365 const int navHidden = inputFlags&MASK_NAVHIDDEN;
1366 const int setNavHidden = settings.inputFlags&MASK_NAVHIDDEN;
1367 if (setNavHidden != 0 && navHidden != 0
1368 && navHidden != setNavHidden) {
1369 return false;
1370 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 if (settings.keyboard != 0 && keyboard != 0
1372 && keyboard != settings.keyboard) {
1373 return false;
1374 }
1375 if (settings.navigation != 0 && navigation != 0
1376 && navigation != settings.navigation) {
1377 return false;
1378 }
1379 }
1380 if (screenSize != 0) {
1381 if (settings.screenWidth != 0 && screenWidth != 0
1382 && screenWidth != settings.screenWidth) {
1383 return false;
1384 }
1385 if (settings.screenHeight != 0 && screenHeight != 0
1386 && screenHeight != settings.screenHeight) {
1387 return false;
1388 }
1389 }
1390 if (version != 0) {
1391 if (settings.sdkVersion != 0 && sdkVersion != 0
Dianne Hackborn55339952009-11-01 21:16:59 -08001392 && sdkVersion > settings.sdkVersion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 return false;
1394 }
1395 if (settings.minorVersion != 0 && minorVersion != 0
1396 && minorVersion != settings.minorVersion) {
1397 return false;
1398 }
1399 }
1400 return true;
1401 }
1402
1403 void getLocale(char str[6]) const {
1404 memset(str, 0, 6);
1405 if (language[0]) {
1406 str[0] = language[0];
1407 str[1] = language[1];
1408 if (country[0]) {
1409 str[2] = '_';
1410 str[3] = country[0];
1411 str[4] = country[1];
1412 }
1413 }
1414 }
1415
1416 String8 toString() const {
1417 char buf[200];
Dianne Hackborn723738c2009-06-25 19:48:04 -07001418 sprintf(buf, "imsi=%d/%d lang=%c%c reg=%c%c orient=%d touch=%d dens=%d "
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001419 "kbd=%d nav=%d input=%d scrnW=%d scrnH=%d sz=%d long=%d vers=%d.%d",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 mcc, mnc,
1421 language[0] ? language[0] : '-', language[1] ? language[1] : '-',
1422 country[0] ? country[0] : '-', country[1] ? country[1] : '-',
1423 orientation, touchscreen, density, keyboard, navigation, inputFlags,
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07001424 screenWidth, screenHeight,
1425 screenLayout&MASK_SCREENSIZE, screenLayout&MASK_SCREENLONG,
1426 sdkVersion, minorVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 return String8(buf);
1428 }
1429};
1430
1431/**
1432 * A specification of the resources defined by a particular type.
1433 *
1434 * There should be one of these chunks for each resource type.
1435 *
1436 * This structure is followed by an array of integers providing the set of
1437 * configuation change flags (ResTable_config::CONFIG_*) that have multiple
1438 * resources for that configuration. In addition, the high bit is set if that
1439 * resource has been made public.
1440 */
1441struct ResTable_typeSpec
1442{
1443 struct ResChunk_header header;
1444
1445 // The type identifier this chunk is holding. Type IDs start
1446 // at 1 (corresponding to the value of the type bits in a
1447 // resource identifier). 0 is invalid.
1448 uint8_t id;
1449
1450 // Must be 0.
1451 uint8_t res0;
1452 // Must be 0.
1453 uint16_t res1;
1454
1455 // Number of uint32_t entry configuration masks that follow.
1456 uint32_t entryCount;
1457
1458 enum {
1459 // Additional flag indicating an entry is public.
1460 SPEC_PUBLIC = 0x40000000
1461 };
1462};
1463
1464/**
1465 * A collection of resource entries for a particular resource data
1466 * type. Followed by an array of uint32_t defining the resource
1467 * values, corresponding to the array of type strings in the
1468 * ResTable_package::typeStrings string block. Each of these hold an
1469 * index from entriesStart; a value of NO_ENTRY means that entry is
1470 * not defined.
1471 *
1472 * There may be multiple of these chunks for a particular resource type,
1473 * supply different configuration variations for the resource values of
1474 * that type.
1475 *
1476 * It would be nice to have an additional ordered index of entries, so
1477 * we can do a binary search if trying to find a resource by string name.
1478 */
1479struct ResTable_type
1480{
1481 struct ResChunk_header header;
1482
1483 enum {
1484 NO_ENTRY = 0xFFFFFFFF
1485 };
1486
1487 // The type identifier this chunk is holding. Type IDs start
1488 // at 1 (corresponding to the value of the type bits in a
1489 // resource identifier). 0 is invalid.
1490 uint8_t id;
1491
1492 // Must be 0.
1493 uint8_t res0;
1494 // Must be 0.
1495 uint16_t res1;
1496
1497 // Number of uint32_t entry indices that follow.
1498 uint32_t entryCount;
1499
1500 // Offset from header where ResTable_entry data starts.
1501 uint32_t entriesStart;
1502
1503 // Configuration this collection of entries is designed for.
1504 ResTable_config config;
1505};
1506
1507/**
1508 * This is the beginning of information about an entry in the resource
1509 * table. It holds the reference to the name of this entry, and is
1510 * immediately followed by one of:
Dianne Hackbornde7faf62009-06-30 13:27:30 -07001511 * * A Res_value structure, if FLAG_COMPLEX is -not- set.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 * * An array of ResTable_map structures, if FLAG_COMPLEX is set.
1513 * These supply a set of name/value mappings of data.
1514 */
1515struct ResTable_entry
1516{
1517 // Number of bytes in this structure.
1518 uint16_t size;
1519
1520 enum {
1521 // If set, this is a complex entry, holding a set of name/value
1522 // mappings. It is followed by an array of ResTable_map structures.
1523 FLAG_COMPLEX = 0x0001,
1524 // If set, this resource has been declared public, so libraries
1525 // are allowed to reference it.
1526 FLAG_PUBLIC = 0x0002
1527 };
1528 uint16_t flags;
1529
1530 // Reference into ResTable_package::keyStrings identifying this entry.
1531 struct ResStringPool_ref key;
1532};
1533
1534/**
1535 * Extended form of a ResTable_entry for map entries, defining a parent map
1536 * resource from which to inherit values.
1537 */
1538struct ResTable_map_entry : public ResTable_entry
1539{
1540 // Resource identifier of the parent mapping, or 0 if there is none.
1541 ResTable_ref parent;
1542 // Number of name/value pairs that follow for FLAG_COMPLEX.
1543 uint32_t count;
1544};
1545
1546/**
1547 * A single name/value mapping that is part of a complex resource
1548 * entry.
1549 */
1550struct ResTable_map
1551{
1552 // The resource identifier defining this mapping's name. For attribute
1553 // resources, 'name' can be one of the following special resource types
1554 // to supply meta-data about the attribute; for all other resource types
1555 // it must be an attribute resource.
1556 ResTable_ref name;
1557
1558 // Special values for 'name' when defining attribute resources.
1559 enum {
1560 // This entry holds the attribute's type code.
1561 ATTR_TYPE = Res_MAKEINTERNAL(0),
1562
1563 // For integral attributes, this is the minimum value it can hold.
1564 ATTR_MIN = Res_MAKEINTERNAL(1),
1565
1566 // For integral attributes, this is the maximum value it can hold.
1567 ATTR_MAX = Res_MAKEINTERNAL(2),
1568
1569 // Localization of this resource is can be encouraged or required with
1570 // an aapt flag if this is set
1571 ATTR_L10N = Res_MAKEINTERNAL(3),
1572
1573 // for plural support, see android.content.res.PluralRules#attrForQuantity(int)
1574 ATTR_OTHER = Res_MAKEINTERNAL(4),
1575 ATTR_ZERO = Res_MAKEINTERNAL(5),
1576 ATTR_ONE = Res_MAKEINTERNAL(6),
1577 ATTR_TWO = Res_MAKEINTERNAL(7),
1578 ATTR_FEW = Res_MAKEINTERNAL(8),
1579 ATTR_MANY = Res_MAKEINTERNAL(9)
1580
1581 };
1582
1583 // Bit mask of allowed types, for use with ATTR_TYPE.
1584 enum {
1585 // No type has been defined for this attribute, use generic
1586 // type handling. The low 16 bits are for types that can be
1587 // handled generically; the upper 16 require additional information
1588 // in the bag so can not be handled generically for TYPE_ANY.
1589 TYPE_ANY = 0x0000FFFF,
1590
1591 // Attribute holds a references to another resource.
1592 TYPE_REFERENCE = 1<<0,
1593
1594 // Attribute holds a generic string.
1595 TYPE_STRING = 1<<1,
1596
1597 // Attribute holds an integer value. ATTR_MIN and ATTR_MIN can
1598 // optionally specify a constrained range of possible integer values.
1599 TYPE_INTEGER = 1<<2,
1600
1601 // Attribute holds a boolean integer.
1602 TYPE_BOOLEAN = 1<<3,
1603
1604 // Attribute holds a color value.
1605 TYPE_COLOR = 1<<4,
1606
1607 // Attribute holds a floating point value.
1608 TYPE_FLOAT = 1<<5,
1609
1610 // Attribute holds a dimension value, such as "20px".
1611 TYPE_DIMENSION = 1<<6,
1612
1613 // Attribute holds a fraction value, such as "20%".
1614 TYPE_FRACTION = 1<<7,
1615
1616 // Attribute holds an enumeration. The enumeration values are
1617 // supplied as additional entries in the map.
1618 TYPE_ENUM = 1<<16,
1619
1620 // Attribute holds a bitmaks of flags. The flag bit values are
1621 // supplied as additional entries in the map.
1622 TYPE_FLAGS = 1<<17
1623 };
1624
1625 // Enum of localization modes, for use with ATTR_L10N.
1626 enum {
1627 L10N_NOT_REQUIRED = 0,
1628 L10N_SUGGESTED = 1
1629 };
1630
1631 // This mapping's value.
1632 Res_value value;
1633};
1634
1635/**
1636 * Convenience class for accessing data in a ResTable resource.
1637 */
1638class ResTable
1639{
1640public:
1641 ResTable();
1642 ResTable(const void* data, size_t size, void* cookie,
1643 bool copyData=false);
1644 ~ResTable();
1645
1646 status_t add(const void* data, size_t size, void* cookie,
1647 bool copyData=false);
1648 status_t add(Asset* asset, void* cookie,
1649 bool copyData=false);
Dianne Hackborn78c40512009-07-06 11:07:40 -07001650 status_t add(ResTable* src);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651
1652 status_t getError() const;
1653
1654 void uninit();
1655
1656 struct resource_name
1657 {
1658 const char16_t* package;
1659 size_t packageLen;
1660 const char16_t* type;
1661 size_t typeLen;
1662 const char16_t* name;
1663 size_t nameLen;
1664 };
1665
1666 bool getResourceName(uint32_t resID, resource_name* outName) const;
1667
1668 /**
1669 * Retrieve the value of a resource. If the resource is found, returns a
1670 * value >= 0 indicating the table it is in (for use with
1671 * getTableStringBlock() and getTableCookie()) and fills in 'outValue'. If
1672 * not found, returns a negative error code.
1673 *
1674 * Note that this function does not do reference traversal. If you want
1675 * to follow references to other resources to get the "real" value to
1676 * use, you need to call resolveReference() after this function.
1677 *
1678 * @param resID The desired resoruce identifier.
1679 * @param outValue Filled in with the resource data that was found.
1680 *
1681 * @return ssize_t Either a >= 0 table index or a negative error code.
1682 */
1683 ssize_t getResource(uint32_t resID, Res_value* outValue, bool mayBeBag=false,
1684 uint32_t* outSpecFlags=NULL, ResTable_config* outConfig=NULL) const;
1685
1686 inline ssize_t getResource(const ResTable_ref& res, Res_value* outValue,
1687 uint32_t* outSpecFlags=NULL) const {
1688 return getResource(res.ident, outValue, false, outSpecFlags, NULL);
1689 }
1690
1691 ssize_t resolveReference(Res_value* inOutValue,
1692 ssize_t blockIndex,
1693 uint32_t* outLastRef = NULL,
Dianne Hackborn0d221012009-07-29 15:41:19 -07001694 uint32_t* inoutTypeSpecFlags = NULL,
1695 ResTable_config* outConfig = NULL) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001696
1697 enum {
1698 TMP_BUFFER_SIZE = 16
1699 };
1700 const char16_t* valueToString(const Res_value* value, size_t stringBlock,
1701 char16_t tmpBuffer[TMP_BUFFER_SIZE],
1702 size_t* outLen);
1703
1704 struct bag_entry {
1705 ssize_t stringBlock;
1706 ResTable_map map;
1707 };
1708
1709 /**
1710 * Retrieve the bag of a resource. If the resoruce is found, returns the
1711 * number of bags it contains and 'outBag' points to an array of their
1712 * values. If not found, a negative error code is returned.
1713 *
1714 * Note that this function -does- do reference traversal of the bag data.
1715 *
1716 * @param resID The desired resource identifier.
1717 * @param outBag Filled inm with a pointer to the bag mappings.
1718 *
1719 * @return ssize_t Either a >= 0 bag count of negative error code.
1720 */
1721 ssize_t lockBag(uint32_t resID, const bag_entry** outBag) const;
1722
1723 void unlockBag(const bag_entry* bag) const;
1724
1725 void lock() const;
1726
1727 ssize_t getBagLocked(uint32_t resID, const bag_entry** outBag,
1728 uint32_t* outTypeSpecFlags=NULL) const;
1729
1730 void unlock() const;
1731
1732 class Theme {
1733 public:
1734 Theme(const ResTable& table);
1735 ~Theme();
1736
1737 inline const ResTable& getResTable() const { return mTable; }
1738
1739 status_t applyStyle(uint32_t resID, bool force=false);
1740 status_t setTo(const Theme& other);
1741
1742 /**
1743 * Retrieve a value in the theme. If the theme defines this
1744 * value, returns a value >= 0 indicating the table it is in
1745 * (for use with getTableStringBlock() and getTableCookie) and
1746 * fills in 'outValue'. If not found, returns a negative error
1747 * code.
1748 *
1749 * Note that this function does not do reference traversal. If you want
1750 * to follow references to other resources to get the "real" value to
1751 * use, you need to call resolveReference() after this function.
1752 *
1753 * @param resID A resource identifier naming the desired theme
1754 * attribute.
1755 * @param outValue Filled in with the theme value that was
1756 * found.
1757 *
1758 * @return ssize_t Either a >= 0 table index or a negative error code.
1759 */
1760 ssize_t getAttribute(uint32_t resID, Res_value* outValue,
1761 uint32_t* outTypeSpecFlags = NULL) const;
1762
1763 /**
1764 * This is like ResTable::resolveReference(), but also takes
1765 * care of resolving attribute references to the theme.
1766 */
1767 ssize_t resolveAttributeReference(Res_value* inOutValue,
1768 ssize_t blockIndex, uint32_t* outLastRef = NULL,
Dianne Hackborn0d221012009-07-29 15:41:19 -07001769 uint32_t* inoutTypeSpecFlags = NULL,
1770 ResTable_config* inoutConfig = NULL) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771
1772 void dumpToLog() const;
1773
1774 private:
1775 Theme(const Theme&);
1776 Theme& operator=(const Theme&);
1777
1778 struct theme_entry {
1779 ssize_t stringBlock;
1780 uint32_t typeSpecFlags;
1781 Res_value value;
1782 };
1783 struct type_info {
1784 size_t numEntries;
1785 theme_entry* entries;
1786 };
1787 struct package_info {
1788 size_t numTypes;
1789 type_info types[];
1790 };
1791
1792 void free_package(package_info* pi);
1793 package_info* copy_package(package_info* pi);
1794
1795 const ResTable& mTable;
1796 package_info* mPackages[Res_MAXPACKAGE];
1797 };
1798
1799 void setParameters(const ResTable_config* params);
1800 void getParameters(ResTable_config* params) const;
1801
1802 // Retrieve an identifier (which can be passed to getResource)
1803 // for a given resource name. The 'name' can be fully qualified
1804 // (<package>:<type>.<basename>) or the package or type components
1805 // can be dropped if default values are supplied here.
1806 //
1807 // Returns 0 if no such resource was found, else a valid resource ID.
1808 uint32_t identifierForName(const char16_t* name, size_t nameLen,
1809 const char16_t* type = 0, size_t typeLen = 0,
1810 const char16_t* defPackage = 0,
1811 size_t defPackageLen = 0,
1812 uint32_t* outTypeSpecFlags = NULL) const;
1813
1814 static bool expandResourceRef(const uint16_t* refStr, size_t refLen,
1815 String16* outPackage,
1816 String16* outType,
1817 String16* outName,
1818 const String16* defType = NULL,
1819 const String16* defPackage = NULL,
1820 const char** outErrorMsg = NULL);
1821
1822 static bool stringToInt(const char16_t* s, size_t len, Res_value* outValue);
1823 static bool stringToFloat(const char16_t* s, size_t len, Res_value* outValue);
1824
1825 // Used with stringToValue.
1826 class Accessor
1827 {
1828 public:
1829 inline virtual ~Accessor() { }
1830
1831 virtual uint32_t getCustomResource(const String16& package,
1832 const String16& type,
1833 const String16& name) const = 0;
1834 virtual uint32_t getCustomResourceWithCreation(const String16& package,
1835 const String16& type,
1836 const String16& name,
1837 const bool createIfNeeded = false) = 0;
1838 virtual uint32_t getRemappedPackage(uint32_t origPackage) const = 0;
1839 virtual bool getAttributeType(uint32_t attrID, uint32_t* outType) = 0;
1840 virtual bool getAttributeMin(uint32_t attrID, uint32_t* outMin) = 0;
1841 virtual bool getAttributeMax(uint32_t attrID, uint32_t* outMax) = 0;
1842 virtual bool getAttributeEnum(uint32_t attrID,
1843 const char16_t* name, size_t nameLen,
1844 Res_value* outValue) = 0;
1845 virtual bool getAttributeFlags(uint32_t attrID,
1846 const char16_t* name, size_t nameLen,
1847 Res_value* outValue) = 0;
1848 virtual uint32_t getAttributeL10N(uint32_t attrID) = 0;
1849 virtual bool getLocalizationSetting() = 0;
1850 virtual void reportError(void* accessorCookie, const char* fmt, ...) = 0;
1851 };
1852
1853 // Convert a string to a resource value. Handles standard "@res",
1854 // "#color", "123", and "0x1bd" types; performs escaping of strings.
1855 // The resulting value is placed in 'outValue'; if it is a string type,
1856 // 'outString' receives the string. If 'attrID' is supplied, the value is
1857 // type checked against this attribute and it is used to perform enum
1858 // evaluation. If 'acccessor' is supplied, it will be used to attempt to
1859 // resolve resources that do not exist in this ResTable. If 'attrType' is
1860 // supplied, the value will be type checked for this format if 'attrID'
1861 // is not supplied or found.
1862 bool stringToValue(Res_value* outValue, String16* outString,
1863 const char16_t* s, size_t len,
1864 bool preserveSpaces, bool coerceType,
1865 uint32_t attrID = 0,
1866 const String16* defType = NULL,
1867 const String16* defPackage = NULL,
1868 Accessor* accessor = NULL,
1869 void* accessorCookie = NULL,
1870 uint32_t attrType = ResTable_map::TYPE_ANY,
1871 bool enforcePrivate = true) const;
1872
1873 // Perform processing of escapes and quotes in a string.
1874 static bool collectString(String16* outString,
1875 const char16_t* s, size_t len,
1876 bool preserveSpaces,
1877 const char** outErrorMsg = NULL,
1878 bool append = false);
1879
1880 size_t getBasePackageCount() const;
1881 const char16_t* getBasePackageName(size_t idx) const;
1882 uint32_t getBasePackageId(size_t idx) const;
1883
1884 size_t getTableCount() const;
1885 const ResStringPool* getTableStringBlock(size_t index) const;
1886 void* getTableCookie(size_t index) const;
1887
1888 // Return the configurations (ResTable_config) that we know about
1889 void getConfigurations(Vector<ResTable_config>* configs) const;
1890
1891 void getLocales(Vector<String8>* locales) const;
1892
1893#ifndef HAVE_ANDROID_OS
Dianne Hackborne17086b2009-06-19 15:13:28 -07001894 void print(bool inclValues) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895#endif
1896
1897private:
1898 struct Header;
1899 struct Type;
1900 struct Package;
1901 struct PackageGroup;
1902 struct bag_set;
1903
1904 status_t add(const void* data, size_t size, void* cookie,
1905 Asset* asset, bool copyData);
1906
1907 ssize_t getResourcePackageIndex(uint32_t resID) const;
1908 ssize_t getEntry(
1909 const Package* package, int typeIndex, int entryIndex,
1910 const ResTable_config* config,
1911 const ResTable_type** outType, const ResTable_entry** outEntry,
1912 const Type** outTypeClass) const;
1913 status_t parsePackage(
1914 const ResTable_package* const pkg, const Header* const header);
1915
Dianne Hackbornde7faf62009-06-30 13:27:30 -07001916 void print_value(const Package* pkg, const Res_value& value) const;
1917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 mutable Mutex mLock;
1919
1920 status_t mError;
1921
1922 ResTable_config mParams;
1923
1924 // Array of all resource tables.
1925 Vector<Header*> mHeaders;
1926
1927 // Array of packages in all resource tables.
1928 Vector<PackageGroup*> mPackageGroups;
1929
1930 // Mapping from resource package IDs to indices into the internal
1931 // package array.
1932 uint8_t mPackageMap[256];
1933};
1934
1935} // namespace android
1936
1937#endif // _LIBS_UTILS_RESOURCE_TYPES_H