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

Commit 8a891d86 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Allow for RRO internal referencing

This change allows RROs to reference their own internal resources as
expected.

Overlays are loaded as shared libraries so they can have their own
resource id space that does not conflict with the resource id space of
the target or other overlays.

References to overlay resources that override target resources now
appear as references to the target resources.

Overlay values that are inlined into the xml file specified using
android:overlayResources are now able to be used at runtime.

See go/rro-references for more information.

Bug: 135943783
Test: idmap2_tests
Test: libandroidfw_tests
Change-Id: Ie349c56d7fd3f7d94b7d595ed6d01dc6b59b6178
parent e753ffef
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -88,8 +88,4 @@ TEST(BinaryStreamVisitorTests, CreateBinaryStreamViaBinaryStreamVisitor) {
  ASSERT_EQ(overlay_entries1[2].target_id, overlay_entries2[2].target_id);
}

TEST(BinaryStreamVisitorTests, CreateIdmapFromApkAssetsInteropWithLoadedIdmap) {
  // TODO(135943783): Removed temporarily until libandroidfw idmap loading is fixed.
}

}  // namespace android::idmap2
+48 −1
Original line number Diff line number Diff line
@@ -280,7 +280,54 @@ TEST_F(Idmap2BinaryTests, Scan) {
}

TEST_F(Idmap2BinaryTests, Lookup) {
  // TODO(135943783): Removed temporarily until libandroidfw idmap loading is fixed.
  SKIP_TEST_IF_CANT_EXEC_IDMAP2;

  // clang-format off
  auto result = ExecuteBinary({"idmap2",
                               "create",
                               "--target-apk-path", GetTargetApkPath(),
                               "--overlay-apk-path", GetOverlayApkPath(),
                               "--idmap-path", GetIdmapPath()});
  // clang-format on
  ASSERT_THAT(result, NotNull());
  ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr;

  // clang-format off
  result = ExecuteBinary({"idmap2",
                          "lookup",
                          "--idmap-path", GetIdmapPath(),
                          "--config", "",
                          "--resid", "0x7f02000c"});  // string/str1
  // clang-format on
  ASSERT_THAT(result, NotNull());
  ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr;
  ASSERT_NE(result->stdout.find("overlay-1"), std::string::npos);
  ASSERT_EQ(result->stdout.find("overlay-1-sv"), std::string::npos);

  // clang-format off
  result = ExecuteBinary({"idmap2",
                          "lookup",
                          "--idmap-path", GetIdmapPath(),
                          "--config", "",
                          "--resid", "test.target:string/str1"});
  // clang-format on
  ASSERT_THAT(result, NotNull());
  ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr;
  ASSERT_NE(result->stdout.find("overlay-1"), std::string::npos);
  ASSERT_EQ(result->stdout.find("overlay-1-sv"), std::string::npos);

  // clang-format off
  result = ExecuteBinary({"idmap2",
                          "lookup",
                          "--idmap-path", GetIdmapPath(),
                          "--config", "sv",
                          "--resid", "test.target:string/str1"});
  // clang-format on
  ASSERT_THAT(result, NotNull());
  ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr;
  ASSERT_NE(result->stdout.find("overlay-1-sv"), std::string::npos);

  unlink(GetIdmapPath().c_str());
}

TEST_F(Idmap2BinaryTests, InvalidCommandLineOptions) {
+2 −2
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ TEST(IdmapTests, CreateIdmapDataDoNotRewriteNonOverlayResourceId) {
  OverlayManifestInfo info{};
  info.target_package = "test.target";
  info.target_name = "TestResources";
  info.resource_mapping = 0x7f030002;  // xml/overlays_different_packages
  info.resource_mapping = 0x7f030001;  // xml/overlays_different_packages
  auto idmap_data = TestIdmapDataFromApkAssets("/target/target.apk", "/overlay/overlay.apk", info,
                                               PolicyFlags::POLICY_PUBLIC,
                                               /* enforce_overlayable */ false);
@@ -272,7 +272,7 @@ TEST(IdmapTests, CreateIdmapDataInlineResources) {
  OverlayManifestInfo info{};
  info.target_package = "test.target";
  info.target_name = "TestResources";
  info.resource_mapping = 0x7f030000;  // xml/overlays_inline
  info.resource_mapping = 0x7f030002;  // xml/overlays_inline
  auto idmap_data = TestIdmapDataFromApkAssets("/target/target.apk", "/overlay/overlay.apk", info,
                                               PolicyFlags::POLICY_PUBLIC,
                                               /* enforce_overlayable */ false);
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ TEST(RawPrintVisitorTests, CreateRawPrintVisitor) {
  ASSERT_NE(stream.str().find("00000000: 504d4449  magic\n"), std::string::npos);
  ASSERT_NE(stream.str().find("00000004: 00000002  version\n"), std::string::npos);
  ASSERT_NE(stream.str().find("00000008: 76a20829  target crc\n"), std::string::npos);
  ASSERT_NE(stream.str().find("0000000c: e3c188b6  overlay crc\n"), std::string::npos);
  ASSERT_NE(stream.str().find("0000000c: c054fb26  overlay crc\n"), std::string::npos);
  ASSERT_NE(stream.str().find("00000210:       7f  target package id\n"), std::string::npos);
  ASSERT_NE(stream.str().find("00000211:       7f  overlay package id\n"), std::string::npos);
  ASSERT_NE(stream.str().find("00000212: 00000004  target entry count\n"), std::string::npos);
+8 −4
Original line number Diff line number Diff line
@@ -750,9 +750,11 @@ static jlong NativeOpenXmlAsset(JNIEnv* env, jobject /*clazz*/, jlong ptr, jint
  }

  // May be nullptr.
  const DynamicRefTable* dynamic_ref_table = assetmanager->GetDynamicRefTableForCookie(cookie);
  std::shared_ptr<const DynamicRefTable> dynamic_ref_table =
      assetmanager->GetDynamicRefTableForCookie(cookie);

  std::unique_ptr<ResXMLTree> xml_tree = util::make_unique<ResXMLTree>(dynamic_ref_table);
  std::unique_ptr<ResXMLTree> xml_tree = util::make_unique<ResXMLTree>(
      std::move(dynamic_ref_table));
  status_t err = xml_tree->setTo(asset->getBuffer(true), asset->getLength(), true);
  asset.reset();

@@ -785,9 +787,11 @@ static jlong NativeOpenXmlAssetFd(JNIEnv* env, jobject /*clazz*/, jlong ptr, int
  ApkAssetsCookie cookie = JavaCookieToApkAssetsCookie(jcookie);

  // May be nullptr.
  const DynamicRefTable* dynamic_ref_table = assetmanager->GetDynamicRefTableForCookie(cookie);
   std::shared_ptr<const DynamicRefTable> dynamic_ref_table =
       assetmanager->GetDynamicRefTableForCookie(cookie);

  std::unique_ptr<ResXMLTree> xml_tree = util::make_unique<ResXMLTree>(dynamic_ref_table);
  std::unique_ptr<ResXMLTree> xml_tree = util::make_unique<ResXMLTree>(
      std::move(dynamic_ref_table));
  status_t err = xml_tree->setTo(asset->getBuffer(true), asset->getLength(), true);
  asset.reset();

Loading