1/*
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 = "proto3";
18
19import "frameworks/base/tools/aapt2/Configuration.proto";
20
21package aapt.pb;
22
23option java_package = "com.android.aapt";
24option optimize_for = LITE_RUNTIME;
25
26// A string pool that wraps the binary form of the C++ class android::ResStringPool.
27message StringPool {
28  bytes data = 1;
29}
30
31// The position of a declared entity within a file.
32message SourcePosition {
33  uint32 line_number = 1;
34  uint32 column_number = 2;
35}
36
37// Developer friendly source file information for an entity in the resource table.
38message Source {
39  // The index of the string path within the source string pool of a ResourceTable.
40  uint32 path_idx = 1;
41  SourcePosition position = 2;
42}
43
44// Top level message representing a resource table.
45message ResourceTable {
46  // The string pool containing source paths referenced throughout the resource table. This does
47  // not end up in the final binary ARSC file.
48  StringPool source_pool = 1;
49
50  // Resource definitions corresponding to an Android package.
51  repeated Package package = 2;
52}
53
54// A package ID in the range [0x00, 0xff].
55message PackageId {
56  uint32 id = 1;
57}
58
59// Defines resources for an Android package.
60message Package {
61  // The package ID of this package, in the range [0x00, 0xff].
62  // - ID 0x00 is reserved for shared libraries, or when the ID is assigned at run-time.
63  // - ID 0x01 is reserved for the 'android' package (framework).
64  // - ID range [0x02, 0x7f) is reserved for auto-assignment to shared libraries at run-time.
65  // - ID 0x7f is reserved for the application package.
66  // - IDs > 0x7f are reserved for the application as well and are treated as feature splits.
67  // This may not be set if no ID was assigned.
68  PackageId package_id = 1;
69
70  // The Java compatible Android package name of the app.
71  string package_name = 2;
72
73  // The series of types defined by the package.
74  repeated Type type = 3;
75}
76
77// A type ID in the range [0x01, 0xff].
78message TypeId {
79  uint32 id = 1;
80}
81
82// A set of resources grouped under a common type. Such types include string, layout, xml, dimen,
83// attr, etc. This maps to the second part of a resource identifier in Java (R.type.entry).
84message Type {
85  // The ID of the type. This may not be set if no ID was assigned.
86  TypeId type_id = 1;
87
88  // The name of the type. This corresponds to the 'type' part of a full resource name of the form
89  // package:type/entry. The set of legal type names is listed in Resource.cpp.
90  string name = 2;
91
92  // The entries defined for this type.
93  repeated Entry entry = 3;
94}
95
96// The Visibility of a symbol/entry (public, private, undefined).
97message Visibility {
98  // The visibility of the resource outside of its package.
99  enum Level {
100    // No visibility was explicitly specified. This is typically treated as private.
101    // The distinction is important when two separate R.java files are generated: a public and
102    // private one. An unknown visibility, in this case, would cause the resource to be omitted
103    // from either R.java.
104    UNKNOWN = 0;
105
106    // A resource was explicitly marked as private. This means the resource can not be accessed
107    // outside of its package unless the @*package:type/entry notation is used (the asterisk being
108    // the private accessor). If two R.java files are generated (private + public), the resource
109    // will only be emitted to the private R.java file.
110    PRIVATE = 1;
111
112    // A resource was explicitly marked as public. This means the resource can be accessed
113    // from any package, and is emitted into all R.java files, public and private.
114    PUBLIC = 2;
115  }
116
117  Level level = 1;
118
119  // The path at which this entry's visibility was defined (eg. public.xml).
120  Source source = 2;
121
122  // The comment associated with the <public> tag.
123  string comment = 3;
124}
125
126// Whether a resource comes from a compile-time overlay and is explicitly allowed to not overlay an
127// existing resource.
128message AllowNew {
129  // Where this was defined in source.
130  Source source = 1;
131
132  // Any comment associated with the declaration.
133  string comment = 2;
134}
135
136// Whether a resource is overlayable by runtime resource overlays (RRO).
137message Overlayable {
138  // Where this declaration was defined in source.
139  Source source = 1;
140
141  // Any comment associated with the declaration.
142  string comment = 2;
143}
144
145// An entry ID in the range [0x0000, 0xffff].
146message EntryId {
147  uint32 id = 1;
148}
149
150// An entry declaration. An entry has a full resource ID that is the combination of package ID,
151// type ID, and its own entry ID. An entry on its own has no value, but values are defined for
152// various configurations/variants.
153message Entry {
154  // The ID of this entry. Together with the package ID and type ID, this forms a full resource ID
155  // of the form 0xPPTTEEEE, where PP is the package ID, TT is the type ID, and EEEE is the entry
156  // ID.
157  // This may not be set if no ID was assigned.
158  EntryId entry_id = 1;
159
160  // The name of this entry. This corresponds to the 'entry' part of a full resource name of the
161  // form package:type/entry.
162  string name = 2;
163
164  // The visibility of this entry (public, private, undefined).
165  Visibility visibility = 3;
166
167  // Whether this resource, when originating from a compile-time overlay, is allowed to NOT overlay
168  // any existing resources.
169  AllowNew allow_new = 4;
170
171  // Whether this resource can be overlaid by a runtime resource overlay (RRO).
172  Overlayable overlayable = 5;
173
174  // The set of values defined for this entry, each corresponding to a different
175  // configuration/variant.
176  repeated ConfigValue config_value = 6;
177}
178
179// A Configuration/Value pair.
180message ConfigValue {
181  Configuration config = 1;
182  Value value = 2;
183}
184
185// The generic meta-data for every value in a resource table.
186message Value {
187  // Where the value was defined.
188  Source source = 1;
189
190  // Any comment associated with the value.
191  string comment = 2;
192
193  // Whether the value can be overridden.
194  bool weak = 3;
195
196  // The value is either an Item or a CompoundValue.
197  oneof value {
198    Item item = 4;
199    CompoundValue compound_value = 5;
200  }
201}
202
203// An Item is an abstract type. It represents a value that can appear inline in many places, such
204// as XML attribute values or on the right hand side of style attribute definitions. The concrete
205// type is one of the types below. Only one can be set.
206message Item {
207  oneof value {
208    Reference ref = 1;
209    String str = 2;
210    RawString raw_str = 3;
211    StyledString styled_str = 4;
212    FileReference file = 5;
213    Id id = 6;
214    Primitive prim = 7;
215  }
216}
217
218// A CompoundValue is an abstract type. It represents a value that is a made of other values.
219// These can only usually appear as top-level resources. The concrete type is one of the types
220// below. Only one can be set.
221message CompoundValue {
222  oneof value {
223    Attribute attr = 1;
224    Style style = 2;
225    Styleable styleable = 3;
226    Array array = 4;
227    Plural plural = 5;
228  }
229}
230
231// A value that is a reference to another resource. This reference can be by name or resource ID.
232message Reference {
233  enum Type {
234    // A plain reference (@package:type/entry).
235    REFERENCE = 0;
236
237    // A reference to a theme attribute (?package:type/entry).
238    ATTRIBUTE = 1;
239  }
240
241  Type type = 1;
242
243  // The resource ID (0xPPTTEEEE) of the resource being referred. This is optional.
244  uint32 id = 2;
245
246  // The name of the resource being referred. This is optional if the resource ID is set.
247  string name = 3;
248
249  // Whether this reference is referencing a private resource (@*package:type/entry).
250  bool private = 4;
251}
252
253// A value that represents an ID. This is just a placeholder, as ID values are used to occupy a
254// resource ID (0xPPTTEEEE) as a unique identifier. Their value is unimportant.
255message Id {
256}
257
258// A value that is a string.
259message String {
260  string value = 1;
261}
262
263// A value that is a raw string, which is unescaped/uninterpreted. This is typically used to
264// represent the value of a style attribute before the attribute is compiled and the set of
265// allowed values is known.
266message RawString {
267  string value = 1;
268}
269
270// A string with styling information, like html tags that specify boldness, italics, etc.
271message StyledString {
272  // The raw text of the string.
273  string value = 1;
274
275  // A Span marks a region of the string text that is styled.
276  message Span {
277    // The name of the tag, and its attributes, encoded as follows:
278    // tag_name;attr1=value1;attr2=value2;[...]
279    string tag = 1;
280
281    // The first character position this span applies to, in UTF-16 offset.
282    uint32 first_char = 2;
283
284    // The last character position this span applies to, in UTF-16 offset.
285    uint32 last_char = 3;
286  }
287
288  repeated Span span = 2;
289}
290
291// A value that is a reference to an external entity, like an XML file or a PNG.
292message FileReference {
293  enum Type {
294    UNKNOWN = 0;
295    PNG = 1;
296    BINARY_XML = 2;
297    PROTO_XML = 3;
298  }
299
300  // Path to a file within the APK (typically res/type-config/entry.ext).
301  string path = 1;
302
303  // The type of file this path points to. For UAM bundle, this cannot be
304  // BINARY_XML.
305  Type type = 2;
306}
307
308// A value that represents a primitive data type (float, int, boolean, etc.).
309// Refer to Res_value in ResourceTypes.h for info on types and formatting
310message Primitive {
311  message NullType {
312  }
313  message EmptyType {
314  }
315  oneof oneof_value {
316    NullType null_value = 1;
317    EmptyType empty_value = 2;
318    float float_value = 3;
319    uint32 dimension_value = 13;
320    uint32 fraction_value = 14;
321    int32 int_decimal_value = 6;
322    uint32 int_hexadecimal_value = 7;
323    bool boolean_value = 8;
324    uint32 color_argb8_value = 9;
325    uint32 color_rgb8_value = 10;
326    uint32 color_argb4_value = 11;
327    uint32 color_rgb4_value = 12;
328    float dimension_value_deprecated = 4 [deprecated=true];
329    float fraction_value_deprecated = 5 [deprecated=true];
330  }
331}
332
333// A value that represents an XML attribute and what values it accepts.
334message Attribute {
335  // A Symbol used to represent an enum or a flag.
336  message Symbol {
337    // Where the enum/flag item was defined.
338    Source source = 1;
339
340    // Any comments associated with the enum or flag.
341    string comment = 2;
342
343    // The name of the enum/flag as a reference. Enums/flag items are generated as ID resource
344    // values.
345    Reference name = 3;
346
347    // The value of the enum/flag.
348    uint32 value = 4;
349  }
350
351  // Bitmask of formats allowed for an attribute.
352  enum FormatFlags {
353    NONE = 0x0;          // Proto3 requires a default of 0.
354    ANY = 0x0000ffff;    // Allows any type except ENUM and FLAGS.
355    REFERENCE = 0x01;    // Allows Reference values.
356    STRING = 0x02;       // Allows String/StyledString values.
357    INTEGER = 0x04;      // Allows any integer BinaryPrimitive values.
358    BOOLEAN = 0x08;      // Allows any boolean BinaryPrimitive values.
359    COLOR = 0x010;       // Allows any color BinaryPrimitive values.
360    FLOAT = 0x020;       // Allows any float BinaryPrimitive values.
361    DIMENSION = 0x040;   // Allows any dimension BinaryPrimitive values.
362    FRACTION = 0x080;    // Allows any fraction BinaryPrimitive values.
363    ENUM = 0x00010000;   // Allows enums that are defined in the Attribute's symbols.
364                         // ENUM and FLAGS cannot BOTH be set.
365    FLAGS = 0x00020000;  // Allows flags that are defined in the Attribute's symbols.
366                         // ENUM and FLAGS cannot BOTH be set.
367  }
368
369  // A bitmask of types that this XML attribute accepts. Corresponds to the flags in the
370  // enum FormatFlags.
371  uint32 format_flags = 1;
372
373  // The smallest integer allowed for this XML attribute. Only makes sense if the format includes
374  // FormatFlags::INTEGER.
375  int32 min_int = 2;
376
377  // The largest integer allowed for this XML attribute. Only makes sense if the format includes
378  // FormatFlags::INTEGER.
379  int32 max_int = 3;
380
381  // The set of enums/flags defined in this attribute. Only makes sense if the format includes
382  // either FormatFlags::ENUM or FormatFlags::FLAGS. Having both is an error.
383  repeated Symbol symbol = 4;
384}
385
386// A value that represents a style.
387message Style {
388  // An XML attribute/value pair defined in the style.
389  message Entry {
390    // Where the entry was defined.
391    Source source = 1;
392
393    // Any comments associated with the entry.
394    string comment = 2;
395
396    // A reference to the XML attribute.
397    Reference key = 3;
398
399    // The Item defined for this XML attribute.
400    Item item = 4;
401  }
402
403  // The optinal style from which this style inherits attributes.
404  Reference parent = 1;
405
406  // The source file information of the parent inheritance declaration.
407  Source parent_source = 2;
408
409  // The set of XML attribute/value pairs for this style.
410  repeated Entry entry = 3;
411}
412
413// A value that represents a <declare-styleable> XML resource. These are not real resources and
414// only end up as Java fields in the generated R.java. They do not end up in the binary ARSC file.
415message Styleable {
416  // An attribute defined for this styleable.
417  message Entry {
418    // Where the attribute was defined within the <declare-styleable> block.
419    Source source = 1;
420
421    // Any comments associated with the declaration.
422    string comment = 2;
423
424    // The reference to the attribute.
425    Reference attr = 3;
426  }
427
428  // The set of attribute declarations.
429  repeated Entry entry = 1;
430}
431
432// A value that represents an array of resource values.
433message Array {
434  // A single element of the array.
435  message Element {
436    // Where the element was defined.
437    Source source = 1;
438
439    // Any comments associated with the element.
440    string comment = 2;
441
442    // The value assigned to this element.
443    Item item = 3;
444  }
445
446  // The list of array elements.
447  repeated Element element = 1;
448}
449
450// A value that represents a string and its many variations based on plurality.
451message Plural {
452  // The arity of the plural.
453  enum Arity {
454    ZERO = 0;
455    ONE = 1;
456    TWO = 2;
457    FEW = 3;
458    MANY = 4;
459    OTHER = 5;
460  }
461
462  // The plural value for a given arity.
463  message Entry {
464    // Where the plural was defined.
465    Source source = 1;
466
467    // Any comments associated with the plural.
468    string comment = 2;
469
470    // The arity of the plural.
471    Arity arity = 3;
472
473    // The value assigned to this plural.
474    Item item = 4;
475  }
476
477  // The set of arity/plural mappings.
478  repeated Entry entry = 1;
479}
480
481// Defines an abstract XmlNode that must be either an XmlElement, or
482// a text node represented by a string.
483message XmlNode {
484  oneof node {
485    XmlElement element = 1;
486    string text = 2;
487  }
488
489  // Source line and column info.
490  SourcePosition source = 3;
491}
492
493// An <element> in an XML document.
494message XmlElement {
495  // Namespaces defined on this element.
496  repeated XmlNamespace namespace_declaration = 1;
497
498  // The namespace URI of this element.
499  string namespace_uri = 2;
500
501  // The name of this element.
502  string name = 3;
503
504  // The attributes of this element.
505  repeated XmlAttribute attribute = 4;
506
507  // The children of this element.
508  repeated XmlNode child = 5;
509}
510
511// A namespace declaration on an XmlElement (xmlns:android="http://...").
512message XmlNamespace {
513  string prefix = 1;
514  string uri = 2;
515
516  // Source line and column info.
517  SourcePosition source = 3;
518}
519
520// An attribute defined on an XmlElement (android:text="...").
521message XmlAttribute {
522  string namespace_uri = 1;
523  string name = 2;
524  string value = 3;
525
526  // Source line and column info.
527  SourcePosition source = 4;
528
529  // The optional resource ID (0xPPTTEEEE) of the attribute.
530  uint32 resource_id = 5;
531
532  // The optional interpreted/compiled version of the `value` string.
533  Item compiled_item = 6;
534}
535