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 17// Keep proto2 syntax because we require the distinction between fields that 18// are set and unset. 19syntax = "proto2"; 20 21option java_package = "com.android.aapt"; 22option optimize_for = LITE_RUNTIME; 23 24package aapt.pb; 25 26// A configuration description that wraps the binary form of the C++ class 27// aapt::ConfigDescription, with an added product definition. 28// TODO(adamlesinski): Flesh this out to be represented in proto. 29message ConfigDescription { 30 optional bytes data = 1; 31 optional string product = 2; 32} 33 34// A string pool that wraps the binary form of the C++ class android::ResStringPool. 35message StringPool { 36 optional bytes data = 1; 37} 38 39// 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 45// Developer friendly source file information for an entity in the resource table. 46message Source { 47 // The index of the string path within the source string pool of a ResourceTable. 48 optional uint32 path_idx = 1; 49 optional SourcePosition position = 2; 50} 51 52// Top level message representing a resource table. 53message ResourceTable { 54 // The string pool containing source paths referenced throughout the resource table. This does 55 // not end up in the final binary ARSC file. 56 optional StringPool source_pool = 1; 57 58 // Resource definitions corresponding to an Android package. 59 repeated Package package = 2; 60} 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. 76 repeated Type type = 3; 77} 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. 90 repeated Entry entry = 3; 91} 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. 102 UNKNOWN = 0; 103 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. 108 PRIVATE = 1; 109 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. 112 PUBLIC = 2; 113 } 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. 146 repeated ConfigValue config_value = 4; 147} 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; 180 optional StyledString styled_str = 4; 181 optional FileReference file = 5; 182 optional Id id = 6; 183 optional Primitive prim = 7; 184} 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. 198message Reference { 199 enum Type { 200 // A plain reference (@package:type/entry). 201 REFERENCE = 0; 202 203 // A reference to a theme attribute (?package:type/entry). 204 ATTRIBUTE = 1; 205 } 206 207 optional Type type = 1; 208 209 // The resource ID (0xPPTTEEEE) of the resource being referred. 210 optional uint32 id = 2; 211 212 // The optional resource name. 213 optional string name = 3; 214 215 // Whether this reference is referencing a private resource (@*package:type/entry). 216 optional bool private = 4; 217} 218 219// 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. 221message Id { 222} 223 224// A value that is a string. 225message String { 226 optional string value = 1; 227} 228 229// 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. 232message RawString { 233 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; 255} 256 257// A value that is a reference to an external entity, like an XML file or a PNG. 258message FileReference { 259 // Path to a file within the APK (typically res/type-config/entry.ext). 260 optional string path = 1; 261} 262 263// 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. 265message Primitive { 266 optional uint32 type = 1; 267 optional uint32 data = 2; 268} 269 270// A value that represents an XML attribute and what values it accepts. 271message Attribute { 272 // 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 288 // 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. 307 optional uint32 format_flags = 1; 308 309 // The smallest integer allowed for this XML attribute. Only makes sense if the format includes 310 // FormatFlags::INTEGER. 311 optional int32 min_int = 2; 312 313 // The largest integer allowed for this XML attribute. Only makes sense if the format includes 314 // FormatFlags::INTEGER. 315 optional int32 max_int = 3; 316 317 // The set of enums/flags defined in this attribute. Only makes sense if the format includes 318 // either FormatFlags::ENUM or FormatFlags::FLAGS. Having both is an error. 319 repeated Symbol symbol = 4; 320} 321 322// A value that represents a style. 323message Style { 324 // An XML attribute/value pair defined in the style. 325 message Entry { 326 // Where the entry was defined. 327 optional Source source = 1; 328 329 // 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. 346 repeated Entry entry = 3; 347} 348 349// 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. 351message Styleable { 352 // 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. 365 repeated Entry entry = 1; 366} 367 368// A value that represents an array of resource values. 369message Array { 370 // A single element of the array. 371 message Element { 372 // 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. 383 repeated Element element = 1; 384} 385 386// A value that represents a string and its many variations based on plurality. 387message Plural { 388 // The arity of the plural. 389 enum Arity { 390 ZERO = 0; 391 ONE = 1; 392 TWO = 2; 393 FEW = 3; 394 MANY = 4; 395 OTHER = 5; 396 } 397 398 // The plural value for a given arity. 399 message Entry { 400 // Where the plural was defined. 401 optional Source source = 1; 402 403 // Any comments associated with the plural. 404 optional string comment = 2; 405 406 // 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. 414 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; 471} 472