Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e4f52b2 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Parse <overlay> and abstract resource mapping

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
parent cd965a32
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -226,6 +226,7 @@ package android {
    field public static final int isVrOnly = 16844152; // 0x1010578
    field public static final int requiredSystemPropertyName = 16844133; // 0x1010565
    field public static final int requiredSystemPropertyValue = 16844134; // 0x1010566
    field public static final int resourcesMap = 16844297; // 0x1010609
    field public static final int supportsAmbientMode = 16844173; // 0x101058d
    field public static final int userRestriction = 16844164; // 0x1010584
  }
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ cc_library {
        "libidmap2/Policies.cpp",
        "libidmap2/PrettyPrintVisitor.cpp",
        "libidmap2/RawPrintVisitor.cpp",
        "libidmap2/ResourceMapping.cpp",
        "libidmap2/ResourceUtils.cpp",
        "libidmap2/Result.cpp",
        "libidmap2/XmlParser.cpp",
@@ -97,6 +98,7 @@ cc_test {
        "tests/PoliciesTests.cpp",
        "tests/PrettyPrintVisitorTests.cpp",
        "tests/RawPrintVisitorTests.cpp",
        "tests/ResourceMappingTests.cpp",
        "tests/ResourceUtilsTests.cpp",
        "tests/ResultTests.cpp",
        "tests/XmlParserTests.cpp",
+2 −2
Original line number Diff line number Diff line
@@ -99,8 +99,8 @@ Result<Unit> Create(const std::vector<std::string>& args) {
    return Error("failed to load apk %s", overlay_apk_path.c_str());
  }

  const auto idmap = Idmap::FromApkAssets(target_apk_path, *target_apk, overlay_apk_path,
                                          *overlay_apk, fulfilled_policies, !ignore_overlayable);
  const auto idmap =
      Idmap::FromApkAssets(*target_apk, *overlay_apk, fulfilled_policies, !ignore_overlayable);
  if (!idmap) {
    return Error(idmap.GetError(), "failed to create idmap");
  }
+2 −2
Original line number Diff line number Diff line
@@ -137,8 +137,8 @@ Status Idmap2Service::createIdmap(const std::string& target_apk_path,
    return error("failed to load apk " + overlay_apk_path);
  }

  const auto idmap = Idmap::FromApkAssets(target_apk_path, *target_apk, overlay_apk_path,
                                          *overlay_apk, policy_bitmask, enforce_overlayable);
  const auto idmap =
      Idmap::FromApkAssets(*target_apk, *overlay_apk, policy_bitmask, enforce_overlayable);
  if (!idmap) {
    return error(idmap.GetErrorMessage());
  }
+7 −12
Original line number Diff line number Diff line
@@ -56,20 +56,14 @@
#include "androidfw/ResourceTypes.h"
#include "androidfw/StringPiece.h"
#include "idmap2/Policies.h"
#include "idmap2/ResourceMapping.h"

namespace android::idmap2 {

class Idmap;
class Visitor;

// use typedefs to let the compiler warn us about implicit casts
typedef uint32_t ResourceId;  // 0xpptteeee
typedef uint8_t PackageId;    // pp in 0xpptteeee
typedef uint8_t TypeId;       // tt in 0xpptteeee
typedef uint16_t EntryId;     // eeee in 0xpptteeee

static constexpr const ResourceId kPadding = 0xffffffffu;

static constexpr const EntryId kNoEntry = 0xffffu;

// magic number: all idmap files start with this
@@ -155,7 +149,7 @@ class IdmapData {
    PackageId target_package_id_;
    uint16_t type_count_;

    friend Idmap;
    friend IdmapData;
    DISALLOW_COPY_AND_ASSIGN(Header);
  };

@@ -194,12 +188,15 @@ class IdmapData {
    uint16_t entry_offset_;
    std::vector<EntryId> entries_;

    friend Idmap;
    friend IdmapData;
    DISALLOW_COPY_AND_ASSIGN(TypeEntry);
  };

  static std::unique_ptr<const IdmapData> FromBinaryStream(std::istream& stream);

  static Result<std::unique_ptr<const IdmapData>> FromResourceMapping(
      const ResourceMapping& resource_mapping);

  inline const std::unique_ptr<const Header>& GetHeader() const {
    return header_;
  }
@@ -232,9 +229,7 @@ class Idmap {
  // file is used; change this in the next version of idmap to use a named
  // package instead; also update FromApkAssets to take additional parameters:
  // the target and overlay package names
  static Result<std::unique_ptr<const Idmap>> FromApkAssets(const std::string& target_apk_path,
                                                            const ApkAssets& target_apk_assets,
                                                            const std::string& overlay_apk_path,
  static Result<std::unique_ptr<const Idmap>> FromApkAssets(const ApkAssets& target_apk_assets,
                                                            const ApkAssets& overlay_apk_assets,
                                                            const PolicyBitmask& fulfilled_policies,
                                                            bool enforce_overlayable);
Loading