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

Commit 30dc2e01 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Accept --overlay-name flag in idmap2

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
parent 0699f1de
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -29,8 +29,8 @@ using android::idmap2::Result;
using android::idmap2::Unit;

Result<Unit> Verify(const std::string& idmap_path, const std::string& target_path,
                    const std::string& overlay_path, PolicyBitmask fulfilled_policies,
                    bool enforce_overlayable) {
                    const std::string& overlay_path, const std::string& overlay_name,
                    PolicyBitmask fulfilled_policies, bool enforce_overlayable) {
  SYSTRACE << "Verify " << idmap_path;
  std::ifstream fin(idmap_path);
  const std::unique_ptr<const IdmapHeader> header = IdmapHeader::FromBinaryStream(fin);
@@ -39,8 +39,8 @@ Result<Unit> Verify(const std::string& idmap_path, const std::string& target_pat
    return Error("failed to parse idmap header");
  }

  const auto header_ok =
      header->IsUpToDate(target_path, overlay_path, fulfilled_policies, enforce_overlayable);
  const auto header_ok = header->IsUpToDate(target_path, overlay_path, overlay_name,
                                            fulfilled_policies, enforce_overlayable);
  if (!header_ok) {
    return Error(header_ok.GetError(), "idmap not up to date");
  }
+3 −5
Original line number Diff line number Diff line
@@ -20,10 +20,8 @@
#include "idmap2/PolicyUtils.h"
#include "idmap2/Result.h"

android::idmap2::Result<android::idmap2::Unit> Verify(const std::string& idmap_path,
                                                      const std::string& target_path,
                                                      const std::string& overlay_path,
                                                      PolicyBitmask fulfilled_policies,
                                                      bool enforce_overlayable);
android::idmap2::Result<android::idmap2::Unit> Verify(
    const std::string& idmap_path, const std::string& target_path, const std::string& overlay_path,
    const std::string& overlay_name, PolicyBitmask fulfilled_policies, bool enforce_overlayable);

#endif  // IDMAP2_IDMAP2_COMMAND_UTILS_H_
+6 −3
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ Result<Unit> Create(const std::vector<std::string>& args) {
  std::string target_apk_path;
  std::string overlay_apk_path;
  std::string idmap_path;
  std::string overlay_name;
  std::vector<std::string> policies;
  bool ignore_overlayable = false;

@@ -62,9 +63,11 @@ Result<Unit> Create(const std::vector<std::string>& args) {
                           "input: path to apk which contains the new resource values",
                           &overlay_apk_path)
          .MandatoryOption("--idmap-path", "output: path to where to write idmap file", &idmap_path)
          .OptionalOption("--overlay-name", "input: the value of android:name of the overlay",
                          &overlay_name)
          .OptionalOption("--policy",
                          "input: an overlayable policy this overlay fulfills "
                          "(if none or supplied, the overlay policy will default to \"public\")",
                          "(if none are supplied, the overlay policy will default to \"public\")",
                          &policies)
          .OptionalFlag("--ignore-overlayable", "disables overlayable and policy checks",
                        &ignore_overlayable);
@@ -100,8 +103,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, *overlay_apk, fulfilled_policies, !ignore_overlayable);
  const auto idmap = Idmap::FromApkAssets(*target_apk, *overlay_apk, overlay_name,
                                          fulfilled_policies, !ignore_overlayable);
  if (!idmap) {
    return Error(idmap.GetError(), "failed to create idmap");
  }
+4 −3
Original line number Diff line number Diff line
@@ -105,7 +105,8 @@ Result<Unit> CreateMultiple(const std::vector<std::string>& args) {
      continue;
    }

    if (!Verify(idmap_path, target_apk_path, overlay_apk_path, fulfilled_policies,
    // TODO(b/175014391): Support multiple overlay tags in OverlayConfig
    if (!Verify(idmap_path, target_apk_path, overlay_apk_path, "", fulfilled_policies,
                !ignore_overlayable)) {
      const std::unique_ptr<const ApkAssets> overlay_apk = ApkAssets::Load(overlay_apk_path);
      if (!overlay_apk) {
@@ -113,8 +114,8 @@ Result<Unit> CreateMultiple(const std::vector<std::string>& args) {
        continue;
      }

      const auto idmap =
          Idmap::FromApkAssets(*target_apk, *overlay_apk, fulfilled_policies, !ignore_overlayable);
      const auto idmap = Idmap::FromApkAssets(*target_apk, *overlay_apk, "", fulfilled_policies,
                                              !ignore_overlayable);
      if (!idmap) {
        LOG(WARNING) << "failed to create idmap";
        continue;
+3 −3
Original line number Diff line number Diff line
@@ -195,12 +195,12 @@ Result<Unit> Lookup(const std::vector<std::string>& args) {
      }
      apk_assets.push_back(std::move(target_apk));

      auto manifest_info =
          ExtractOverlayManifestInfo(idmap_header->GetOverlayPath(), true /* assert_overlay */);
      auto manifest_info = ExtractOverlayManifestInfo(idmap_header->GetOverlayPath(),
                                                      idmap_header->GetOverlayName());
      if (!manifest_info) {
        return manifest_info.GetError();
      }
      target_package_name = (*manifest_info).target_package;
      target_package_name = manifest_info->target_package;
    } else if (target_path != idmap_header->GetTargetPath()) {
      return Error("different target APKs (expected target APK %s but %s has target APK %s)",
                   target_path.c_str(), idmap_path.c_str(), idmap_header->GetTargetPath().c_str());
Loading