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

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

Merge changes I1740dcdc,I12f965b5

* changes:
  Parse <overlay> and abstract resource mapping
  Improve idmap2 xml parsing
parents 98bfc275 9e4f52b2
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
  }
+4 −2
Original line number Diff line number Diff line
@@ -43,9 +43,10 @@ cc_library {
        "libidmap2/Policies.cpp",
        "libidmap2/PrettyPrintVisitor.cpp",
        "libidmap2/RawPrintVisitor.cpp",
        "libidmap2/ResourceMapping.cpp",
        "libidmap2/ResourceUtils.cpp",
        "libidmap2/Result.cpp",
        "libidmap2/Xml.cpp",
        "libidmap2/XmlParser.cpp",
        "libidmap2/ZipFile.cpp",
    ],
    export_include_dirs: ["include"],
@@ -97,9 +98,10 @@ cc_test {
        "tests/PoliciesTests.cpp",
        "tests/PrettyPrintVisitorTests.cpp",
        "tests/RawPrintVisitorTests.cpp",
        "tests/ResourceMappingTests.cpp",
        "tests/ResourceUtilsTests.cpp",
        "tests/ResultTests.cpp",
        "tests/XmlTests.cpp",
        "tests/XmlParserTests.cpp",
        "tests/ZipFileTests.cpp",
    ],
    required: [
+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");
  }
+8 −31
Original line number Diff line number Diff line
@@ -33,9 +33,10 @@
#include "androidfw/Util.h"
#include "idmap2/CommandLineOptions.h"
#include "idmap2/Idmap.h"
#include "idmap2/ResourceUtils.h"
#include "idmap2/Result.h"
#include "idmap2/SysTrace.h"
#include "idmap2/Xml.h"
#include "idmap2/XmlParser.h"
#include "idmap2/ZipFile.h"
#include "utils/String16.h"
#include "utils/String8.h"
@@ -57,8 +58,7 @@ using android::idmap2::IdmapHeader;
using android::idmap2::ResourceId;
using android::idmap2::Result;
using android::idmap2::Unit;
using android::idmap2::Xml;
using android::idmap2::ZipFile;
using android::idmap2::utils::ExtractOverlayManifestInfo;
using android::util::Utf16ToUtf8;

namespace {
@@ -132,29 +132,6 @@ Result<std::string> WARN_UNUSED GetValue(const AssetManager2& am, ResourceId res
  return out;
}

Result<std::string> GetTargetPackageNameFromManifest(const std::string& apk_path) {
  const auto zip = ZipFile::Open(apk_path);
  if (!zip) {
    return Error("failed to open %s as zip", apk_path.c_str());
  }
  const auto entry = zip->Uncompress("AndroidManifest.xml");
  if (!entry) {
    return Error("failed to uncompress AndroidManifest.xml in %s", apk_path.c_str());
  }
  const auto xml = Xml::Create(entry->buf, entry->size);
  if (!xml) {
    return Error("failed to create XML buffer");
  }
  const auto tag = xml->FindTag("overlay");
  if (!tag) {
    return Error("failed to find <overlay> tag");
  }
  const auto iter = tag->find("targetPackage");
  if (iter == tag->end()) {
    return Error("failed to find targetPackage attribute");
  }
  return iter->second;
}
}  // namespace

Result<Unit> Lookup(const std::vector<std::string>& args) {
@@ -202,12 +179,12 @@ Result<Unit> Lookup(const std::vector<std::string>& args) {
      }
      apk_assets.push_back(std::move(target_apk));

      const Result<std::string> package_name =
          GetTargetPackageNameFromManifest(idmap_header->GetOverlayPath().to_string());
      if (!package_name) {
        return Error("failed to parse android:targetPackage from overlay manifest");
      auto manifest_info = ExtractOverlayManifestInfo(idmap_header->GetOverlayPath().to_string(),
                                                      true /* assert_overlay */);
      if (!manifest_info) {
        return manifest_info.GetError();
      }
      target_package_name = *package_name;
      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(),
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
#include "idmap2/ResourceUtils.h"
#include "idmap2/Result.h"
#include "idmap2/SysTrace.h"
#include "idmap2/Xml.h"
#include "idmap2/XmlParser.h"
#include "idmap2/ZipFile.h"

using android::idmap2::CommandLineOptions;
Loading