/** * A specification of the resources defined by a particular type. * * There should be one of these chunks for each resource type. * * This structure is followed by an array of integers providing the set of * configuration change flags (ResTable_config::CONFIG_*) that have multiple * resources for that configuration. In addition, the high bit is set if that * resource has been made public. */ struct ResTable_typeSpec { struct ResChunk_header header;
// The type identifier this chunk is holding. Type IDs start // at 1 (corresponding to the value of the type bits in a // resource identifier). 0 is invalid. uint8_t id;
// Must be 0. uint8_t res0; // Must be 0. uint16_t res1;
// Number of uint32_t entry configuration masks that follow. uint32_t entryCount;
enum { // Additional flag indicating an entry is public. SPEC_PUBLIC = 0x40000000 }; };
/** * A collection of resource entries for a particular resource data * type. Followed by an array of uint32_t defining the resource * values, corresponding to the array of type strings in the * ResTable_package::typeStrings string block. Each of these hold an * index from entriesStart; a value of NO_ENTRY means that entry is * not defined. * * There may be multiple of these chunks for a particular resource type, * supply different configuration variations for the resource values of * that type. * * It would be nice to have an additional ordered index of entries, so * we can do a binary search if trying to find a resource by string name. */ struct ResTable_type { struct ResChunk_header header;
enum { NO_ENTRY = 0xFFFFFFFF };
// The type identifier this chunk is holding. Type IDs start // at 1 (corresponding to the value of the type bits in a // resource identifier). 0 is invalid. uint8_t id;
// Must be 0. uint8_t res0; // Must be 0. uint16_t res1;
// Number of uint32_t entry indices that follow. uint32_t entryCount;
// Offset from header where ResTable_entry data starts. uint32_t entriesStart;
/** * This is the beginning of information about an entry in the resource * table. It holds the reference to the name of this entry, and is * immediately followed by one of: * * A Res_value structure, if FLAG_COMPLEX is -not- set. * * An array of ResTable_map structures, if FLAG_COMPLEX is set. * These supply a set of name/value mappings of data. */ struct ResTable_entry { // Number of bytes in this structure. uint16_t size;
enum { // If set, this is a complex entry, holding a set of name/value // mappings. It is followed by an array of ResTable_map structures. FLAG_COMPLEX = 0x0001, // If set, this resource has been declared public, so libraries // are allowed to reference it. FLAG_PUBLIC = 0x0002, // If set, this is a weak resource and may be overriden by strong // resources of the same name/type. This is only useful during // linking with other resource tables. FLAG_WEAK = 0x0004 }; uint16_t flags;
// Reference into ResTable_package::keyStrings identifying this entry. struct ResStringPool_ref key; };
/** * Extended form of a ResTable_entry for map entries, defining a parent map * resource from which to inherit values. */ struct ResTable_map_entry : public ResTable_entry { // Resource identifier of the parent mapping, or 0 if there is none. ResTable_ref parent; // Number of name/value pairs that follow for FLAG_COMPLEX. uint32_t count; };
/** * Representation of a value in a resource, supplying type * information. */ struct Res_value { // Number of bytes in this structure. uint16_t size;
// Always set to 0. uint8_t res0;
// Type of the data value. enum { // The 'data' is either 0 or 1, specifying this resource is either // undefined or empty, respectively. TYPE_NULL = 0x00, // The 'data' holds a ResTable_ref, a reference to another resource // table entry. TYPE_REFERENCE = 0x01, // The 'data' holds an attribute resource identifier. TYPE_ATTRIBUTE = 0x02, // The 'data' holds an index into the containing resource table's // global value string pool. TYPE_STRING = 0x03, // The 'data' holds a single-precision floating point number. TYPE_FLOAT = 0x04, // The 'data' holds a complex number encoding a dimension value, // such as "100in". TYPE_DIMENSION = 0x05, // The 'data' holds a complex number encoding a fraction of a // container. TYPE_FRACTION = 0x06, // The 'data' holds a dynamic ResTable_ref, which needs to be // resolved before it can be used like a TYPE_REFERENCE. TYPE_DYNAMIC_REFERENCE = 0x07, // The 'data' holds an attribute resource identifier, which needs to be resolved // before it can be used like a TYPE_ATTRIBUTE. TYPE_DYNAMIC_ATTRIBUTE = 0x08, // Beginning of integer flavors... TYPE_FIRST_INT = 0x10,
// The 'data' is a raw integer value of the form n..n. TYPE_INT_DEC = 0x10, // The 'data' is a raw integer value of the form 0xn..n. TYPE_INT_HEX = 0x11, // The 'data' is either 0 or 1, for input "false" or "true" respectively. TYPE_INT_BOOLEAN = 0x12,
// Beginning of color integer flavors... TYPE_FIRST_COLOR_INT = 0x1c,
// The 'data' is a raw integer value of the form #aarrggbb. TYPE_INT_COLOR_ARGB8 = 0x1c, // The 'data' is a raw integer value of the form #rrggbb. TYPE_INT_COLOR_RGB8 = 0x1d, // The 'data' is a raw integer value of the form #argb. TYPE_INT_COLOR_ARGB4 = 0x1e, // The 'data' is a raw integer value of the form #rgb. TYPE_INT_COLOR_RGB4 = 0x1f,
// ...end of integer flavors. TYPE_LAST_COLOR_INT = 0x1f,
// ...end of integer flavors. TYPE_LAST_INT = 0x1f }; uint8_t dataType; // Structure of complex data values (TYPE_UNIT and TYPE_FRACTION) enum { // Where the unit type information is. This gives us 16 possible // types, as defined below. COMPLEX_UNIT_SHIFT = 0, COMPLEX_UNIT_MASK = 0xf,
// TYPE_DIMENSION: Value is raw pixels. COMPLEX_UNIT_PX = 0, // TYPE_DIMENSION: Value is Device Independent Pixels. COMPLEX_UNIT_DIP = 1, // TYPE_DIMENSION: Value is a Scaled device independent Pixels. COMPLEX_UNIT_SP = 2, // TYPE_DIMENSION: Value is in points. COMPLEX_UNIT_PT = 3, // TYPE_DIMENSION: Value is in inches. COMPLEX_UNIT_IN = 4, // TYPE_DIMENSION: Value is in millimeters. COMPLEX_UNIT_MM = 5,
// TYPE_FRACTION: A basic fraction of the overall size. COMPLEX_UNIT_FRACTION = 0, // TYPE_FRACTION: A fraction of the parent size. COMPLEX_UNIT_FRACTION_PARENT = 1,
// Where the radix information is, telling where the decimal place // appears in the mantissa. This give us 4 possible fixed point // representations as defined below. COMPLEX_RADIX_SHIFT = 4, COMPLEX_RADIX_MASK = 0x3,
// The mantissa is an integral number -- i.e., 0xnnnnnn.0 COMPLEX_RADIX_23p0 = 0, // The mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn COMPLEX_RADIX_16p7 = 1, // The mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn COMPLEX_RADIX_8p15 = 2, // The mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn COMPLEX_RADIX_0p23 = 3, // Where the actual value is. This gives us 23 bits of // precision. The top bit is the sign. COMPLEX_MANTISSA_SHIFT = 8, COMPLEX_MANTISSA_MASK = 0xffffff };
// Possible data values for TYPE_NULL. enum { // The value is not defined. DATA_NULL_UNDEFINED = 0, // The value is explicitly defined as empty. DATA_NULL_EMPTY = 1 };
// The data for this item, as interpreted according to dataType. typedef uint32_t data_type; data_type data; };
/** * Extended form of a ResTable_entry for map entries, defining a parent map * resource from which to inherit values. */ struct ResTable_map_entry : public ResTable_entry { // Resource identifier of the parent mapping, or 0 if there is none. ResTable_ref parent; // Number of name/value pairs that follow for FLAG_COMPLEX. uint32_t count; };
/** * This is a reference to a unique entry (a ResTable_entry structure) * in a resource table. The value is structured as: 0xpptteeee, * where pp is the package index, tt is the type index in that * package, and eeee is the entry index in that type. The package * and type values start at 1 for the first item, to help catch cases * where they have not been supplied. */ struct ResTable_ref { uint32_t ident; };
这个ident代表的就是资源的id。这个值其实我们在java里面也能看到:
1 2 3 4 5 6 7 8 9
public final class R { ... public static final class bool { public static final int abc_action_bar_embed_tabs=0x7f030000; public static final int abc_allow_stacked_button_bar=0x7f030001; public static final int abc_config_actionMenuItemAllCaps=0x7f030002; } ... }
/** * A single name/value mapping that is part of a complex resource * entry. */ struct ResTable_map { // The resource identifier defining this mapping's name. For attribute // resources, 'name' can be one of the following special resource types // to supply meta-data about the attribute; for all other resource types // it must be an attribute resource. ResTable_ref name;
// Special values for 'name' when defining attribute resources. enum { // This entry holds the attribute's type code. ATTR_TYPE = Res_MAKEINTERNAL(0),
// For integral attributes, this is the minimum value it can hold. ATTR_MIN = Res_MAKEINTERNAL(1),
// For integral attributes, this is the maximum value it can hold. ATTR_MAX = Res_MAKEINTERNAL(2),
// Localization of this resource is can be encouraged or required with // an aapt flag if this is set ATTR_L10N = Res_MAKEINTERNAL(3),
}; // Bit mask of allowed types, for use with ATTR_TYPE. enum { // No type has been defined for this attribute, use generic // type handling. The low 16 bits are for types that can be // handled generically; the upper 16 require additional information // in the bag so can not be handled generically for TYPE_ANY. TYPE_ANY = 0x0000FFFF,
// Attribute holds a references to another resource. TYPE_REFERENCE = 1<<0,
// Attribute holds a generic string. TYPE_STRING = 1<<1,
// Attribute holds an integer value. ATTR_MIN and ATTR_MIN can // optionally specify a constrained range of possible integer values. TYPE_INTEGER = 1<<2,
// Attribute holds a boolean integer. TYPE_BOOLEAN = 1<<3,
// Attribute holds a color value. TYPE_COLOR = 1<<4,
// Attribute holds a floating point value. TYPE_FLOAT = 1<<5,
// Attribute holds a dimension value, such as "20px". TYPE_DIMENSION = 1<<6,
// Attribute holds a fraction value, such as "20%". TYPE_FRACTION = 1<<7,
// Attribute holds an enumeration. The enumeration values are // supplied as additional entries in the map. TYPE_ENUM = 1<<16,
// Attribute holds a bitmaks of flags. The flag bit values are // supplied as additional entries in the map. TYPE_FLAGS = 1<<17 };
// Enum of localization modes, for use with ATTR_L10N. enum { L10N_NOT_REQUIRED = 0, L10N_SUGGESTED = 1 };
enum { // No type has been defined for this attribute, use generic // type handling. The low 16 bits are for types that can be // handled generically; the upper 16 require additional information // in the bag so can not be handled generically for TYPE_ANY. TYPE_ANY = 0x0000FFFF,
// Attribute holds a references to another resource. TYPE_REFERENCE = 1<<0,
// Attribute holds a generic string. TYPE_STRING = 1<<1,
// Attribute holds an integer value. ATTR_MIN and ATTR_MIN can // optionally specify a constrained range of possible integer values. TYPE_INTEGER = 1<<2,
// Attribute holds a boolean integer. TYPE_BOOLEAN = 1<<3,
// Attribute holds a color value. TYPE_COLOR = 1<<4,
// Attribute holds a floating point value. TYPE_FLOAT = 1<<5,
// Attribute holds a dimension value, such as "20px". TYPE_DIMENSION = 1<<6,
// Attribute holds a fraction value, such as "20%". TYPE_FRACTION = 1<<7,
// Attribute holds an enumeration. The enumeration values are // supplied as additional entries in the map. TYPE_ENUM = 1<<16,
// Attribute holds a bitmaks of flags. The flag bit values are // supplied as additional entries in the map. TYPE_FLAGS = 1<<17 };