summaryrefslogtreecommitdiff
path: root/cmds/idmap2/tests/IdmapTests.cpp
Commit message (Collapse)AuthorAgeFilesLines
* idmap2: Remove more redundant "using" statementsYi Kong2022-02-201-1/+0
| | | | | | Test: presubmit Bug: 219872355 Change-Id: I74e5b38400060477f9d50b51b1f261ec6a181dd1
* idmap2: fix cpplint warningsMårten Kongstad2021-06-021-2/+2
| | | | | | Bug: 189963636 Test: frameworks/base/cmds/idmap2/static-checks.sh Change-Id: I6da18cdbbd2fc33db711696445230a9f316dc143
* Add fabricated RRO generation to libidmap2Ryan Mitchell2021-02-091-69/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fail idmap parsing earlier if version differsRyan Mitchell2021-01-131-16/+24
| | | | | | | | | | | | | Variable length strings are now in the idmap format. Idmap attempts to parse the old idmap files using the new format and can interpret old data as the length of a variable length string. Fail parsing idmap header early if the idmap magic or version differs from what is expected. Bug: 177295273 Test: boot, apply change, reboot Change-Id: I2914f11547424457fdb78de0ad03976e1fc81084
* Accept --overlay-name flag in idmap2Ryan Mitchell2021-01-061-90/+142
| | | | | | | | | | | | | | | | | | 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
* Remove idmap path 256 length limitRyan Mitchell2021-01-061-71/+43
| | | | | | | | | | | | | Overlay and target package paths can be longer than 256 characters. Currently, the idmap will fail to be generated if either path is longer than 256 characters. This change removes the 256 character limit and makes parsing variable length strings easier in libandroidfw. Bug: 174676094 Test: idmap2_tests && libandroidfw_tests Change-Id: Ic240cdb8700566b2ac2ade08da58bea852e4ae0c
* Remove malloc/free for inline overlay valuesRyan Mitchell2020-10-141-49/+65
| | | | | | | | | | | | | | | | | | Remove malloc/free of android::ResTable_entry for inline overlay values. Add `target_entry_inline` to the idmap format to encode inline overlay values separate from direct mapping of target resource to overlay resource. This reduces the number of bytes needed to represent a direct mapping of target resource to overlay resource from 9 bytes to 8 bytes per entry. Fixed all idmap alignment issues that required the framework to use "#pragma pack(push, 1)" when loading idmaps. Bug: 170341022 Test: idmap2_tests and libandroidfw_tests Change-Id: Iab4d3902508f02773464724913e0ee966e3689e4
* Add policies and enforce overlayable to headerRyan Mitchell2020-06-011-18/+56
| | | | | | | | | | | | | | | If the fulfilled policies change without the contents of the target and overlay APKs changing, the idmap for the overlay should be regenerated. This change adds fulfilled policies and enforce overlayable to the idmap header so that idmap2d can determine if the polices or enforce overlayable changed from what was used to generate the idmap. Bug: 119328308 Test: idmap2_tests Test: atest RegenerateIdmapTest Change-Id: I96f970e82b5243be01b205ac2cb6ab249c6100bc
* Actor signature overlayable policyWinson2020-02-261-8/+16
| | | | | | | | | | | | | | | | | | There are cases where an app can ship overlays for itself, but the "signature" policy as described would open up a vulnerability by allowing the system actor to create and sign any arbitrary overlay that will apply to the target. To prevent this, redefine "signature" as target package only, and introduce "actor" for checking against the actor signature. Any app that wishes to use both can include both policies. Bug: 130563563 Test: m aapt2_tests idmapt2_tests and run from host test output Test: atest libandroidfw_tests Change-Id: I1c583a5b37f4abbeb18fc6a35c502377d8977a41
* Refactor overlayable policyWinson2020-02-261-26/+34
| | | | | | | | | | | | | | | | | | | | To make it easier to add the actor policy in a follow up CL, move most of the policy handling to a central location. The strings and transformation between strings and flags is now handled in libidmap2policies, with libandroidfw containing the single source of policy flags. This also extracts all the test resource IDs into an R.h so they can be swapped without having to edit a dozen files each time. Bug: 130563563 Test: m aapt2_tests idmapt2_tests and run from host test output Test: atest libandroidfw_tests Change-Id: Ie533c9cebf938215df7586f00c38763ae467e606
* Fix resourcesMap to work with shared librariesRyan Mitchell2020-02-061-0/+37
| | | | | | | | | | 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
* idmap2: add debug information to idmap file formatMårten Kongstad2019-12-191-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a new variable length string to the idmap file format. This string will hold debug information like fulfilled policies and any warnings triggered while generating the file. Bump the idmap version to 3. Adjust the idmap header definition in ResourceType.h to take the new string into account. Example debug info: $ idmap2 create \ --target-apk-path frameworks/base/cmds/idmap2/tests/data/target/target.apk \ --overlay-apk-path frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk \ --idmap-path /tmp/a.idmap \ --policy public \ --policy oem $ idmap2 dump --idmap-path /tmp/a.idmap target apk path : frameworks/base/cmds/idmap2/tests/data/target/target.apk overlay apk path : frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk I fulfilled_policies=oem|public enforce_overlayable=true W failed to find resource "integer/not_in_target" in target resources 0x7f010000 -> 0x7f010000 integer/int1 0x7f02000c -> 0x7f020000 string/str1 [...] $ idmap2 dump --idmap-path /tmp/a.idmap --verbose 00000000: 504d4449 magic 00000004: 00000003 version 00000008: 76a20829 target crc 0000000c: c054fb26 overlay crc 00000010: ........ target path: frameworks/base/cmds/idmap2/tests/data/target/target.apk 00000110: ........ overlay path: frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk 00000210: ........ debug info: ... 00000294: 7f target package id 00000295: 7f overlay package id [...] Also, tell cpplint to accept non-const references as function parameters: they make more sense as out-parameters than pointers that are assumed to be non-null. Also, switch to regular expressions in the RawPrintVisitorTests: no more manual fixups of the stream offsets! Tell cpplint that the <regex> header is OK to use. Bug: 140790707 Test: idmap2_tests Change-Id: Ib94684a3b4001240321801e21af8e132fbcf6609
* Allow for RRO internal referencingRyan Mitchell2019-10-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | This change allows RROs to reference their own internal resources as expected. Overlays are loaded as shared libraries so they can have their own resource id space that does not conflict with the resource id space of the target or other overlays. References to overlay resources that override target resources now appear as references to the target resources. Overlay values that are inlined into the xml file specified using android:overlayResources are now able to be used at runtime. See go/rro-references for more information. Bug: 135943783 Test: idmap2_tests Test: libandroidfw_tests Change-Id: Ie349c56d7fd3f7d94b7d595ed6d01dc6b59b6178
* Idmap format changes for bidirectional lookupRyan Mitchell2019-10-171-327/+148
| | | | | | | | | | | | | | | | | | 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-8/+5
| | | | | | | | | | | | | | | 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
* Add odm and oem policiesRyan Mitchell2019-04-171-24/+37
| | | | | | | | | This change adds parsing, encoding, and validating of odm and oem overlayable policies to aapt2, libandroidfw, and idmap2. Bug: 121033532 Test: aapt2_tests, idmap2_tests Change-Id: Ifc0d4b6c9f9c37e06b2988abade69dbb277c50c2
* Run idmap2 static-checks and fix formatting issuesRyan Mitchell2019-04-151-7/+3
| | | | | | Bug: 130324774 Test: builds Change-Id: I2cf9d3aa268ffe38e525fadee9d81fc6aefe19b1
* idmap2: move Idmap.h to ResultMårten Kongstad2019-03-201-22/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change the signatures of Idmap::FromApkAssets and Idmap::FromBinaryStream from std::unique_ptr<const Idmap> func(..., std::ostream& out_error); to Result<std::unique_ptr<const Idmap>> func(...); The returned pointer is still a unique pointer to ensure the dynamically allocated memory is automatically released when no longer used. This means that using the returned value of either function requires one of two patterns: const auto idmap = func(...); if (!idmap) { return Error(...); } (*idmap)->accept(...); or auto result = func(...); if (!result) { return Error(...); } const auto idmap = std::move(*result); idmap->accept(...); Note that in the second example, result must be non-const or the call to std::move(*result) will not compile. With this change, the entire idmap2 project has been converted to use Result. Test: make idmap2_tests Change-Id: I533f4e03b99645523d94dd5f446ad76fb435f661
* idmap2: move commands to Result<Unit>Mårten Kongstad2019-03-191-7/+7
| | | | | | | | | | | | | | Change the signature of the idmap2 commands (Create, Dump, ...) to return Result<Unit> instead of bool. This removes the need to pass in an ostream for error messages: instead, those messages are part of the returned Result. Consolidate error messages: texts in Error objects should not be prefixed with "error:", that is the responsibility of the outer-most caller (i.e. main()). Test: make idmap2_tests Change-Id: I074881b3d1982ea8f4be5752161ac74b14fcba95
* Revert "Revert "Enforce a default policy on packages without <overlayable>""Ryan Mitchell2019-03-071-156/+118
| | | | | | | This reverts commit 6ce5b00f2ac8307ab8cce1deb79e1e39d8b1b8b7. Bug: 127835630 Test: manual and idmap2_tests
* Revert "Enforce a default policy on packages without <overlayable>"Ryan Mitchell2019-03-071-118/+156
| | | | | | | | This reverts commit 48945224bdc298630c76befdb50a31838bdafd8e. Reason for revert: <b/127835630> Change-Id: I0bc90c26e5b7d6b4d94704a2a1f92bbc889c025c
* Enforce a default policy on packages without <overlayable>Ryan Mitchell2019-03-071-156/+118
| | | | | | | | | | | | | In order to lift the signature/preinstalled install restrictions on overlays, we must protect packages that have not migrated to <overlayable> from being overlaid. If a resources is not specified as overlayable and the overlay does not define an <overlayable>, require the overlay to be preinstalled or signed with the same signature as the target. Bug: 121016681 Bug: 125933494 Test: idmap2_tests Change-Id: I38f520929031b743e4bbe0366a9be55aac5795c5
* idmap2: switch to improved Result classMårten Kongstad2019-02-271-12/+14
| | | | | | | | 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
* idmap2: add signature policyWinson2019-02-151-17/+85
| | | | | | | | | | Handles the new signature policy for overlayable resources. Bug: 119402606 Test: idmap2_tests target Change-Id: I7961e04a879c40c240ed9097bb510addb8b56680
* idmap2: include AndroidManifest.xml in CRCsMårten Kongstad2019-02-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | The CRCs stored in the idmap file header are copies of the zip file CRC for the resources.arsc entry in the target and overlay package apks, and are used to quickly check if either package's contents has changed, which in turn means the idmap file must be recreated. With the introduction of named targets, just checking the resources.arsc file is no longer sufficient: an overlay package could be installed with targetName="a" and updated to targetName="b". This change is not reflected in the resources.arsc file, only in the AndroidManifest.xml. To account for this, update the CRC in the idmap file header from CRC(resources.arsc) to CRC(resources.arsc) ^ CRC(AndroidManifest.xml) Test: make idmap2_tests Bug: 119761809 Change-Id: Ieb0c6b466ac23eb81a2670a32309fa46ade5c5c8
* Enforce overlayable API when definedRyan Mitchell2019-02-051-11/+96
| | | | | | | | | If a package defines overlayable resources, then do not allow resources that are not defined as overlayable to be overlaid. Bug:123600120 Test: idmap2_tests and cts-tradefed run cts -m CtsRROTestCases Change-Id: I35120a97ccf4650e67c7ba65a60f4f3c51b0e627
* Add enforcement of overlayable targetNameRyan Mitchell2019-01-181-13/+15
| | | | | | | | | | | | | | | 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
* Add enforcement of idmap policiesMårten Kongstad2019-01-161-6/+123
| | | | | | | | | | | | | | Teaches idmap2 to recognize policy restrictions put on overlayable resources. If overlayable enforcement is turned on for an overlay, then any resources defined within the overlayable api of the target will have policy restrictions imposed on them. All resources without overlayable definitions will continue to be overlayable without policy restrictions. Bug: 119390857 Test: atest idmap2 and booting Co-authored-by: Ryan Mitchell <rtmitchell@google.com> Change-Id: I7e435648eb6e4a87b0b90a7b2a0c3f33c1516ea6
* idmap2: fix clang-tidy warnings [modernize-*]Mårten Kongstad2018-12-211-9/+7
| | | | | | Bug: 120024673 Test: mmm frameworks/base/cmds/idmap2; check output Change-Id: I8768169fb7b541eb6b1aa3311c46a710eb71aac9
* idmap2: fix clang-tidy warnings [readability-*]Mårten Kongstad2018-12-201-68/+68
| | | | | | Bug: 120024673 Test: mmm frameworks/base/cmds/idmap2; check output Change-Id: I1565afac8d34e4347d8c946228d1134211e8b435
* idmap2: initial code dropMårten Kongstad2018-10-301-0/+395
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