ResourceTypeExtensions.h revision 28cacf091ad2b1c2749e77f590e9523e58735252
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 * New types for a ResTable_map.
71 */
72struct ExtendedResTableMapTypes {
73    enum {
74        /**
75         * Type that contains the source path of the next item in the map.
76         */
77        ATTR_SOURCE_PATH = Res_MAKEINTERNAL(0xffff),
78
79        /**
80         * Type that contains the source line of the next item in the map.
81         */
82        ATTR_SOURCE_LINE = Res_MAKEINTERNAL(0xfffe),
83
84        /**
85         * Type that contains the comment of the next item in the map.
86         */
87        ATTR_COMMENT = Res_MAKEINTERNAL(0xfffd)
88    };
89};
90
91/**
92 * Followed by exportedSymbolCount ExportedSymbol structs, followed by the string pool.
93 */
94struct FileExport_header {
95    android::ResChunk_header header;
96
97    /**
98     * MAGIC value. Must be 'AAPT' (0x41415054)
99     */
100    uint8_t magic[4];
101
102    /**
103     * Version of AAPT that built this file.
104     */
105    uint32_t version;
106
107    /**
108     * The resource name.
109     */
110    android::ResStringPool_ref name;
111
112    /**
113     * Configuration of this file.
114     */
115    android::ResTable_config config;
116
117    /**
118     * Original source path of this file.
119     */
120    android::ResStringPool_ref source;
121
122    /**
123     * Number of symbols exported by this file.
124     */
125    uint32_t exportedSymbolCount;
126};
127
128struct ExportedSymbol {
129    android::ResStringPool_ref name;
130    uint32_t line;
131};
132
133struct Public_header {
134    android::ResChunk_header header;
135
136    /**
137     * The ID of the type this structure refers to.
138     */
139    uint8_t typeId;
140
141    /**
142     * Reserved. Must be 0.
143     */
144    uint8_t res0;
145
146    /**
147     * Reserved. Must be 0.
148     */
149    uint16_t res1;
150
151    /**
152     * Number of public entries.
153     */
154    uint32_t count;
155};
156
157/**
158 * A structure representing source data for a resource entry.
159 * Appears after an android::ResTable_entry or android::ResTable_map_entry.
160 *
161 * TODO(adamlesinski): This causes some issues when runtime code checks
162 * the size of an android::ResTable_entry. It assumes it is an
163 * android::ResTable_map_entry if the size is bigger than an android::ResTable_entry
164 * which may not be true if this structure is present.
165 */
166struct ResTable_entry_source {
167    /**
168     * File path reference.
169     */
170    android::ResStringPool_ref path;
171
172    /**
173     * Line number this resource was defined on.
174     */
175    uint32_t line;
176
177    /**
178     * Comment string reference.
179     */
180    android::ResStringPool_ref comment;
181};
182
183struct Public_entry {
184    uint16_t entryId;
185
186    enum : uint16_t {
187        kUndefined = 0,
188        kPublic = 1,
189        kPrivate = 2,
190    };
191
192    uint16_t state;
193    android::ResStringPool_ref key;
194    ResTable_entry_source source;
195};
196
197/**
198 * A chunk with type RES_TABLE_SYMBOL_TABLE_TYPE.
199 * Following the header are count number of SymbolTable_entry
200 * structures, followed by an android::ResStringPool_header.
201 */
202struct SymbolTable_header {
203    android::ResChunk_header header;
204
205    /**
206     * Number of SymbolTable_entry structures following
207     * this header.
208     */
209    uint32_t count;
210};
211
212struct SymbolTable_entry {
213    /**
214     * Offset from the beginning of the resource table
215     * where the symbol entry is referenced.
216     */
217    uint32_t offset;
218
219    /**
220     * The index into the string pool where the name of this
221     * symbol exists.
222     */
223    android::ResStringPool_ref name;
224};
225
226/**
227 * An alternative struct to use instead of ResTable_map_entry. This one is a standard_layout
228 * struct.
229 */
230struct ResTable_entry_ext {
231    android::ResTable_entry entry;
232    android::ResTable_ref parent;
233    uint32_t count;
234};
235
236} // namespace aapt
237
238#endif // AAPT_RESOURCE_TYPE_EXTENSIONS_H
239