blob: 6be7f02dc7d26a3778a3923ccb2fb045e14de8a0 [file] [log] [blame]
Adam Lesinski59e04c62016-02-04 15:59:23 -08001/*
2 * Copyright (C) 2016 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
17syntax = "proto2";
18
19option optimize_for = LITE_RUNTIME;
20
21package aapt.pb;
22
Adam Lesinski0c808952017-07-10 05:40:39 -070023// A configuration description that wraps the binary form of the C++ class
24// aapt::ConfigDescription, with an added product definition.
Adam Lesinski59e04c62016-02-04 15:59:23 -080025message ConfigDescription {
Adam Lesinski0c808952017-07-10 05:40:39 -070026 optional bytes data = 1;
27 optional string product = 2;
Adam Lesinski59e04c62016-02-04 15:59:23 -080028}
29
Adam Lesinski0c808952017-07-10 05:40:39 -070030// A string pool that wraps the binary form of the C++ class android::ResStringPool.
Adam Lesinski59e04c62016-02-04 15:59:23 -080031message StringPool {
Adam Lesinski0c808952017-07-10 05:40:39 -070032 optional bytes data = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -080033}
34
Adam Lesinski0c808952017-07-10 05:40:39 -070035// Developer friendly source file information for an entity in the resource table.
Adam Lesinski59e04c62016-02-04 15:59:23 -080036message Source {
Adam Lesinski0c808952017-07-10 05:40:39 -070037 // The index of the string path within the source string pool of a ResourceTable.
38 optional uint32 path_idx = 1;
39
40 optional uint32 line_no = 2;
41 optional uint32 col_no = 3;
Adam Lesinski59e04c62016-02-04 15:59:23 -080042}
43
Adam Lesinski0c808952017-07-10 05:40:39 -070044// The top level message representing an external resource file (layout XML, PNG, etc).
45message CompiledFile {
46 message Symbol {
47 // The name of the symbol (in the form package:type/name).
48 optional string resource_name = 1;
49
50 // Line number in the file at which this symbol is defined. For debug use.
51 optional uint32 line_no = 2;
52 }
53
54 // The name of the resource (in the form package:type/name).
55 optional string resource_name = 1;
56
57 // The configuration for which the resource is defined.
58 optional ConfigDescription config = 2;
59
60 // The filesystem path to where the source file originated.
61 // Mainly used to display helpful error messages.
62 optional string source_path = 3;
63
64 // Any symbols this file auto-generates/exports (eg. @+id/foo in an XML file).
65 repeated Symbol exported_symbols = 4;
66}
67
68// Top level message representing a resource table.
69message ResourceTable {
Adam Lesinski0c808952017-07-10 05:40:39 -070070 // The string pool containing source paths referenced throughout the resource table. This does
71 // not end up in the final binary ARSC file.
Adam Lesinski08535002017-08-04 16:15:17 -070072 optional StringPool source_pool = 1;
Adam Lesinski0c808952017-07-10 05:40:39 -070073
74 // Resource definitions corresponding to an Android package.
Adam Lesinski08535002017-08-04 16:15:17 -070075 repeated Package packages = 2;
Adam Lesinski0c808952017-07-10 05:40:39 -070076}
77
78// Defines resources for an Android package.
79message Package {
80 // The package ID of this package, in the range [0x00, 0xff].
81 // The ID 0x00 is reserved for shared libraries, or when the ID is assigned at run-time.
82 // The ID 0x01 is reserved for the 'android' package (framework).
83 // The ID range [0x02, 0x7f) is reserved for auto-assignment to shared libraries at run-time.
84 // The ID 0x7f is reserved for the application package.
85 // IDs > 0x7f are reserved for the application as well and are treated as feature splits.
86 optional uint32 package_id = 1;
87
88 // The Java compatible Android package name of the app.
89 optional string package_name = 2;
90
91 // The series of types defined by the package.
92 repeated Type types = 3;
93}
94
95// A set of resources grouped under a common type. Such types include string, layout, xml, dimen,
96// attr, etc. This maps to the second part of a resource identifier in Java (R.type.entry).
97message Type {
98 // The ID of the type. This may be 0, which indicates no ID is set.
99 optional uint32 id = 1;
100
101 // The name of the type. This corresponds to the 'type' part of a full resource name of the form
102 // package:type/entry. The set of legal type names is listed in Resource.cpp.
103 optional string name = 2;
104
105 // The entries defined for this type.
106 repeated Entry entries = 3;
107}
108
109// The status of a symbol/entry. This contains information like visibility (public/private),
110// comments, and whether the entry can be overridden.
111message SymbolStatus {
112 // The visibility of the resource outside of its package.
113 enum Visibility {
114 // No visibility was explicitly specified. This is typically treated as private.
115 // The distinction is important when two separate R.java files are generated: a public and
116 // private one. An unknown visibility, in this case, would cause the resource to be omitted
117 // from either R.java.
118 Unknown = 0;
119
120 // A resource was explicitly marked as private. This means the resource can not be accessed
121 // outside of its package unless the @*package:type/entry notation is used (the asterisk being
122 // the private accessor). If two R.java files are generated (private + public), the resource
123 // will only be emitted to the private R.java file.
124 Private = 1;
125
126 // A resource was explicitly marked as public. This means the resource can be accessed
127 // from any package, and is emitted into all R.java files, public and private.
128 Public = 2;
129 }
130
131 optional Visibility visibility = 1;
132
133 // The path at which this entry's visibility was defined (eg. public.xml).
134 optional Source source = 2;
135
136 // The comment associated with the <public> tag.
137 optional string comment = 3;
138
139 // Whether the symbol can be merged into another resource table without there being an existing
140 // definition to override. Used for overlays and set to true when <add-resource> is specified.
141 optional bool allow_new = 4;
142}
143
144// An entry declaration. An entry has a full resource ID that is the combination of package ID,
145// type ID, and its own entry ID. An entry on its own has no value, but values are defined for
146// various configurations/variants.
147message Entry {
148 // The ID of this entry. Together with the package ID and type ID, this forms a full resource ID
149 // of the form 0xPPTTEEEE, where PP is the package ID, TT is the type ID, and EEEE is the entry
150 // ID.
151 optional uint32 id = 1;
152
153 // The name of this entry. This corresponds to the 'entry' part of a full resource name of the
154 // form package:type/entry.
155 optional string name = 2;
156
157 // The symbol status of this entry, which includes visibility information.
158 optional SymbolStatus symbol_status = 3;
159
160 // The set of values defined for this entry, each corresponding to a different
161 // configuration/variant.
162 repeated ConfigValue config_values = 4;
163}
164
165// A Configuration/Value pair.
166message ConfigValue {
167 optional ConfigDescription config = 1;
168 optional Value value = 2;
169}
170
171// The generic meta-data for every value in a resource table.
172message Value {
173 // Where the value was defined.
174 optional Source source = 1;
175
176 // Any comment associated with the value.
177 optional string comment = 2;
178
179 // Whether the value can be overridden.
180 optional bool weak = 3;
181
182 // If the value is an Item, this is set.
183 optional Item item = 4;
184
185 // If the value is a CompoundValue, this is set.
186 optional CompoundValue compound_value = 5;
187}
188
189// An Item is an abstract type. It represents a value that can appear inline in many places, such
190// as XML attribute values or on the right hand side of style attribute definitions. The concrete
191// type is one of the types below. Only one can be set.
192message Item {
193 optional Reference ref = 1;
194 optional String str = 2;
195 optional RawString raw_str = 3;
Adam Lesinski08535002017-08-04 16:15:17 -0700196 optional StyledString styled_str = 4;
197 optional FileReference file = 5;
198 optional Id id = 6;
199 optional Primitive prim = 7;
Adam Lesinski0c808952017-07-10 05:40:39 -0700200}
201
202// A CompoundValue is an abstract type. It represents a value that is a made of other values.
203// These can only usually appear as top-level resources. The concrete type is one of the types
204// below. Only one can be set.
205message CompoundValue {
206 optional Attribute attr = 1;
207 optional Style style = 2;
208 optional Styleable styleable = 3;
209 optional Array array = 4;
210 optional Plural plural = 5;
211}
212
213// A value that is a reference to another resource. This reference can be by name or resource ID.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800214message Reference {
Adam Lesinski0c808952017-07-10 05:40:39 -0700215 enum Type {
216 // A plain reference (@package:type/entry).
217 Ref = 0;
218
219 // A reference to a theme attribute (?package:type/entry).
220 Attr = 1;
221 }
222
223 optional Type type = 1;
224
225 // The resource ID (0xPPTTEEEE) of the resource being referred.
226 optional uint32 id = 2;
227
Adam Lesinski08535002017-08-04 16:15:17 -0700228 // The optional resource name.
229 optional string name = 3;
Adam Lesinski0c808952017-07-10 05:40:39 -0700230
231 // Whether this reference is referencing a private resource (@*package:type/entry).
232 optional bool private = 4;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800233}
234
Adam Lesinski0c808952017-07-10 05:40:39 -0700235// A value that represents an ID. This is just a placeholder, as ID values are used to occupy a
236// resource ID (0xPPTTEEEE) as a unique identifier. Their value is unimportant.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800237message Id {
238}
239
Adam Lesinski0c808952017-07-10 05:40:39 -0700240// A value that is a string.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800241message String {
Adam Lesinski08535002017-08-04 16:15:17 -0700242 optional string value = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800243}
244
Adam Lesinski0c808952017-07-10 05:40:39 -0700245// A value that is a raw string, which is unescaped/uninterpreted. This is typically used to
246// represent the value of a style attribute before the attribute is compiled and the set of
247// allowed values is known.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800248message RawString {
Adam Lesinski08535002017-08-04 16:15:17 -0700249 optional string value = 1;
250}
251
252// A string with styling information, like html tags that specify boldness, italics, etc.
253message StyledString {
254 // The raw text of the string.
255 optional string value = 1;
256
257 // A Span marks a region of the string text that is styled.
258 message Span {
259 // The name of the tag, and its attributes, encoded as follows:
260 // tag_name;attr1=value1;attr2=value2;[...]
261 optional string tag = 1;
262
263 // The first character position this span applies to, in UTF-16 offset.
264 optional uint32 first_char = 2;
265
266 // The last character position this span applies to, in UTF-16 offset.
267 optional uint32 last_char = 3;
268 }
269
270 repeated Span span = 2;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800271}
272
Adam Lesinski0c808952017-07-10 05:40:39 -0700273// A value that is a reference to an external entity, like an XML file or a PNG.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800274message FileReference {
Adam Lesinski08535002017-08-04 16:15:17 -0700275 // Path to a file within the APK (typically res/type-config/entry.ext).
276 optional string path = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800277}
278
Adam Lesinski0c808952017-07-10 05:40:39 -0700279// A value that represents a primitive data type (float, int, boolean, etc.).
280// Corresponds to the fields (type/data) of the C struct android::Res_value.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800281message Primitive {
Adam Lesinski0c808952017-07-10 05:40:39 -0700282 optional uint32 type = 1;
283 optional uint32 data = 2;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800284}
285
Adam Lesinski0c808952017-07-10 05:40:39 -0700286// A value that represents an XML attribute and what values it accepts.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800287message Attribute {
Adam Lesinski0c808952017-07-10 05:40:39 -0700288 // A Symbol used to represent an enum or a flag.
289 message Symbol {
290 // Where the enum/flag item was defined.
291 optional Source source = 1;
292
293 // Any comments associated with the enum or flag.
294 optional string comment = 2;
295
296 // The name of the enum/flag as a reference. Enums/flag items are generated as ID resource
297 // values.
298 optional Reference name = 3;
299
300 // The value of the enum/flag.
301 optional uint32 value = 4;
302 }
303
304 // A bitmask of types that this XML attribute accepts. Corresponds to the flags in the C struct
305 // android::ResTable_map.
306 optional uint32 format_flags = 1;
307
308 // The smallest integer allowed for this XML attribute. Only makes sense if the format includes
309 // TYPE_INTEGER.
310 optional int32 min_int = 2;
311
312 // The largest integer allowed for this XML attribute. Only makes sense if the format includes
313 // TYPE_INTEGER.
314 optional int32 max_int = 3;
315
316 // The set of enums/flags defined in this attribute. Only makes sense if the format includes
317 // either TYPE_ENUM or TYPE_FLAGS. Having both is an error.
318 repeated Symbol symbols = 4;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800319}
320
Adam Lesinski0c808952017-07-10 05:40:39 -0700321// A value that represents a style.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800322message Style {
Adam Lesinski0c808952017-07-10 05:40:39 -0700323 // An XML attribute/value pair defined in the style.
324 message Entry {
325 // Where the entry was defined.
326 optional Source source = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800327
Adam Lesinski0c808952017-07-10 05:40:39 -0700328 // Any comments associated with the entry.
329 optional string comment = 2;
330
331 // A reference to the XML attribute.
332 optional Reference key = 3;
333
334 // The Item defined for this XML attribute.
335 optional Item item = 4;
336 }
337
338 // The optinal style from which this style inherits attributes.
339 optional Reference parent = 1;
340
341 // The source file information of the parent inheritance declaration.
342 optional Source parent_source = 2;
343
344 // The set of XML attribute/value pairs for this style.
345 repeated Entry entries = 3;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800346}
347
Adam Lesinski0c808952017-07-10 05:40:39 -0700348// A value that represents a <declare-styleable> XML resource. These are not real resources and
349// only end up as Java fields in the generated R.java. They do not end up in the binary ARSC file.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800350message Styleable {
Adam Lesinski0c808952017-07-10 05:40:39 -0700351 // An attribute defined for this styleable.
352 message Entry {
353 // Where the attribute was defined within the <declare-styleable> block.
354 optional Source source = 1;
355
356 // Any comments associated with the declaration.
357 optional string comment = 2;
358
359 // The reference to the attribute.
360 optional Reference attr = 3;
361 }
362
363 // The set of attribute declarations.
364 repeated Entry entries = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800365}
366
Adam Lesinski0c808952017-07-10 05:40:39 -0700367// A value that represents an array of resource values.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800368message Array {
Adam Lesinski0c808952017-07-10 05:40:39 -0700369 // A single element of the array.
370 message Entry {
371 // Where the element was defined.
372 optional Source source = 1;
373
374 // Any comments associated with the element.
375 optional string comment = 2;
376
377 // The value assigned to this element.
378 optional Item item = 3;
379 }
380
381 // The list of array elements.
382 repeated Entry entries = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800383}
384
Adam Lesinski0c808952017-07-10 05:40:39 -0700385// A value that represents a string and its many variations based on plurality.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800386message Plural {
Adam Lesinski0c808952017-07-10 05:40:39 -0700387 // The arity of the plural.
388 enum Arity {
389 Zero = 0;
390 One = 1;
391 Two = 2;
392 Few = 3;
393 Many = 4;
394 Other = 5;
395 }
Adam Lesinski59e04c62016-02-04 15:59:23 -0800396
Adam Lesinski0c808952017-07-10 05:40:39 -0700397 // The plural value for a given arity.
398 message Entry {
399 // Where the plural was defined.
400 optional Source source = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800401
Adam Lesinski0c808952017-07-10 05:40:39 -0700402 // Any comments associated with the plural.
403 optional string comment = 2;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800404
Adam Lesinski0c808952017-07-10 05:40:39 -0700405 // The arity of the plural.
406 optional Arity arity = 3;
407
408 // The value assigned to this plural.
409 optional Item item = 4;
410 }
411
412 // The set of arity/plural mappings.
413 repeated Entry entries = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800414}