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

Commit 3d91609e authored by Ryan Mitchell's avatar Ryan Mitchell Committed by Android (Google) Code Review
Browse files

Merge changes I09965e58,I02316d0b,Ic240cdb8

* changes:
  Read manifest values using resource id in idmap2
  Accept --overlay-name flag in idmap2
  Remove idmap path 256 length limit
parents d5d79830 fb4d09ca
Loading
Loading
Loading
Loading
+3 −3
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,7 +39,7 @@ 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.c_str(), overlay_path.c_str(),
  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;
+6 −8
Original line number Diff line number Diff line
@@ -188,29 +188,27 @@ Result<Unit> Lookup(const std::vector<std::string>& args) {
    }

    if (i == 0) {
      target_path = idmap_header->GetTargetPath().to_string();
      target_path = idmap_header->GetTargetPath();
      auto target_apk = ApkAssets::Load(target_path);
      if (!target_apk) {
        return Error("failed to read target apk from %s", target_path.c_str());
      }
      apk_assets.push_back(std::move(target_apk));

      auto manifest_info = ExtractOverlayManifestInfo(idmap_header->GetOverlayPath().to_string(),
                                                      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().to_string().c_str());
                   target_path.c_str(), idmap_path.c_str(), idmap_header->GetTargetPath().c_str());
    }

    auto overlay_apk = ApkAssets::LoadOverlay(idmap_path);
    if (!overlay_apk) {
      return Error("failed to read overlay apk from %s",
                   idmap_header->GetOverlayPath().to_string().c_str());
      return Error("failed to read overlay apk from %s", idmap_header->GetOverlayPath().c_str());
    }
    apk_assets.push_back(std::move(overlay_apk));
  }
Loading