summaryrefslogtreecommitdiff
path: root/cmds/idmap2/idmap2d/Idmap2Service.cpp
AgeCommit message (Collapse)Author
2021-07-19Use binder-based iterator to retrieve FRROsRyan Mitchell
If for some reason there are a lot of fabricated overlays in the resources cache, the binder limit of the list of fabricated overlay infos could exceed the maximum binder transaction size. Rather than return all of the frro infos in one transactions, register an iterator with the native idmap2d service and use multiple binder transactions to iterate through all of the frros. Bug: 192948522 Test: Toggle device theme colors several times and observe frro cache Reboot device and observe old frros are deleted Change-Id: I5e9cf3ae9d1d45eda683c24141a0cd4e4301e02f
2021-06-02idmap2: fix cpplint warningsMårten Kongstad
Bug: 189963636 Test: frameworks/base/cmds/idmap2/static-checks.sh Change-Id: I6da18cdbbd2fc33db711696445230a9f316dc143
2021-06-02OMS: include idmap data in dumpMårten Kongstad
Teach the overlay manager to ask the idmap service to pretty print the contents of each idmap file as part of OMS dump. This creates a single entry point for dumping both OMS and idmap data, and circumvents the problem of accessing the idmap service if it has been killed due to inactivity. Example idmap section: ---- 8< ---- IDMAP OF com.android.theme.color.sand Paths: target path : /system/framework/framework-res.apk overlay path : /product/overlay/AccentColorSand/AccentColorSandOverlay.apk Debug info: W failed to find resource 'string/accent_color_overlay' Mapping: 0x0106006e -> 0x7f010000 (color/accent_device_default_dark -> color/accent_device_default_dark) 0x01060070 -> 0x7f010001 (color/accent_device_default_light -> color/accent_device_default_light) ---- >8 ---- Bug: 189963636 Test: adb exec-out dumpsys Test: adb exec-out cmd overlay dump Test: adb exec-out cmd overlay dump <overlay-identifier> Change-Id: I9de6ba646ad4714c9d0f0d8081fbf632577107e7
2021-06-02idmap2: create in-memory FRRO before creating fileMårten Kongstad
Re-order the serialization of an FRRO and creation of the backing file. This prevents a dangling (empty) file if the serialization fails. Bug: 189963636 Test: manual: cmd overlay fabricate <bad parameters>, verify no file created in /data/resource-cache Change-Id: I1af88c6d2d1c3a881beecfb50ccaf541a249f39b
2021-02-10Always delete old idmap in createIdmapRyan Mitchell
If the target package updates its policies, and the overlay fails to successfully overlay any resources, the overlay should no longer work anymore. By deleting the old idmap file at the beginning of Idmap2Service::createIdmap, the overlay state will change to STATE_NO_IDMAP if the new idmap cannot be successfully generated. Bug: 173032050 Test: manual Change-Id: I1915e65feeb801d8602c12cc7df0f90da4c9b5c5
2021-02-09OverlayManager Fabricated RROsRyan Mitchell
Adds registering and unregistering of FabricatedOverlay to the OMS. The process that creates the fabricated overlays owns it and is the only process allowed to unregister it. When a fabricated overlay is registered, overlay settings for it are initialized in all users. When a fabricated overlay is unregistered, it is disabled and removed from all users. When a new user is created, it will be able to use the fabricated overlay as well. On boot, fabricated overlays that are not referenced in overlay settings will be deleted. When the package that created the fabricated overlay is uninstalled, its fabricated overlays are also unregistered. Bug: 172471315 Test: atest OverlayDeviceTests Change-Id: I0539656f4c919246b13129579b0286c08a398dc2
2021-02-09Add fabricated RRO generation to libidmap2Ryan Mitchell
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
2021-01-06Accept --overlay-name flag in idmap2Ryan Mitchell
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
2021-01-06Remove idmap path 256 length limitRyan Mitchell
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
2020-08-10Switch aidl::nullable to std::optionalJooyung Han
AIDL's @nullable is represented as std::optional in C++ backend. The previous aidl::nullable was a temporary solution to avoid merge-conflicts between rvc-dev and master branches. Bug: 151275535 Test: m Change-Id: I8fe5bfc1763087e7ff364b4408f862436492d1db
2020-06-10Merge "idmap2: Set aidl_return to true on success" into rvc-dev am: 6700d5e48cTreeHugger Robot
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11795074 Change-Id: I2d0cb691028bd264675625610eda332aed8d19f9
2020-06-09idmap2: Set aidl_return to true on successRyan Mitchell
idmap2d did not set the aidl return value to true when IdmapHeader::IsUpToDate succeeded. This regressed OMS initialization time. This change sets aidl_return to true when the header is up-to-date and also replaces usages of `uint32_t` for fulfilled_policies with `PolicyBitmask`. Bug: 158491243 Bug: 158535227 Bug: 158468195 Test: enable/disable overlays and onserve that verify succeeds Test: change the values of enforce overlayable and fulfilled policies and confirm that idmap verify fails Change-Id: If8febbfd0283d53211263690f85e2970706a33b7
2020-06-05Merge "Add policies and enforce overlayable to header" into rvc-dev am: ↵Ryan Mitchell
2201f8b626 Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11481145 Change-Id: I71ff9f46e1e5a5016291a062dd5389078527588f
2020-06-01Add policies and enforce overlayable to headerRyan Mitchell
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
2020-04-28Merge "Reduce OMS start time" into rvc-dev am: 84a84ac62aRyan Mitchell
Change-Id: I9a419e6be7cc950693e39c5d474e3c60161c4b69
2020-04-28Reduce OMS start timeRyan Mitchell
This change attempts to reduce the amount of time initializing the OMS. The change: 1) Reduces the amount of time between subsequent attempts to connect to the idmap2d service when it is not alive. 2) Caches package infos retrieved from getOverlayPackages 3) Caches the crc of the android package to preventing having to retrieve it for every overlay package targeting the framework This chance reduced OMS start up time from ~500ms to ~100ms on a Pixel 3. If the idmap2d service is running when system sever starts then start up time will be around ~70ms. Bug: 151481016 Test: adb shell stop && adb shell start && [capture trace] Change-Id: I6137c385baf099413b62e98557419fffb9fd2d93
2020-04-10Merge changes from topic "invalidate_idmap" into rvc-dev am: 6cb79cdfb7Ryan Mitchell
Change-Id: Iec3d0e3bab28964442c5aada00c2586e284feb92
2020-04-07Invalidate idmap when target updatesRyan Mitchell
When the target package update, check if the idmap file must change. If so, propagate the idmap changes to the targets overlay paths, and invalidate cached overlay ApkAssets in ResourcesManager. Bug: 147794117 Bug: 150877400 Test: OverlayRemountedTest Test: libandroidfw_tests Change-Id: I6115c30bae3672b188a5ff270720a0eea15b43b5
2020-03-30Merge "Consider target path when verifyIdmap." into rvc-dev am: fa0f02a91cRyan Mitchell
Change-Id: Iad2e29a73f4b7b11c84fa30fd376a5d25e3c197c
2020-03-26Consider target path when verifyIdmap.hg.choi
Updating new version package with changing resource id, Overlay idmap still retain same resource id and target path of prebuilt package. Consequentially overlay can not apply to new update resource id. As is : VerifyIdmap only verify uptodate of idmap. To be : Verify change of target path. Bug: 147794117 Bug: 150877400 Test: idmap2_tests Change-Id: I2ed6b5ba49aeb1b24625866daefea56c9766baef
2020-03-12Use aidl::nullable for nullable type in C++Jooyung Han
To reduce the discrepance between old code which still uses std::unique_ptr and new code using std::optional. This might help to avoid merge-conflicts between branches. Bug: 144773267 Test: m Merged-In: Ie3196ee5cce17d77950eea9479d2cc1406e9e674 Merged-In: I33822bc76ef87637d5408849f64a0607e121792e Change-Id: I33822bc76ef87637d5408849f64a0607e121792e (cherry picked from commit ad62e8cbf5cf6083568f6f230ef7d73ad8776971) Exempt-From-Owner-Approval: cherry-pick from master with owner's approval
2020-03-12Use aidl::nullable for nullable type in C++Jooyung Han
To reduce the discrepance between old code which still uses std::unique_ptr and new code using std::optional. This might help to avoid merge-conflicts between branches. Bug: 144773267 Test: m (cherry picked from commit ad62e8cbf5cf6083568f6f230ef7d73ad8776971) Change-Id: Ie3196ee5cce17d77950eea9479d2cc1406e9e674 Merged-In: I33822bc76ef87637d5408849f64a0607e121792e Exempt-From-Owner-Approval: approved from master
2020-03-12Revert "Use aidl::nullable for nullable type in C++"Jooyung Han
Revert submission 10632869-nullable-compat-rvc-dev-plus-aosp Reason for revert: incorrect merged-in line Reverted Changes: I33822bc76:Use aidl::nullable for nullable type in C++ I378dbf848:Add aidl::nullable type for nullable in AIDL Change-Id: I98d4041770fe97b622aaaf8c829b97259bd82e2c Exempt-From-Owner-Approval: revert wrong submission
2020-03-12Use aidl::nullable for nullable type in C++Jooyung Han
To reduce the discrepance between old code which still uses std::unique_ptr and new code using std::optional. This might help to avoid merge-conflicts between branches. Bug: 144773267 Test: m Merged-In I33822bc76ef87637d5408849f64a0607e121792e Change-Id: I33822bc76ef87637d5408849f64a0607e121792e (cherry picked from commit ad62e8cbf5cf6083568f6f230ef7d73ad8776971) Exempt-From-Owner-Approval: cherry-pick from master
2020-02-27Merge changes from topic "actor-signature-policy-rvc-dev" into rvc-dev am: ↵Automerger Merge Worker
b0c5105b2d Change-Id: I55a362a896901a09fc1bf49f9129455d53b2d440
2020-02-26Refactor overlayable policyWinson
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
2020-02-26Use optional for nullable typesJooyung Han
AIDL generates optional<T> for nullable T types for C++, which is more efficient and idomatic and easy to use. Bug: 144773267 Test: build/flash/boot Merged-In: I90cf2ce1193c479179687d71a5c1416f6cdf0b16 Change-Id: I90cf2ce1193c479179687d71a5c1416f6cdf0b16 (cherry picked from commit 53be7f4db497a05256407bd4c499a8fafc8e095d) Exempt-From-Owner-Approval: CP from master
2019-10-04Parse <overlay> and abstract resource mappingRyan Mitchell
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
2019-04-15Run idmap2 static-checks and fix formatting issuesRyan Mitchell
Bug: 130324774 Test: builds Change-Id: I2cf9d3aa268ffe38e525fadee9d81fc6aefe19b1
2019-03-20idmap2: move Idmap.h to ResultMårten Kongstad
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
2019-03-19idmap2: move commands to Result<Unit>Mårten Kongstad
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
2019-02-27idmap2: switch to improved Result classMårten Kongstad
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
2019-02-08idmap2: add systrace logsMårten Kongstad
Thanks to the ART team for art/libartbase/base/systrace.h which served as inspiration for the SYSTRACE macro. Bug: 119761810 Test: run idmap2_tests on device while capturing systrace Change-Id: I81112ae8e58daf20ebed33ef8b0f5a0caa4dbc73
2019-01-18idmap2: lock down write access to /data/resouce-cacheMårten Kongstad
Deny write access to /data/resource-cache for UIDs other than root and system. While this is already handled by SELinux rules, add an additional layer of security to explicitly prevent malicious apps from messing with the system's idmap files. Test: make idmap2_tests Change-Id: Id986633558d5d02452276f05f64337a8700f148a
2019-01-16Add enforcement of idmap policiesMårten Kongstad
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
2018-12-21idmap2: fix clang-tidy warnings [modernize-*]Mårten Kongstad
Bug: 120024673 Test: mmm frameworks/base/cmds/idmap2; check output Change-Id: I8768169fb7b541eb6b1aa3311c46a710eb71aac9
2018-12-20idmap2: fix clang-tidy warnings [readability-*]Mårten Kongstad
Bug: 120024673 Test: mmm frameworks/base/cmds/idmap2; check output Change-Id: I1565afac8d34e4347d8c946228d1134211e8b435
2018-12-17OMS: extract verifyIdmap from createIdmapMårten Kongstad
For clarity, split IIdmap2::createIdmap into two separate functions: - IIdmap2::verifyIdmap [check if an existing idmap file is OK to use] - IIdmap2::createIdmap [unconditionally (re)create an idmap file] Teach the IdmapManager to call verifyIdmap and to proceed with createIdmap only if actually needed. Test: atest OverlayDeviceTests OverlayHostTests Change-Id: I9f6f1192011fcb094adffeca1eb3f709520bbd24
2018-10-30idmap2: initial code dropMårten Kongstad
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