From 62ac8b56a9f7cf75f3f0677ec37d8acb8def475c Mon Sep 17 00:00:00 2001 From: Winson Date: Wed, 4 Dec 2019 08:36:48 -0800 Subject: Refactor overlayable policy 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 --- tools/aapt2/Debug.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'tools/aapt2/Debug.cpp') diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp index 137fbd671865..1eb7d95f381a 100644 --- a/tools/aapt2/Debug.cpp +++ b/tools/aapt2/Debug.cpp @@ -32,10 +32,16 @@ #include "text/Printer.h" #include "util/Util.h" +#include "idmap2/Policies.h" + using ::aapt::text::Printer; using ::android::StringPiece; using ::android::base::StringPrintf; +using android::idmap2::policy::kPolicyStringToFlag; + +using PolicyFlags = android::ResTable_overlayable_policy_header::PolicyFlags; + namespace aapt { namespace { @@ -246,32 +252,25 @@ class ValueBodyPrinter : public ConstValueVisitor { Printer* printer_; }; -std::string OverlayablePoliciesToString(OverlayableItem::PolicyFlags policies) { - static const std::map kFlagToString = { - {OverlayableItem::kPublic, "public"}, - {OverlayableItem::kSystem, "system"}, - {OverlayableItem::kVendor, "vendor"}, - {OverlayableItem::kProduct, "product"}, - {OverlayableItem::kSignature, "signature"}, - {OverlayableItem::kOdm, "odm"}, - {OverlayableItem::kOem, "oem"}, - }; +std::string OverlayablePoliciesToString(PolicyFlags policies) { std::string str; - for (auto const& policy : kFlagToString) { - if ((policies & policy.first) != policy.first) { + + uint32_t remaining = policies; + for (auto const& policy : kPolicyStringToFlag) { + if ((policies & policy.second) != policy.second) { continue; } if (!str.empty()) { str.append("|"); } - str.append(policy.second); - policies &= ~policy.first; + str.append(policy.first.data()); + remaining &= ~policy.second; } - if (policies != 0) { + if (remaining != 0) { if (!str.empty()) { str.append("|"); } - str.append(StringPrintf("0x%08x", policies)); + str.append(StringPrintf("0x%08x", remaining)); } return !str.empty() ? str : "none"; } -- cgit v1.2.3-59-g8ed1b