Loading tools/aapt2/Resource.h +3 −0 Original line number Diff line number Diff line Loading @@ -118,6 +118,9 @@ struct ResourceNameRef { bool is_valid() const; }; constexpr const uint8_t kAppPackageId = 0x7fu; constexpr const uint8_t kFrameworkPackageId = 0x01u; /** * A binary identifier representing a resource. Internally it * is a 32bit integer split as follows: Loading tools/aapt2/ResourceUtils.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -533,6 +533,7 @@ uint32_t AndroidTypeToAttributeTypeMask(uint16_t type) { case android::Res_value::TYPE_REFERENCE: case android::Res_value::TYPE_ATTRIBUTE: case android::Res_value::TYPE_DYNAMIC_REFERENCE: case android::Res_value::TYPE_DYNAMIC_ATTRIBUTE: return android::ResTable_map::TYPE_REFERENCE; case android::Res_value::TYPE_STRING: Loading tools/aapt2/ResourceValues.cpp +18 −4 Original line number Diff line number Diff line Loading @@ -88,10 +88,24 @@ bool Reference::Equals(const Value* value) const { } bool Reference::Flatten(android::Res_value* out_value) const { out_value->dataType = (reference_type == Reference::Type::kResource) ? android::Res_value::TYPE_REFERENCE : android::Res_value::TYPE_ATTRIBUTE; out_value->data = util::HostToDevice32(id ? id.value().id : 0); const ResourceId resid = id.value_or_default(ResourceId(0)); const bool dynamic = (resid.package_id() != kFrameworkPackageId && resid.package_id() != kAppPackageId); if (reference_type == Reference::Type::kResource) { if (dynamic) { out_value->dataType = android::Res_value::TYPE_DYNAMIC_REFERENCE; } else { out_value->dataType = android::Res_value::TYPE_REFERENCE; } } else { if (dynamic) { out_value->dataType = android::Res_value::TYPE_DYNAMIC_ATTRIBUTE; } else { out_value->dataType = android::Res_value::TYPE_ATTRIBUTE; } } out_value->data = util::HostToDevice32(resid.id); return true; } Loading tools/aapt2/java/JavaClassGenerator.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -533,9 +533,14 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, std::unique_ptr<MethodDefinition> rewrite_method; // Generate an onResourcesLoaded() callback if requested. if (options_.generate_rewrite_callback) { if (options_.rewrite_callback_options) { rewrite_method = util::make_unique<MethodDefinition>("public static void onResourcesLoaded(int p)"); for (const std::string& package_to_callback : options_.rewrite_callback_options.value().packages_to_callback) { rewrite_method->AppendStatement( StringPrintf("%s.R.onResourcesLoaded(p);", package_to_callback.data())); } } for (const auto& package : table_->packages) { Loading tools/aapt2/java/JavaClassGenerator.h +9 −3 Original line number Diff line number Diff line Loading @@ -33,13 +33,19 @@ class AnnotationProcessor; class ClassDefinition; class MethodDefinition; // Options for generating onResourcesLoaded callback in R.java. struct OnResourcesLoadedCallbackOptions { // Other R classes to delegate the same callback to (with the same package ID). std::vector<std::string> packages_to_callback; }; struct JavaClassGeneratorOptions { // Specifies whether to use the 'final' modifier on resource entries. Default is true. bool use_final = true; // Whether to generate code to rewrite the package ID of resources. // Implies use_final == true. Default is false. bool generate_rewrite_callback = false; // If set, generates code to rewrite the package ID of resources. // Implies use_final == true. Default is unset. Maybe<OnResourcesLoadedCallbackOptions> rewrite_callback_options; enum class SymbolTypes { kAll, Loading Loading
tools/aapt2/Resource.h +3 −0 Original line number Diff line number Diff line Loading @@ -118,6 +118,9 @@ struct ResourceNameRef { bool is_valid() const; }; constexpr const uint8_t kAppPackageId = 0x7fu; constexpr const uint8_t kFrameworkPackageId = 0x01u; /** * A binary identifier representing a resource. Internally it * is a 32bit integer split as follows: Loading
tools/aapt2/ResourceUtils.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -533,6 +533,7 @@ uint32_t AndroidTypeToAttributeTypeMask(uint16_t type) { case android::Res_value::TYPE_REFERENCE: case android::Res_value::TYPE_ATTRIBUTE: case android::Res_value::TYPE_DYNAMIC_REFERENCE: case android::Res_value::TYPE_DYNAMIC_ATTRIBUTE: return android::ResTable_map::TYPE_REFERENCE; case android::Res_value::TYPE_STRING: Loading
tools/aapt2/ResourceValues.cpp +18 −4 Original line number Diff line number Diff line Loading @@ -88,10 +88,24 @@ bool Reference::Equals(const Value* value) const { } bool Reference::Flatten(android::Res_value* out_value) const { out_value->dataType = (reference_type == Reference::Type::kResource) ? android::Res_value::TYPE_REFERENCE : android::Res_value::TYPE_ATTRIBUTE; out_value->data = util::HostToDevice32(id ? id.value().id : 0); const ResourceId resid = id.value_or_default(ResourceId(0)); const bool dynamic = (resid.package_id() != kFrameworkPackageId && resid.package_id() != kAppPackageId); if (reference_type == Reference::Type::kResource) { if (dynamic) { out_value->dataType = android::Res_value::TYPE_DYNAMIC_REFERENCE; } else { out_value->dataType = android::Res_value::TYPE_REFERENCE; } } else { if (dynamic) { out_value->dataType = android::Res_value::TYPE_DYNAMIC_ATTRIBUTE; } else { out_value->dataType = android::Res_value::TYPE_ATTRIBUTE; } } out_value->data = util::HostToDevice32(resid.id); return true; } Loading
tools/aapt2/java/JavaClassGenerator.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -533,9 +533,14 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, std::unique_ptr<MethodDefinition> rewrite_method; // Generate an onResourcesLoaded() callback if requested. if (options_.generate_rewrite_callback) { if (options_.rewrite_callback_options) { rewrite_method = util::make_unique<MethodDefinition>("public static void onResourcesLoaded(int p)"); for (const std::string& package_to_callback : options_.rewrite_callback_options.value().packages_to_callback) { rewrite_method->AppendStatement( StringPrintf("%s.R.onResourcesLoaded(p);", package_to_callback.data())); } } for (const auto& package : table_->packages) { Loading
tools/aapt2/java/JavaClassGenerator.h +9 −3 Original line number Diff line number Diff line Loading @@ -33,13 +33,19 @@ class AnnotationProcessor; class ClassDefinition; class MethodDefinition; // Options for generating onResourcesLoaded callback in R.java. struct OnResourcesLoadedCallbackOptions { // Other R classes to delegate the same callback to (with the same package ID). std::vector<std::string> packages_to_callback; }; struct JavaClassGeneratorOptions { // Specifies whether to use the 'final' modifier on resource entries. Default is true. bool use_final = true; // Whether to generate code to rewrite the package ID of resources. // Implies use_final == true. Default is false. bool generate_rewrite_callback = false; // If set, generates code to rewrite the package ID of resources. // Implies use_final == true. Default is unset. Maybe<OnResourcesLoadedCallbackOptions> rewrite_callback_options; enum class SymbolTypes { kAll, Loading