ResourceTypeExtensions.h revision 1ab598f46c3ff520a67f9d80194847741f3467ab
1/* 2 * Copyright (C) 2015 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#ifndef AAPT_RESOURCE_TYPE_EXTENSIONS_H 18#define AAPT_RESOURCE_TYPE_EXTENSIONS_H 19 20#include <androidfw/ResourceTypes.h> 21 22namespace aapt { 23 24/** 25 * New android::ResChunk_header types defined 26 * for AAPT to use. 27 * 28 * TODO(adamlesinski): Consider reserving these 29 * enums in androidfw/ResourceTypes.h to avoid 30 * future collisions. 31 */ 32enum { 33 /** 34 * A chunk that contains an entire file that 35 * has been compiled. 36 */ 37 RES_FILE_EXPORT_TYPE = 0x000c, 38 39 RES_TABLE_PUBLIC_TYPE = 0x000d, 40 41 /** 42 * A chunk that holds the string pool 43 * for source entries (path/to/source:line). 44 */ 45 RES_TABLE_SOURCE_POOL_TYPE = 0x000e, 46 47 /** 48 * A chunk holding names of externally 49 * defined symbols and offsets to where 50 * they are referenced in the table. 51 */ 52 RES_TABLE_SYMBOL_TABLE_TYPE = 0x000f, 53}; 54 55/** 56 * New resource types that are meant to only be used 57 * by AAPT and will not end up on the device. 58 */ 59struct ExtendedTypes { 60 enum { 61 /** 62 * A raw string value that hasn't had its escape sequences 63 * processed nor whitespace removed. 64 */ 65 TYPE_RAW_STRING = 0xfe 66 }; 67}; 68 69/** 70 * Followed by exportedSymbolCount ExportedSymbol structs, followed by the string pool. 71 */ 72struct FileExport_header { 73 android::ResChunk_header header; 74 75 /** 76 * MAGIC value. Must be 'AAPT' (0x41415054) 77 */ 78 uint8_t magic[4]; 79 80 /** 81 * Version of AAPT that built this file. 82 */ 83 uint32_t version; 84 85 /** 86 * The resource name. 87 */ 88 android::ResStringPool_ref name; 89 90 /** 91 * Configuration of this file. 92 */ 93 android::ResTable_config config; 94 95 /** 96 * Original source path of this file. 97 */ 98 android::ResStringPool_ref source; 99 100 /** 101 * Number of symbols exported by this file. 102 */ 103 uint32_t exportedSymbolCount; 104}; 105 106struct ExportedSymbol { 107 android::ResStringPool_ref name; 108 uint32_t line; 109}; 110 111struct Public_header { 112 android::ResChunk_header header; 113 114 /** 115 * The ID of the type this structure refers to. 116 */ 117 uint8_t typeId; 118 119 /** 120 * Reserved. Must be 0. 121 */ 122 uint8_t res0; 123 124 /** 125 * Reserved. Must be 0. 126 */ 127 uint16_t res1; 128 129 /** 130 * Number of public entries. 131 */ 132 uint32_t count; 133}; 134 135struct Public_entry { 136 uint16_t entryId; 137 uint16_t res0; 138 android::ResStringPool_ref key; 139 android::ResStringPool_ref source; 140 uint32_t sourceLine; 141}; 142 143/** 144 * A chunk with type RES_TABLE_SYMBOL_TABLE_TYPE. 145 * Following the header are count number of SymbolTable_entry 146 * structures, followed by an android::ResStringPool_header. 147 */ 148struct SymbolTable_header { 149 android::ResChunk_header header; 150 151 /** 152 * Number of SymbolTable_entry structures following 153 * this header. 154 */ 155 uint32_t count; 156}; 157 158struct SymbolTable_entry { 159 /** 160 * Offset from the beginning of the resource table 161 * where the symbol entry is referenced. 162 */ 163 uint32_t offset; 164 165 /** 166 * The index into the string pool where the name of this 167 * symbol exists. 168 */ 169 uint32_t stringIndex; 170}; 171 172/** 173 * A structure representing the source of a resourc entry. 174 * Appears after an android::ResTable_entry or android::ResTable_map_entry. 175 * 176 * TODO(adamlesinski): This causes some issues when runtime code checks 177 * the size of an android::ResTable_entry. It assumes it is an 178 * android::ResTable_map_entry if the size is bigger than an android::ResTable_entry 179 * which may not be true if this structure is present. 180 */ 181struct ResTable_entry_source { 182 /** 183 * Index into the source string pool. 184 */ 185 uint32_t pathIndex; 186 187 /** 188 * Line number this resource was defined on. 189 */ 190 uint32_t line; 191}; 192 193/** 194 * An alternative struct to use instead of ResTable_map_entry. This one is a standard_layout 195 * struct. 196 */ 197struct ResTable_entry_ext { 198 android::ResTable_entry entry; 199 android::ResTable_ref parent; 200 uint32_t count; 201}; 202 203} // namespace aapt 204 205#endif // AAPT_RESOURCE_TYPE_EXTENSIONS_H 206