Loading tools/aapt2/Resource.h +5 −4 Original line number Diff line number Diff line Loading @@ -147,10 +147,11 @@ struct ResourceId { ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor) ResourceId(uint8_t p, uint8_t t, uint16_t e); bool is_valid() const; // Returns true if the ID is a valid ID that is not dynamic (package ID cannot be 0) bool is_valid_static() const; // Returns true if the ID is a valid ID or dynamic ID (package ID can be 0). bool is_valid_dynamic() const; bool is_valid() const; uint8_t package_id() const; uint8_t type_id() const; Loading Loading @@ -233,11 +234,11 @@ inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {} inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e) : id((p << 24) | (t << 16) | e) {} inline bool ResourceId::is_valid() const { inline bool ResourceId::is_valid_static() const { return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0; } inline bool ResourceId::is_valid_dynamic() const { inline bool ResourceId::is_valid() const { return (id & 0x00ff0000u) != 0; } Loading tools/aapt2/ResourceTable.cpp +8 −8 Original line number Diff line number Diff line Loading @@ -398,7 +398,7 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI // Check for package names appearing twice with two different package ids ResourceTablePackage* package = FindOrCreatePackage(name.package); if (res_id.is_valid_dynamic() && package->id && package->id.value() != res_id.package_id()) { if (res_id.is_valid() && package->id && package->id.value() != res_id.package_id()) { diag->Error(DiagMessage(source) << "trying to add resource '" << name << "' with ID " << res_id << " but package '" << package->name << "' already has ID " Loading @@ -407,9 +407,9 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI } // Whether or not to error on duplicate resources bool check_id = validate_resources_ && res_id.is_valid_dynamic(); bool check_id = validate_resources_ && res_id.is_valid(); // Whether or not to create a duplicate resource if the id does not match bool use_id = !validate_resources_ && res_id.is_valid_dynamic(); bool use_id = !validate_resources_ && res_id.is_valid(); ResourceTableType* type = package->FindOrCreateType(name.type, use_id ? res_id.type_id() : Maybe<uint8_t>()); Loading Loading @@ -463,7 +463,7 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI } } if (res_id.is_valid_dynamic()) { if (res_id.is_valid()) { package->id = res_id.package_id(); type->id = res_id.type_id(); entry->id = res_id.entry_id(); Loading Loading @@ -504,7 +504,7 @@ bool ResourceTable::SetVisibilityImpl(const ResourceNameRef& name, const Visibil // Check for package names appearing twice with two different package ids ResourceTablePackage* package = FindOrCreatePackage(name.package); if (res_id.is_valid_dynamic() && package->id && package->id.value() != res_id.package_id()) { if (res_id.is_valid() && package->id && package->id.value() != res_id.package_id()) { diag->Error(DiagMessage(source) << "trying to add resource '" << name << "' with ID " << res_id << " but package '" << package->name << "' already has ID " Loading @@ -513,9 +513,9 @@ bool ResourceTable::SetVisibilityImpl(const ResourceNameRef& name, const Visibil } // Whether or not to error on duplicate resources bool check_id = validate_resources_ && res_id.is_valid_dynamic(); bool check_id = validate_resources_ && res_id.is_valid(); // Whether or not to create a duplicate resource if the id does not match bool use_id = !validate_resources_ && res_id.is_valid_dynamic(); bool use_id = !validate_resources_ && res_id.is_valid(); ResourceTableType* type = package->FindOrCreateType(name.type, use_id ? res_id.type_id() : Maybe<uint8_t>()); Loading @@ -541,7 +541,7 @@ bool ResourceTable::SetVisibilityImpl(const ResourceNameRef& name, const Visibil return false; } if (res_id.is_valid_dynamic()) { if (res_id.is_valid()) { package->id = res_id.package_id(); type->id = res_id.type_id(); entry->id = res_id.entry_id(); Loading tools/aapt2/ResourceUtils.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -516,7 +516,7 @@ Maybe<ResourceId> ParseResourceId(const StringPiece& str) { if (android::ResTable::stringToInt(str16.data(), str16.size(), &value)) { if (value.dataType == android::Res_value::TYPE_INT_HEX) { ResourceId id(value.data); if (id.is_valid_dynamic()) { if (id.is_valid()) { return id; } } Loading tools/aapt2/ResourceValues.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ bool Reference::Equals(const Value* value) const { bool Reference::Flatten(android::Res_value* out_value) const { const ResourceId resid = id.value_or_default(ResourceId(0)); const bool dynamic = resid.is_valid_dynamic() && is_dynamic; const bool dynamic = resid.is_valid() && is_dynamic; if (reference_type == Reference::Type::kResource) { if (dynamic) { Loading Loading @@ -159,7 +159,7 @@ void Reference::Print(std::ostream* out) const { *out << name.value(); } if (id && id.value().is_valid_dynamic()) { if (id && id.value().is_valid()) { if (name) { *out << " "; } Loading Loading @@ -196,7 +196,7 @@ static void PrettyPrintReferenceImpl(const Reference& ref, bool print_package, P printer->Print("/"); printer->Print(name.entry); } } else if (ref.id && ref.id.value().is_valid_dynamic()) { } else if (ref.id && ref.id.value().is_valid()) { printer->Print(ref.id.value().to_string()); } } Loading tools/aapt2/process/SymbolTable.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -340,7 +340,7 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName( } res_id = asset_manager_.GetResourceId(real_name.to_string()); if (res_id.is_valid() && asset_manager_.GetResourceFlags(res_id.id, &type_spec_flags)) { if (res_id.is_valid_static() && asset_manager_.GetResourceFlags(res_id.id, &type_spec_flags)) { found = true; return false; } Loading Loading @@ -379,7 +379,7 @@ static Maybe<ResourceName> GetResourceName(android::AssetManager2& am, std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById( ResourceId id) { if (!id.is_valid()) { if (!id.is_valid_static()) { // Exit early and avoid the error logs from AssetManager. return {}; } Loading Loading
tools/aapt2/Resource.h +5 −4 Original line number Diff line number Diff line Loading @@ -147,10 +147,11 @@ struct ResourceId { ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor) ResourceId(uint8_t p, uint8_t t, uint16_t e); bool is_valid() const; // Returns true if the ID is a valid ID that is not dynamic (package ID cannot be 0) bool is_valid_static() const; // Returns true if the ID is a valid ID or dynamic ID (package ID can be 0). bool is_valid_dynamic() const; bool is_valid() const; uint8_t package_id() const; uint8_t type_id() const; Loading Loading @@ -233,11 +234,11 @@ inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {} inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e) : id((p << 24) | (t << 16) | e) {} inline bool ResourceId::is_valid() const { inline bool ResourceId::is_valid_static() const { return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0; } inline bool ResourceId::is_valid_dynamic() const { inline bool ResourceId::is_valid() const { return (id & 0x00ff0000u) != 0; } Loading
tools/aapt2/ResourceTable.cpp +8 −8 Original line number Diff line number Diff line Loading @@ -398,7 +398,7 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI // Check for package names appearing twice with two different package ids ResourceTablePackage* package = FindOrCreatePackage(name.package); if (res_id.is_valid_dynamic() && package->id && package->id.value() != res_id.package_id()) { if (res_id.is_valid() && package->id && package->id.value() != res_id.package_id()) { diag->Error(DiagMessage(source) << "trying to add resource '" << name << "' with ID " << res_id << " but package '" << package->name << "' already has ID " Loading @@ -407,9 +407,9 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI } // Whether or not to error on duplicate resources bool check_id = validate_resources_ && res_id.is_valid_dynamic(); bool check_id = validate_resources_ && res_id.is_valid(); // Whether or not to create a duplicate resource if the id does not match bool use_id = !validate_resources_ && res_id.is_valid_dynamic(); bool use_id = !validate_resources_ && res_id.is_valid(); ResourceTableType* type = package->FindOrCreateType(name.type, use_id ? res_id.type_id() : Maybe<uint8_t>()); Loading Loading @@ -463,7 +463,7 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI } } if (res_id.is_valid_dynamic()) { if (res_id.is_valid()) { package->id = res_id.package_id(); type->id = res_id.type_id(); entry->id = res_id.entry_id(); Loading Loading @@ -504,7 +504,7 @@ bool ResourceTable::SetVisibilityImpl(const ResourceNameRef& name, const Visibil // Check for package names appearing twice with two different package ids ResourceTablePackage* package = FindOrCreatePackage(name.package); if (res_id.is_valid_dynamic() && package->id && package->id.value() != res_id.package_id()) { if (res_id.is_valid() && package->id && package->id.value() != res_id.package_id()) { diag->Error(DiagMessage(source) << "trying to add resource '" << name << "' with ID " << res_id << " but package '" << package->name << "' already has ID " Loading @@ -513,9 +513,9 @@ bool ResourceTable::SetVisibilityImpl(const ResourceNameRef& name, const Visibil } // Whether or not to error on duplicate resources bool check_id = validate_resources_ && res_id.is_valid_dynamic(); bool check_id = validate_resources_ && res_id.is_valid(); // Whether or not to create a duplicate resource if the id does not match bool use_id = !validate_resources_ && res_id.is_valid_dynamic(); bool use_id = !validate_resources_ && res_id.is_valid(); ResourceTableType* type = package->FindOrCreateType(name.type, use_id ? res_id.type_id() : Maybe<uint8_t>()); Loading @@ -541,7 +541,7 @@ bool ResourceTable::SetVisibilityImpl(const ResourceNameRef& name, const Visibil return false; } if (res_id.is_valid_dynamic()) { if (res_id.is_valid()) { package->id = res_id.package_id(); type->id = res_id.type_id(); entry->id = res_id.entry_id(); Loading
tools/aapt2/ResourceUtils.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -516,7 +516,7 @@ Maybe<ResourceId> ParseResourceId(const StringPiece& str) { if (android::ResTable::stringToInt(str16.data(), str16.size(), &value)) { if (value.dataType == android::Res_value::TYPE_INT_HEX) { ResourceId id(value.data); if (id.is_valid_dynamic()) { if (id.is_valid()) { return id; } } Loading
tools/aapt2/ResourceValues.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ bool Reference::Equals(const Value* value) const { bool Reference::Flatten(android::Res_value* out_value) const { const ResourceId resid = id.value_or_default(ResourceId(0)); const bool dynamic = resid.is_valid_dynamic() && is_dynamic; const bool dynamic = resid.is_valid() && is_dynamic; if (reference_type == Reference::Type::kResource) { if (dynamic) { Loading Loading @@ -159,7 +159,7 @@ void Reference::Print(std::ostream* out) const { *out << name.value(); } if (id && id.value().is_valid_dynamic()) { if (id && id.value().is_valid()) { if (name) { *out << " "; } Loading Loading @@ -196,7 +196,7 @@ static void PrettyPrintReferenceImpl(const Reference& ref, bool print_package, P printer->Print("/"); printer->Print(name.entry); } } else if (ref.id && ref.id.value().is_valid_dynamic()) { } else if (ref.id && ref.id.value().is_valid()) { printer->Print(ref.id.value().to_string()); } } Loading
tools/aapt2/process/SymbolTable.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -340,7 +340,7 @@ std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName( } res_id = asset_manager_.GetResourceId(real_name.to_string()); if (res_id.is_valid() && asset_manager_.GetResourceFlags(res_id.id, &type_spec_flags)) { if (res_id.is_valid_static() && asset_manager_.GetResourceFlags(res_id.id, &type_spec_flags)) { found = true; return false; } Loading Loading @@ -379,7 +379,7 @@ static Maybe<ResourceName> GetResourceName(android::AssetManager2& am, std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById( ResourceId id) { if (!id.is_valid()) { if (!id.is_valid_static()) { // Exit early and avoid the error logs from AssetManager. return {}; } Loading