summaryrefslogtreecommitdiff
path: root/cmds/idmap2/libidmap2/ResourceUtils.cpp
Commit message (Collapse)AuthorAgeFilesLines
* idmap2: fix cpplint warningsMårten Kongstad2021-06-021-0/+1
| | | | | | Bug: 189963636 Test: frameworks/base/cmds/idmap2/static-checks.sh Change-Id: I6da18cdbbd2fc33db711696445230a9f316dc143
* Add fabricated RRO generation to libidmap2Ryan Mitchell2021-02-091-78/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fabricated Runtime Resource Overlays are overlays that are generated at runtime and are stored in the data/ partition. The system can fabricate RROs at runtime to dynamically theme the device. Idmaps can now be created from APK RROs and fabricated RROs. Rather than operating on ApkAssets, libidmap2 now operates on abstract resource "containers" that supply resource values. Target resource containers implement methods needed to query overlayable and target overlay information. Currently only APKs can be loaded as target resource containers. Overlay resource containers implement methods to supply the mapping of target resource to overlay value and other overlay information. The format of a fabricated RRO is as follows: 0x00 - 0x04 : fabricated overlay magic (always FRRO) 0x04 - 0x08 : file format version 0x08 - 0x0c : crc of version + proto data 0x0c - EOF : proto fabricated overlay data The magic is used to quickly detect if the file is a fabricated overlay. The version is incremented whenever backwards incompatible changes are made to the proto file format. Idmap must always be able to upgrade fabricated overlays from previous versions to new versions, so all previous versions must be checked into the tree. Bug: 172471315 Test: libidmap2_tests && libandroidfw_tests Change-Id: I4c9f29da278672e5695fb57d131a44c11a835180
* Read manifest values using resource id in idmap2Ryan Mitchell2021-01-081-4/+10
| | | | | | | | | | | | | Idmap2 currently reads android:targetPackage and android:targetName from overlay manifests by looking for an attribute with the name of the attribute resource. This fixes the divergence from package parsing by finding the attributes using their resource ids. Bug: 175060836 Test: libidmap2_tests Change-Id: I09965e5880a1e6c48c3f8077db0c595484804ce7
* Accept --overlay-name flag in idmap2Ryan Mitchell2021-01-061-49/+33
| | | | | | | | | | | | | | | | | | To support allowing for multiple <overlay> tags in one package, idmap2 must be able to generate an idmap for an individual <overlay> tag. `idmap2 create` now accepts a --overlay-name flag that specifies which tag to use to generate the idmap. The value of --overlay-name should be set to the value of the android:name attribute on the <overlay> tag to use. If the flag is not present, idmap2 will look for an <overlay> tag with no value for android:name. Bug: 162841629 Test: libandroidfw_tests Test: libidmap2_tests Change-Id: I02316d0b88773f02c04a5d462be9825016fa496d
* Revert^2 "libandroidfw hardening for IncFs"Ryan Mitchell2020-11-171-8/+8
| | | | | | 55ef6167a2c235bd88c7216238b2001b46795b79 Change-Id: I02d4890d181655dfd0a14c188468db512559d27b
* Revert "libandroidfw hardening for IncFs"Ryan Mitchell2020-11-131-8/+8
| | | | | | | | | | | | | | | Revert "Move map_ptr to incfs namspace" Revert submission 12787270 Reason for revert: b/173250495 Reverted Changes: I5cd1bc8a2:libandroidfw hardening for IncFs Ice5dbcfb2:Move map_ptr to incfs namspace I29ccdc8ed:Do not cache bag parent stack until requested I1e9e9acaa:Cache resolved theme values Change-Id: Ib90ef68339710086df41e9abe0833a542d03a74f
* libandroidfw hardening for IncFsRyan Mitchell2020-11-121-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Migrate libandroifw to using incfs::util::map_ptr to prevent processes from crashing when parsing the resources.arsc, parsing compiled xml, files, and retrieving resource values. This change propagates incremental failures to the JNI level where they are raised as ResourcesNotFoundException. Performance of ResourcesPerfWorkloads without change (time in nanoseconds): [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.883s) youtube_ns_median: 93812805 youtube_ns_standardDeviation: 4387062 youtube_ns_mean: 94455597 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (11.265s) maps_ns_standardDeviation: 2997543 maps_ns_mean: 83480371 maps_ns_median: 82210941 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.963s) gmail_ns_median: 266141091 gmail_ns_standardDeviation: 3492043 gmail_ns_mean: 267472765 With change and verification forcibly enabled for all apks (including the framework-res.apk): [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.646s) youtube_ns_median: 101999396 youtube_ns_standardDeviation: 4625782 youtube_ns_mean: 102631770 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (11.286s) maps_ns_standardDeviation: 2692088 maps_ns_mean: 91326538 maps_ns_median: 90519884 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.694s) gmail_ns_median: 290284442 gmail_ns_standardDeviation: 5764632 gmail_ns_mean: 291660464 With change and verification disabled: [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.748s) youtube_ns_median: 95490747 youtube_ns_standardDeviation: 7282249 youtube_ns_mean: 98442515 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (10.862s) maps_ns_standardDeviation: 4484213 maps_ns_mean: 87912988 maps_ns_median: 86325549 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.034s) gmail_ns_median: 282175838 gmail_ns_standardDeviation: 6560876 gmail_ns_mean: 282869146 These tests were done on a Pixel 3 and with cpu settings configured by libs/hwui/tests/scripts/prep_generic.sh: Locked CPUs 4,5,6,7 to 1459200 / 2803200 KHz Disabled CPUs 0,1,2,3 Bug: 160635104 Bug: 169423204 Test: boot device && atest ResourcesPerfWorkloads Change-Id: I5cd1bc8a2257bffaba6ca4a1c96f4e6640106866
* Fix resourcesMap to work with shared librariesRyan Mitchell2020-02-061-1/+5
| | | | | | | | | | android:resourcesMap is not working at all with shared libraries. This change fixes that so overlays built as shared libraries can use the attribute. Bug: None Test: idmap2_tests Change-Id: I767481f88c58892a3818a919616056291b09b57e
* Idmap format changes for bidirectional lookupRyan Mitchell2019-10-171-1/+35
| | | | | | | | | | | | | | | | | | This change modifies the idmap file format to allow for target resources to map to arbitrary type/value combinations and to allow overlay resources to be mapped back to target resource ids so references to overlay resources can appear as references to target resources at runtime. The mappings of target resources to overlay resources and vice-versa are both encoded as sparse arrays. Instead of looking up a resource by indexing into an array that maps to the overlay resource id, the runtime will binary search over the sparse array to find the type and value that overlays the target resource. Bug: 135943783 Test: idmap2_tests Change-Id: I5d5344cdb7fe35f4f2e8d6781016299dea5d1e20
* Parse <overlay> and abstract resource mappingRyan Mitchell2019-10-041-6/+13
| | | | | | | | | | | | | | | This change introduces idmap parsing of <overlay> tags. The <overlay> tag allows one to explicitly map resources in the target to either a resource in the overlay or an inline attribute value. Use the android:resourcesMap atttribute on the <overlay> tag in the android manifest to specify a file to provide the resource mapping. Bug: 135943783 Bug: 135051420 Test: idmap2_tests Change-Id: I1740dcdc01849c43b1f2cb8c6645d666dbb05dba
* Improve idmap2 xml parsingRyan Mitchell2019-10-041-24/+37
| | | | | | | | | | | | | | | | | To parse the <overlay> tags for internal overlay references, we require the ability to parse XML. The current implementation only allows idmap2 to find a tag somewhere in an xml file. This implementation allows for the retrieval of an iterator that iterates over direct children xml elements. Now we can enforce that the <overlay> tag in the manifest is nested within the <manifest> tag and we can ensure <item> tags are within the <overlay> tags of the overlay resource configuration xml. Bug: 135051420 Bug: 135943783 Test: idmap2_tests Change-Id: I12f965b55c18960af6cf9dc6ca46429f53124c9a
* Merge "Revert "Improve idmap2 xml parsing""Ryan Mitchell2019-10-021-37/+24
|\
| * Revert "Improve idmap2 xml parsing"Ryan Mitchell2019-10-021-37/+24
| | | | | | | | | | | | | | | | This reverts commit 58cdc2a8226e8618331a81c1e1b77a4421bb5629. Reason for revert: <aosp/1129572 caused a build failure> Change-Id: Iecae19877dacf9ec5c2b2bc59dca362f573e9a7a
* | Merge "Add requiredSystemPropertyValue support in idmap2" am: b30f65713f am: ↵Ryan Mitchell2019-10-021-0/+10
|\ \ | |/ |/| | | | | | | | | | | fa9362aec9 am: b8a749dac6 am: 042900cf9a Change-Id: I8b7f30cc8088b4d04856358e7f1ffc18159b1b7f
| * Add requiredSystemPropertyValue support in idmap2Gabriel Siqueira2019-09-271-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up to Android P, there was this feature were we are able to define "requiredSystemPropertyValue" in the AndroidManifest.xml of the RRO apk, so that it will only be loaded if requiredSystemPropertyValue/requiredSystemPropertyName are matched. Porting support from idmap https://android.googlesource.com/platform/frameworks/base/+/master/cmds/idmap/scan.cpp#135 To idmap2 https://android.googlesource.com/platform/frameworks/base/+/master/cmds/idmap2/idmap2/Scan.cpp#175 Bug: 140891738 Change-Id: I47752af93efa4563a60e336c1e1b1ffc081b51ec
* | Improve idmap2 xml parsingRyan Mitchell2019-10-011-24/+37
|/ | | | | | | | | | | | | | | | | To parse the <overlay> tags for internal overlay references, we require the ability to parse XML. The current implementation only allows idmap2 to find a tag somewhere in an xml file. This implementation allows for the retrieval of an iterator that iterates over direct children xml elements. Now we can enforce that the <overlay> tag in the manifest is nested within the <manifest> tag and we can ensure <item> tags are within the <overlay> tags of the overlay resource configuration xml. Bug: 135051420 Bug: 135943783 Test: idmap2_tests Change-Id: I1a1c4329514eb63b7575c4376adc0d8cda217269
* Run idmap2 static-checks and fix formatting issuesRyan Mitchell2019-04-151-2/+2
| | | | | | Bug: 130324774 Test: builds Change-Id: I2cf9d3aa268ffe38e525fadee9d81fc6aefe19b1
* idmap2: switch to improved Result classMårten Kongstad2019-02-271-14/+8
| | | | | | | | Remove the old std::optional based Result class, replace uses with the new std::variant based Result class. Test: make idmap2_tests Change-Id: I401cb36e5af06133a2872d835cf29bfb0b106597
* Add enforcement of overlayable targetNameRyan Mitchell2019-01-181-0/+65
| | | | | | | | | | | | | | | Adds android:targetName to the overlay manifest attributes and PackageParser reads the name into PackageInfo. Specifying android:targetName on an overlay allows the overlay to be associated with a particular set of overlayable resources. The overlay can only override the values of the resources defined within the target overlayable element. Test: idmap2_tests Bug: 119390855 Bug: 110869880 Change-Id: I1128274af4cae983f61ae15cdfcbface63233ff2
* idmap2: fix clang-tidy warnings [modernize-*]Mårten Kongstad2018-12-211-6/+2
| | | | | | Bug: 120024673 Test: mmm frameworks/base/cmds/idmap2; check output Change-Id: I8768169fb7b541eb6b1aa3311c46a710eb71aac9
* idmap2: replace std::pair<bool, T> with Result<T>Mårten Kongstad2018-12-171-5/+4
| | | | | | | | | | | | | | | | | | | | | Introduce a new type Result<T> to indicate if an operation succeeded or not, and if it did, to hold the return value of the operation. This is the same as how std::pair<bool, T> is already used in the codebase, so replace all instances with Result<T> to improve clarity. Result<T> is simply an alias for std::optional<T>. The difference is semantic: use Result<T> as the return value for functions that can fail, use std::optional<T> when values are truly optional. This is modelled after Rust's std::result and std::option. A future change may graduate Result<T> to a proper class which can hold additional details on why an operation failed, such as a string or an error code. As a special case, continue to use std::unique_ptr<T> instead of Result<std::unique_ptr<T>> for now: the latter would increase code complexity without added benefit. Test: make idmap2_tests Change-Id: I2a8355107ed2b6485409e5e655a84cf1e20b9911
* idmap2: initial code dropMårten Kongstad2018-10-301-0/+55
idmap2 is a reboot of the idmap project. The project aims to - use modern C++ - greatly improve test and debug support - interface towards AssetManager2 (instead of AssetManager) - provide a solid foundation to add support for new features To make it easier to verify correctness, this first version of idmap2 is feature equivalent to idmap. Later versions will add support for new features such as <overlayable>. Bug: 78815803 Test: make idmap2_tests Change-Id: I1d806dc875a493e730ab55d2fdb027618e586d16