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