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

Commit 9db03589 authored by Rico Wind's avatar Rico Wind Committed by Android (Google) Code Review
Browse files

Merge "Add support for DynamicRefTable when serializing/deserializing proto"

parents 94b7000c e70bbb1e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -46,6 +46,13 @@ message ToolFingerprint {
  string version = 2;
}

// References to non local resources
message DynamicRefTable {
  PackageId package_id = 1;
  string package_name = 2;
}


// Top level message representing a resource table.
message ResourceTable {
  // The string pool containing source paths referenced throughout the resource table. This does
@@ -60,6 +67,8 @@ message ResourceTable {

  // The version fingerprints of the tools that built the resource table.
  repeated ToolFingerprint tool_fingerprint = 4;

  repeated DynamicRefTable dynamic_ref_table = 5;
}

// A package ID in the range [0x00, 0xff].
+5 −0
Original line number Diff line number Diff line
@@ -562,6 +562,11 @@ bool DeserializeTableFromPb(const pb::ResourceTable& pb_table, io::IFileCollecti
    }
  }

  for (const pb::DynamicRefTable& dynamic_ref : pb_table.dynamic_ref_table()) {
    out_table->included_packages_.insert(
        {dynamic_ref.package_id().id(), dynamic_ref.package_name()});
  }

  // Deserialize the overlayable groups of the table
  std::vector<std::shared_ptr<Overlayable>> overlayables;
  for (const pb::Overlayable& pb_overlayable : pb_table.overlayable()) {
+5 −1
Original line number Diff line number Diff line
@@ -345,7 +345,11 @@ void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table
  pb::ToolFingerprint* pb_fingerprint = out_table->add_tool_fingerprint();
  pb_fingerprint->set_tool(util::GetToolName());
  pb_fingerprint->set_version(util::GetToolFingerprint());

  for (auto it = table.included_packages_.begin(); it != table.included_packages_.end(); ++it) {
    pb::DynamicRefTable* pb_dynamic_ref = out_table->add_dynamic_ref_table();
    pb_dynamic_ref->mutable_package_id()->set_id(it->first);
    pb_dynamic_ref->set_package_name(it->second);
  }
  std::vector<Overlayable*> overlayables;
  auto table_view = table.GetPartitionedView();
  for (const auto& package : table_view.packages) {
+24 −0
Original line number Diff line number Diff line
@@ -1024,4 +1024,28 @@ TEST(ProtoSerializeTest, CustomResourceTypes) {
  EXPECT_THAT(*(custom_layout->path), Eq("res/layout/bar.xml"));
}

TEST(ProtoSerializeTest, SerializeDynamicRef) {
  std::unique_ptr<IAaptContext> context =
      test::ContextBuilder().SetCompilationPackage("app").SetPackageId(0x7f).Build();
  std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder().Build();
  table->included_packages_.insert({20, "foobar"});
  table->included_packages_.insert({30, "barfoo"});

  ResourceTable new_table;
  pb::ResourceTable pb_table;
  MockFileCollection files;
  std::string error;
  SerializeTableToPb(*table, &pb_table, context->GetDiagnostics());
  ASSERT_TRUE(DeserializeTableFromPb(pb_table, &files, &new_table, &error));
  EXPECT_THAT(error, IsEmpty());

  int result = new_table.included_packages_.size();
  EXPECT_THAT(result, Eq(2));
  auto it = new_table.included_packages_.begin();
  EXPECT_THAT(it->first, Eq(20));
  EXPECT_THAT(it->second, Eq("foobar"));
  it++;
  EXPECT_THAT(it->first, Eq(30));
  EXPECT_THAT(it->second, Eq("barfoo"));
}
}  // namespace aapt