blob: 71f33b0853ad466020c97df664088f45f9abec4c [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
Adam Lesinski4ffea042017-08-10 15:37:28 -070017// Keep proto2 syntax because we require the distinction between fields that
18// are set and unset.
Adam Lesinski59e04c62016-02-04 15:59:23 -080019syntax = "proto2";
20
Adam Lesinski4ffea042017-08-10 15:37:28 -070021option java_package = "com.android.aapt";
Adam Lesinski59e04c62016-02-04 15:59:23 -080022option optimize_for = LITE_RUNTIME;
23
24package aapt.pb;
25
Adam Lesinski0c808952017-07-10 05:40:39 -070026// A configuration description that wraps the binary form of the C++ class
27// aapt::ConfigDescription, with an added product definition.
Adam Lesinski4ffea042017-08-10 15:37:28 -070028// TODO(adamlesinski): Flesh this out to be represented in proto.
Adam Lesinski59e04c62016-02-04 15:59:23 -080029message ConfigDescription {
Adam Lesinski0c808952017-07-10 05:40:39 -070030 optional bytes data = 1;
31 optional string product = 2;
Adam Lesinski59e04c62016-02-04 15:59:23 -080032}
33
Adam Lesinski0c808952017-07-10 05:40:39 -070034// A string pool that wraps the binary form of the C++ class android::ResStringPool.
Adam Lesinski59e04c62016-02-04 15:59:23 -080035message StringPool {
Adam Lesinski0c808952017-07-10 05:40:39 -070036 optional bytes data = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -080037}
38
Adam Lesinski4ffea042017-08-10 15:37:28 -070039// The position of a declared entity within a file.
40message SourcePosition {
41 optional uint32 line_number = 1;
42 optional uint32 column_number = 2;
43}
44
Adam Lesinski0c808952017-07-10 05:40:39 -070045// Developer friendly source file information for an entity in the resource table.
Adam Lesinski59e04c62016-02-04 15:59:23 -080046message Source {
Adam Lesinski0c808952017-07-10 05:40:39 -070047 // The index of the string path within the source string pool of a ResourceTable.
48 optional uint32 path_idx = 1;
Adam Lesinski4ffea042017-08-10 15:37:28 -070049 optional SourcePosition position = 2;
Adam Lesinski0c808952017-07-10 05:40:39 -070050}
51
52// Top level message representing a resource table.
53message ResourceTable {
Adam Lesinski0c808952017-07-10 05:40:39 -070054 // The string pool containing source paths referenced throughout the resource table. This does
55 // not end up in the final binary ARSC file.
Adam Lesinski08535002017-08-04 16:15:17 -070056 optional StringPool source_pool = 1;
Adam Lesinski0c808952017-07-10 05:40:39 -070057
58 // Resource definitions corresponding to an Android package.
Adam Lesinski4ffea042017-08-10 15:37:28 -070059 repeated Package package = 2;
Adam Lesinski0c808952017-07-10 05:40:39 -070060}
61
62// Defines resources for an Android package.
63message Package {
64 // The package ID of this package, in the range [0x00, 0xff].
65 // The ID 0x00 is reserved for shared libraries, or when the ID is assigned at run-time.
66 // The ID 0x01 is reserved for the 'android' package (framework).
67 // The ID range [0x02, 0x7f) is reserved for auto-assignment to shared libraries at run-time.
68 // The ID 0x7f is reserved for the application package.
69 // IDs > 0x7f are reserved for the application as well and are treated as feature splits.
70 optional uint32 package_id = 1;
71
72 // The Java compatible Android package name of the app.
73 optional string package_name = 2;
74
75 // The series of types defined by the package.
Adam Lesinski4ffea042017-08-10 15:37:28 -070076 repeated Type type = 3;
Adam Lesinski0c808952017-07-10 05:40:39 -070077}
78
79// A set of resources grouped under a common type. Such types include string, layout, xml, dimen,
80// attr, etc. This maps to the second part of a resource identifier in Java (R.type.entry).
81message Type {
82 // The ID of the type. This may be 0, which indicates no ID is set.
83 optional uint32 id = 1;
84
85 // The name of the type. This corresponds to the 'type' part of a full resource name of the form
86 // package:type/entry. The set of legal type names is listed in Resource.cpp.
87 optional string name = 2;
88
89 // The entries defined for this type.
Adam Lesinski4ffea042017-08-10 15:37:28 -070090 repeated Entry entry = 3;
Adam Lesinski0c808952017-07-10 05:40:39 -070091}
92
93// The status of a symbol/entry. This contains information like visibility (public/private),
94// comments, and whether the entry can be overridden.
95message SymbolStatus {
96 // The visibility of the resource outside of its package.
97 enum Visibility {
98 // No visibility was explicitly specified. This is typically treated as private.
99 // The distinction is important when two separate R.java files are generated: a public and
100 // private one. An unknown visibility, in this case, would cause the resource to be omitted
101 // from either R.java.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700102 UNKNOWN = 0;
Adam Lesinski0c808952017-07-10 05:40:39 -0700103
104 // A resource was explicitly marked as private. This means the resource can not be accessed
105 // outside of its package unless the @*package:type/entry notation is used (the asterisk being
106 // the private accessor). If two R.java files are generated (private + public), the resource
107 // will only be emitted to the private R.java file.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700108 PRIVATE = 1;
Adam Lesinski0c808952017-07-10 05:40:39 -0700109
110 // A resource was explicitly marked as public. This means the resource can be accessed
111 // from any package, and is emitted into all R.java files, public and private.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700112 PUBLIC = 2;
Adam Lesinski0c808952017-07-10 05:40:39 -0700113 }
114
115 optional Visibility visibility = 1;
116
117 // The path at which this entry's visibility was defined (eg. public.xml).
118 optional Source source = 2;
119
120 // The comment associated with the <public> tag.
121 optional string comment = 3;
122
123 // Whether the symbol can be merged into another resource table without there being an existing
124 // definition to override. Used for overlays and set to true when <add-resource> is specified.
125 optional bool allow_new = 4;
126}
127
128// An entry declaration. An entry has a full resource ID that is the combination of package ID,
129// type ID, and its own entry ID. An entry on its own has no value, but values are defined for
130// various configurations/variants.
131message Entry {
132 // The ID of this entry. Together with the package ID and type ID, this forms a full resource ID
133 // of the form 0xPPTTEEEE, where PP is the package ID, TT is the type ID, and EEEE is the entry
134 // ID.
135 optional uint32 id = 1;
136
137 // The name of this entry. This corresponds to the 'entry' part of a full resource name of the
138 // form package:type/entry.
139 optional string name = 2;
140
141 // The symbol status of this entry, which includes visibility information.
142 optional SymbolStatus symbol_status = 3;
143
144 // The set of values defined for this entry, each corresponding to a different
145 // configuration/variant.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700146 repeated ConfigValue config_value = 4;
Adam Lesinski0c808952017-07-10 05:40:39 -0700147}
148
149// A Configuration/Value pair.
150message ConfigValue {
151 optional ConfigDescription config = 1;
152 optional Value value = 2;
153}
154
155// The generic meta-data for every value in a resource table.
156message Value {
157 // Where the value was defined.
158 optional Source source = 1;
159
160 // Any comment associated with the value.
161 optional string comment = 2;
162
163 // Whether the value can be overridden.
164 optional bool weak = 3;
165
166 // If the value is an Item, this is set.
167 optional Item item = 4;
168
169 // If the value is a CompoundValue, this is set.
170 optional CompoundValue compound_value = 5;
171}
172
173// An Item is an abstract type. It represents a value that can appear inline in many places, such
174// as XML attribute values or on the right hand side of style attribute definitions. The concrete
175// type is one of the types below. Only one can be set.
176message Item {
177 optional Reference ref = 1;
178 optional String str = 2;
179 optional RawString raw_str = 3;
Adam Lesinski08535002017-08-04 16:15:17 -0700180 optional StyledString styled_str = 4;
181 optional FileReference file = 5;
182 optional Id id = 6;
183 optional Primitive prim = 7;
Adam Lesinski0c808952017-07-10 05:40:39 -0700184}
185
186// A CompoundValue is an abstract type. It represents a value that is a made of other values.
187// These can only usually appear as top-level resources. The concrete type is one of the types
188// below. Only one can be set.
189message CompoundValue {
190 optional Attribute attr = 1;
191 optional Style style = 2;
192 optional Styleable styleable = 3;
193 optional Array array = 4;
194 optional Plural plural = 5;
195}
196
197// 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 -0800198message Reference {
Adam Lesinski0c808952017-07-10 05:40:39 -0700199 enum Type {
200 // A plain reference (@package:type/entry).
Adam Lesinski4ffea042017-08-10 15:37:28 -0700201 REFERENCE = 0;
Adam Lesinski0c808952017-07-10 05:40:39 -0700202
203 // A reference to a theme attribute (?package:type/entry).
Adam Lesinski4ffea042017-08-10 15:37:28 -0700204 ATTRIBUTE = 1;
Adam Lesinski0c808952017-07-10 05:40:39 -0700205 }
206
207 optional Type type = 1;
208
209 // The resource ID (0xPPTTEEEE) of the resource being referred.
210 optional uint32 id = 2;
211
Adam Lesinski08535002017-08-04 16:15:17 -0700212 // The optional resource name.
213 optional string name = 3;
Adam Lesinski0c808952017-07-10 05:40:39 -0700214
215 // Whether this reference is referencing a private resource (@*package:type/entry).
216 optional bool private = 4;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800217}
218
Adam Lesinski0c808952017-07-10 05:40:39 -0700219// A value that represents an ID. This is just a placeholder, as ID values are used to occupy a
220// resource ID (0xPPTTEEEE) as a unique identifier. Their value is unimportant.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800221message Id {
222}
223
Adam Lesinski0c808952017-07-10 05:40:39 -0700224// A value that is a string.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800225message String {
Adam Lesinski08535002017-08-04 16:15:17 -0700226 optional string value = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800227}
228
Adam Lesinski0c808952017-07-10 05:40:39 -0700229// A value that is a raw string, which is unescaped/uninterpreted. This is typically used to
230// represent the value of a style attribute before the attribute is compiled and the set of
231// allowed values is known.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800232message RawString {
Adam Lesinski08535002017-08-04 16:15:17 -0700233 optional string value = 1;
234}
235
236// A string with styling information, like html tags that specify boldness, italics, etc.
237message StyledString {
238 // The raw text of the string.
239 optional string value = 1;
240
241 // A Span marks a region of the string text that is styled.
242 message Span {
243 // The name of the tag, and its attributes, encoded as follows:
244 // tag_name;attr1=value1;attr2=value2;[...]
245 optional string tag = 1;
246
247 // The first character position this span applies to, in UTF-16 offset.
248 optional uint32 first_char = 2;
249
250 // The last character position this span applies to, in UTF-16 offset.
251 optional uint32 last_char = 3;
252 }
253
254 repeated Span span = 2;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800255}
256
Adam Lesinski0c808952017-07-10 05:40:39 -0700257// A value that is a reference to an external entity, like an XML file or a PNG.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800258message FileReference {
Adam Lesinski08535002017-08-04 16:15:17 -0700259 // Path to a file within the APK (typically res/type-config/entry.ext).
260 optional string path = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800261}
262
Adam Lesinski0c808952017-07-10 05:40:39 -0700263// A value that represents a primitive data type (float, int, boolean, etc.).
264// Corresponds to the fields (type/data) of the C struct android::Res_value.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800265message Primitive {
Adam Lesinski0c808952017-07-10 05:40:39 -0700266 optional uint32 type = 1;
267 optional uint32 data = 2;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800268}
269
Adam Lesinski0c808952017-07-10 05:40:39 -0700270// A value that represents an XML attribute and what values it accepts.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800271message Attribute {
Adam Lesinski0c808952017-07-10 05:40:39 -0700272 // A Symbol used to represent an enum or a flag.
273 message Symbol {
274 // Where the enum/flag item was defined.
275 optional Source source = 1;
276
277 // Any comments associated with the enum or flag.
278 optional string comment = 2;
279
280 // The name of the enum/flag as a reference. Enums/flag items are generated as ID resource
281 // values.
282 optional Reference name = 3;
283
284 // The value of the enum/flag.
285 optional uint32 value = 4;
286 }
287
Adam Lesinski4ffea042017-08-10 15:37:28 -0700288 // Bitmask of formats allowed for an attribute.
289 enum FormatFlags {
290 ANY = 0x0000ffff; // Allows any type except ENUM and FLAGS.
291 REFERENCE = 0x01; // Allows Reference values.
292 STRING = 0x02; // Allows String/StyledString values.
293 INTEGER = 0x04; // Allows any integer BinaryPrimitive values.
294 BOOLEAN = 0x08; // Allows any boolean BinaryPrimitive values.
295 COLOR = 0x010; // Allows any color BinaryPrimitive values.
296 FLOAT = 0x020; // Allows any float BinaryPrimitive values.
297 DIMENSION = 0x040; // Allows any dimension BinaryPrimitive values.
298 FRACTION = 0x080; // Allows any fraction BinaryPrimitive values.
299 ENUM = 0x00010000; // Allows enums that are defined in the Attribute's symbols.
300 // ENUM and FLAGS cannot BOTH be set.
301 FLAGS = 0x00020000; // Allows flags that are defined in the Attribute's symbols.
302 // ENUM and FLAGS cannot BOTH be set.
303 }
304
305 // A bitmask of types that this XML attribute accepts. Corresponds to the flags in the
306 // enum FormatFlags.
Adam Lesinski0c808952017-07-10 05:40:39 -0700307 optional uint32 format_flags = 1;
308
309 // The smallest integer allowed for this XML attribute. Only makes sense if the format includes
Adam Lesinski4ffea042017-08-10 15:37:28 -0700310 // FormatFlags::INTEGER.
Adam Lesinski0c808952017-07-10 05:40:39 -0700311 optional int32 min_int = 2;
312
313 // The largest integer allowed for this XML attribute. Only makes sense if the format includes
Adam Lesinski4ffea042017-08-10 15:37:28 -0700314 // FormatFlags::INTEGER.
Adam Lesinski0c808952017-07-10 05:40:39 -0700315 optional int32 max_int = 3;
316
317 // The set of enums/flags defined in this attribute. Only makes sense if the format includes
Adam Lesinski4ffea042017-08-10 15:37:28 -0700318 // either FormatFlags::ENUM or FormatFlags::FLAGS. Having both is an error.
319 repeated Symbol symbol = 4;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800320}
321
Adam Lesinski0c808952017-07-10 05:40:39 -0700322// A value that represents a style.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800323message Style {
Adam Lesinski0c808952017-07-10 05:40:39 -0700324 // An XML attribute/value pair defined in the style.
325 message Entry {
326 // Where the entry was defined.
327 optional Source source = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800328
Adam Lesinski0c808952017-07-10 05:40:39 -0700329 // Any comments associated with the entry.
330 optional string comment = 2;
331
332 // A reference to the XML attribute.
333 optional Reference key = 3;
334
335 // The Item defined for this XML attribute.
336 optional Item item = 4;
337 }
338
339 // The optinal style from which this style inherits attributes.
340 optional Reference parent = 1;
341
342 // The source file information of the parent inheritance declaration.
343 optional Source parent_source = 2;
344
345 // The set of XML attribute/value pairs for this style.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700346 repeated Entry entry = 3;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800347}
348
Adam Lesinski0c808952017-07-10 05:40:39 -0700349// A value that represents a <declare-styleable> XML resource. These are not real resources and
350// 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 -0800351message Styleable {
Adam Lesinski0c808952017-07-10 05:40:39 -0700352 // An attribute defined for this styleable.
353 message Entry {
354 // Where the attribute was defined within the <declare-styleable> block.
355 optional Source source = 1;
356
357 // Any comments associated with the declaration.
358 optional string comment = 2;
359
360 // The reference to the attribute.
361 optional Reference attr = 3;
362 }
363
364 // The set of attribute declarations.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700365 repeated Entry entry = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800366}
367
Adam Lesinski0c808952017-07-10 05:40:39 -0700368// A value that represents an array of resource values.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800369message Array {
Adam Lesinski0c808952017-07-10 05:40:39 -0700370 // A single element of the array.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700371 message Element {
Adam Lesinski0c808952017-07-10 05:40:39 -0700372 // Where the element was defined.
373 optional Source source = 1;
374
375 // Any comments associated with the element.
376 optional string comment = 2;
377
378 // The value assigned to this element.
379 optional Item item = 3;
380 }
381
382 // The list of array elements.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700383 repeated Element element = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800384}
385
Adam Lesinski0c808952017-07-10 05:40:39 -0700386// A value that represents a string and its many variations based on plurality.
Adam Lesinski59e04c62016-02-04 15:59:23 -0800387message Plural {
Adam Lesinski0c808952017-07-10 05:40:39 -0700388 // The arity of the plural.
389 enum Arity {
Adam Lesinski4ffea042017-08-10 15:37:28 -0700390 ZERO = 0;
391 ONE = 1;
392 TWO = 2;
393 FEW = 3;
394 MANY = 4;
395 OTHER = 5;
Adam Lesinski0c808952017-07-10 05:40:39 -0700396 }
Adam Lesinski59e04c62016-02-04 15:59:23 -0800397
Adam Lesinski0c808952017-07-10 05:40:39 -0700398 // The plural value for a given arity.
399 message Entry {
400 // Where the plural was defined.
401 optional Source source = 1;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800402
Adam Lesinski0c808952017-07-10 05:40:39 -0700403 // Any comments associated with the plural.
404 optional string comment = 2;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800405
Adam Lesinski0c808952017-07-10 05:40:39 -0700406 // The arity of the plural.
407 optional Arity arity = 3;
408
409 // The value assigned to this plural.
410 optional Item item = 4;
411 }
412
413 // The set of arity/plural mappings.
Adam Lesinski4ffea042017-08-10 15:37:28 -0700414 repeated Entry entry = 1;
415}
416
417// Defines an abstract XmlNode that must be either an XmlElement, or
418// a text node represented by a string.
419message XmlNode {
420 // If set, this node is an element/tag.
421 optional XmlElement element = 1;
422
423 // If set, this node is a chunk of text.
424 optional string text = 2;
425
426 // Source line and column info.
427 optional SourcePosition source = 3;
428}
429
430// An <element> in an XML document.
431message XmlElement {
432 // Namespaces defined on this element.
433 repeated XmlNamespace namespace_declaration = 1;
434
435 // The namespace URI of this element.
436 optional string namespace_uri = 2;
437
438 // The name of this element.
439 optional string name = 3;
440
441 // The attributes of this element.
442 repeated XmlAttribute attribute = 4;
443
444 // The children of this element.
445 repeated XmlNode child = 5;
446}
447
448// A namespace declaration on an XmlElement (xmlns:android="http://...").
449message XmlNamespace {
450 optional string prefix = 1;
451 optional string uri = 2;
452
453 // Source line and column info.
454 optional SourcePosition source = 3;
455}
456
457// An attribute defined on an XmlElement (android:text="...").
458message XmlAttribute {
459 optional string namespace_uri = 1;
460 optional string name = 2;
461 optional string value = 3;
462
463 // Source line and column info.
464 optional SourcePosition source = 4;
465
466 // The resource ID (0xPPTTEEEE) of the attribute.
467 optional uint32 resource_id = 5;
468
469 // The interpreted/compiled version of the `value` string.
470 optional Item compiled_item = 6;
Adam Lesinski59e04c62016-02-04 15:59:23 -0800471}