Add fabricated RRO generation to libidmap2
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
diff --git a/cmds/idmap2/idmap2d/Idmap2Service.h b/cmds/idmap2/idmap2d/Idmap2Service.h
index 0127e87..869a4d9 100644
--- a/cmds/idmap2/idmap2d/Idmap2Service.h
+++ b/cmds/idmap2/idmap2d/Idmap2Service.h
@@ -18,12 +18,13 @@
#define IDMAP2_IDMAP2D_IDMAP2SERVICE_H_
#include <android-base/unique_fd.h>
+#include <android/os/BnIdmap2.h>
#include <binder/BinderService.h>
+#include <idmap2/ResourceContainer.h>
+#include <idmap2/Result.h>
#include <string>
-#include "android/os/BnIdmap2.h"
-
namespace android::os {
class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 {
@@ -32,27 +33,44 @@
return "idmap";
}
- binder::Status getIdmapPath(const std::string& overlay_apk_path, int32_t user_id,
+ binder::Status getIdmapPath(const std::string& overlay_path, int32_t user_id,
std::string* _aidl_return) override;
- binder::Status removeIdmap(const std::string& overlay_apk_path, int32_t user_id,
+ binder::Status removeIdmap(const std::string& overlay_path, int32_t user_id,
bool* _aidl_return) override;
- binder::Status verifyIdmap(const std::string& target_apk_path,
- const std::string& overlay_apk_path, int32_t fulfilled_policies,
- bool enforce_overlayable, int32_t user_id,
+ binder::Status verifyIdmap(const std::string& target_path, const std::string& overlay_path,
+ int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id,
bool* _aidl_return) override;
- binder::Status createIdmap(const std::string& target_apk_path,
- const std::string& overlay_apk_path, int32_t fulfilled_policies,
- bool enforce_overlayable, int32_t user_id,
+ binder::Status createIdmap(const std::string& target_path, const std::string& overlay_path,
+ int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id,
std::optional<std::string>* _aidl_return) override;
private:
- // Cache the crc of the android framework package since the crc cannot change without a reboot.
- std::optional<uint32_t> android_crc_;
+ // idmap2d is killed after a period of inactivity, so any information stored on this class should
+ // be able to be recalculated if idmap2 dies and restarts.
+ std::unique_ptr<idmap2::TargetResourceContainer> framework_apk_cache_;
+
+ template <typename T>
+ using MaybeUniquePtr = std::variant<std::unique_ptr<T>, T*>;
+
+ using TargetResourceContainerPtr = MaybeUniquePtr<idmap2::TargetResourceContainer>;
+ idmap2::Result<TargetResourceContainerPtr> GetTargetContainer(const std::string& target_path);
+
+ template <typename T>
+ WARN_UNUSED static const T* GetPointer(const MaybeUniquePtr<T>& ptr);
};
+template <typename T>
+const T* Idmap2Service::GetPointer(const MaybeUniquePtr<T>& ptr) {
+ auto u = std::get_if<T*>(&ptr);
+ if (u != nullptr) {
+ return *u;
+ }
+ return std::get<std::unique_ptr<T>>(ptr).get();
+}
+
} // namespace android::os
#endif // IDMAP2_IDMAP2D_IDMAP2SERVICE_H_