summaryrefslogtreecommitdiff
path: root/libs/androidfw/Idmap.cpp
diff options
context:
space:
mode:
author Biswarup Pal <biswarupp@google.com> 2025-01-31 13:09:44 +0000
committer Biswarup Pal <biswarupp@google.com> 2025-02-06 17:48:20 +0000
commitb1608a954f53515c90b500b93b5164b3365d6c55 (patch)
tree9191f1dc6805569345ebecd18ec3b2845faecb13 /libs/androidfw/Idmap.cpp
parent3dcc45555519cc0a27c313bbb0fa251d7ae750ac (diff)
Add constraints for enabling RROs
This change introduces hidden API's for setting constraints for enabling RROs. Currently, the constraints are of the following types: 1. Display id constraint: This can be set for a RRO if the RRO is desired to be applied on only the apps running on that specific display. 2. Device id constraint: This can be set for a RRO if the RRO is desired to be applied on only the apps running on that specific device (for apps running on the default device, this would be Context#DEVICE_ID_DEFAULT, and for apps running on a virtual device, this would be the id of the virtual device). An overlay would be enabled when any of the given constraints are met. Constraints can only be set while enabling a RRO. Re-enabling a RRO with different constraints updates the constraints for the RRO. This change facilitates the writing of the constraints for RROs into the correspodning idmap files, and also persists them as part of the settings used by OverlayManagerService. The filtering of resource overlays based on constraints during resource resolution will be done in a follow-up CL. Test: atest FrameworksServicesTests Test: atest idmap2_tests Test: atest libandroidfw_tests Test: atest CtsResourcesTestCases Bug: 371801644 Flag: android.content.res.rro_constraints Change-Id: I0cad58bfb5b9b90105e2ef839c58147b9a50767c
Diffstat (limited to 'libs/androidfw/Idmap.cpp')
-rw-r--r--libs/androidfw/Idmap.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/libs/androidfw/Idmap.cpp b/libs/androidfw/Idmap.cpp
index 3ecd82b074a1..095be57a5dc8 100644
--- a/libs/androidfw/Idmap.cpp
+++ b/libs/androidfw/Idmap.cpp
@@ -55,6 +55,13 @@ struct Idmap_header {
// without having to read/store each header entry separately.
};
+struct Idmap_constraint {
+ // Constraint type can be TYPE_DISPLAY_ID or TYP_DEVICE_ID, please refer
+ // to ConstraintType in OverlayConstraint.java
+ uint32_t constraint_type;
+ uint32_t constraint_value;
+};
+
struct Idmap_data_header {
uint32_t target_entry_count;
uint32_t target_inline_entry_count;
@@ -254,13 +261,18 @@ std::optional<std::string_view> ReadString(const uint8_t** in_out_data_ptr, size
#endif
LoadedIdmap::LoadedIdmap(const std::string& idmap_path, const Idmap_header* header,
- const Idmap_data_header* data_header, Idmap_target_entries target_entries,
+ const Idmap_constraint* constraints,
+ uint32_t constraints_count,
+ const Idmap_data_header* data_header,
+ Idmap_target_entries target_entries,
Idmap_target_inline_entries target_inline_entries,
const Idmap_target_entry_inline_value* inline_entry_values,
const ConfigDescription* configs, Idmap_overlay_entries overlay_entries,
std::unique_ptr<ResStringPool>&& string_pool,
std::string_view overlay_apk_path, std::string_view target_apk_path)
: header_(header),
+ constraints_(constraints),
+ constraints_count_(constraints_count),
data_header_(data_header),
target_entries_(target_entries),
target_inline_entries_(target_inline_entries),
@@ -298,9 +310,9 @@ std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPie
return {};
}
std::optional<std::string_view> target_path = ReadString(&data_ptr, &data_size, "target path");
- if (!target_path) {
- return {};
- }
+ if (!target_path) {
+ return {};
+ }
std::optional<std::string_view> overlay_path = ReadString(&data_ptr, &data_size, "overlay path");
if (!overlay_path) {
return {};
@@ -310,6 +322,17 @@ std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPie
return {};
}
+ auto constraints_count = ReadType<uint32_t>(&data_ptr, &data_size, "constraints count");
+ if (!constraints_count) {
+ return {};
+ }
+ auto constraints = *constraints_count > 0 ?
+ ReadType<Idmap_constraint>(&data_ptr, &data_size, "constraints", *constraints_count)
+ : nullptr;
+ if (*constraints_count > 0 && !constraints) {
+ return {};
+ }
+
// Parse the idmap data blocks. Currently idmap2 can only generate one data block.
auto data_header = ReadType<Idmap_data_header>(&data_ptr, &data_size, "data header");
if (data_header == nullptr) {
@@ -376,9 +399,10 @@ std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPie
// Can't use make_unique because LoadedIdmap constructor is private.
return std::unique_ptr<LoadedIdmap>(
- new LoadedIdmap(std::string(idmap_path), header, data_header, target_entries,
- target_inline_entries, target_inline_entry_values, configurations,
- overlay_entries, std::move(idmap_string_pool), *overlay_path, *target_path));
+ new LoadedIdmap(std::string(idmap_path), header, constraints, *constraints_count,
+ data_header, target_entries, target_inline_entries,
+ target_inline_entry_values,configurations, overlay_entries,
+ std::move(idmap_string_pool),*overlay_path, *target_path));
}
bool LoadedIdmap::IsUpToDate() const {