AAPT2: Propagate SPEC_OVERLAYABLE flag to final APK
Resources can be marked as overlayable, which means they can
be overlaid by runtime resource overlays.
This change propagates this state to the final resource table that
is installed on device.
Future work:
- Have the idmap tool respect the overlayable state and ignore
entries that overlay anything else.
Bug: 64980941
Test: make aapt2_tests
Change-Id: Id45b1e141a281be2ee32a4ac3096fcf1114d523b
diff --git a/tools/aapt2/cmd/Diff.cpp b/tools/aapt2/cmd/Diff.cpp
index fc1f1d6..12113ed 100644
--- a/tools/aapt2/cmd/Diff.cpp
+++ b/tools/aapt2/cmd/Diff.cpp
@@ -75,14 +75,14 @@
std::cerr << source << ": " << message << "\n";
}
-static bool IsSymbolVisibilityDifferent(const Symbol& symbol_a, const Symbol& symbol_b) {
- return symbol_a.state != symbol_b.state;
+static bool IsSymbolVisibilityDifferent(const Visibility& vis_a, const Visibility& vis_b) {
+ return vis_a.level != vis_b.level;
}
template <typename Id>
-static bool IsIdDiff(const Symbol& symbol_a, const Maybe<Id>& id_a, const Symbol& symbol_b,
- const Maybe<Id>& id_b) {
- if (symbol_a.state == SymbolState::kPublic || symbol_b.state == SymbolState::kPublic) {
+static bool IsIdDiff(const Visibility::Level& level_a, const Maybe<Id>& id_a,
+ const Visibility::Level& level_b, const Maybe<Id>& id_b) {
+ if (level_a == Visibility::Level::kPublic || level_b == Visibility::Level::kPublic) {
return id_a != id_b;
}
return false;
@@ -157,17 +157,17 @@
EmitDiffLine(apk_b->GetSource(), str_stream.str());
diff = true;
} else {
- if (IsSymbolVisibilityDifferent(entry_a->symbol_status, entry_b->symbol_status)) {
+ if (IsSymbolVisibilityDifferent(entry_a->visibility, entry_b->visibility)) {
std::stringstream str_stream;
str_stream << pkg_a->name << ":" << type_a->type << "/" << entry_a->name
<< " has different visibility (";
- if (entry_b->symbol_status.state == SymbolState::kPublic) {
+ if (entry_b->visibility.level == Visibility::Level::kPublic) {
str_stream << "PUBLIC";
} else {
str_stream << "PRIVATE";
}
str_stream << " vs ";
- if (entry_a->symbol_status.state == SymbolState::kPublic) {
+ if (entry_a->visibility.level == Visibility::Level::kPublic) {
str_stream << "PUBLIC";
} else {
str_stream << "PRIVATE";
@@ -175,7 +175,7 @@
str_stream << ")";
EmitDiffLine(apk_b->GetSource(), str_stream.str());
diff = true;
- } else if (IsIdDiff(entry_a->symbol_status, entry_a->id, entry_b->symbol_status,
+ } else if (IsIdDiff(entry_a->visibility.level, entry_a->id, entry_b->visibility.level,
entry_b->id)) {
std::stringstream str_stream;
str_stream << pkg_a->name << ":" << type_a->type << "/" << entry_a->name
@@ -225,16 +225,16 @@
EmitDiffLine(apk_a->GetSource(), str_stream.str());
diff = true;
} else {
- if (IsSymbolVisibilityDifferent(type_a->symbol_status, type_b->symbol_status)) {
+ if (type_a->visibility_level != type_b->visibility_level) {
std::stringstream str_stream;
str_stream << pkg_a->name << ":" << type_a->type << " has different visibility (";
- if (type_b->symbol_status.state == SymbolState::kPublic) {
+ if (type_b->visibility_level == Visibility::Level::kPublic) {
str_stream << "PUBLIC";
} else {
str_stream << "PRIVATE";
}
str_stream << " vs ";
- if (type_a->symbol_status.state == SymbolState::kPublic) {
+ if (type_a->visibility_level == Visibility::Level::kPublic) {
str_stream << "PUBLIC";
} else {
str_stream << "PRIVATE";
@@ -242,7 +242,8 @@
str_stream << ")";
EmitDiffLine(apk_b->GetSource(), str_stream.str());
diff = true;
- } else if (IsIdDiff(type_a->symbol_status, type_a->id, type_b->symbol_status, type_b->id)) {
+ } else if (IsIdDiff(type_a->visibility_level, type_a->id, type_b->visibility_level,
+ type_b->id)) {
std::stringstream str_stream;
str_stream << pkg_a->name << ":" << type_a->type << " has different public ID (";
if (type_b->id) {
diff --git a/tools/aapt2/cmd/Dump.cpp b/tools/aapt2/cmd/Dump.cpp
index bc7f5a8..3d2fb55 100644
--- a/tools/aapt2/cmd/Dump.cpp
+++ b/tools/aapt2/cmd/Dump.cpp
@@ -69,15 +69,13 @@
printer->Println(StringPrintf("Data: offset=%" PRIi64 " length=%zd", offset, len));
}
-static bool TryDumpFile(IAaptContext* context, const std::string& file_path) {
+static bool TryDumpFile(IAaptContext* context, const std::string& file_path,
+ const DebugPrintTableOptions& print_options) {
// Use a smaller buffer so that there is less latency for dumping to stdout.
constexpr size_t kStdOutBufferSize = 1024u;
io::FileOutputStream fout(STDOUT_FILENO, kStdOutBufferSize);
Printer printer(&fout);
- DebugPrintTableOptions print_options;
- print_options.show_sources = true;
-
std::string err;
std::unique_ptr<io::ZipFileCollection> zip = io::ZipFileCollection::Create(file_path, &err);
if (zip) {
@@ -244,7 +242,12 @@
// Entry point for dump command.
int Dump(const std::vector<StringPiece>& args) {
bool verbose = false;
- Flags flags = Flags().OptionalSwitch("-v", "increase verbosity of output", &verbose);
+ bool no_values = false;
+ Flags flags = Flags()
+ .OptionalSwitch("--no-values",
+ "Suppresses output of values when displaying resource tables.",
+ &no_values)
+ .OptionalSwitch("-v", "increase verbosity of output", &verbose);
if (!flags.Parse("aapt2 dump", args, &std::cerr)) {
return 1;
}
@@ -252,8 +255,11 @@
DumpContext context;
context.SetVerbose(verbose);
+ DebugPrintTableOptions dump_table_options;
+ dump_table_options.show_sources = true;
+ dump_table_options.show_values = !no_values;
for (const std::string& arg : flags.GetArgs()) {
- if (!TryDumpFile(&context, arg)) {
+ if (!TryDumpFile(&context, arg, dump_table_options)) {
return 1;
}
}
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index d782de5..becbfc2 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -631,9 +631,9 @@
dst_path =
ResourceUtils::BuildResourceFileName(doc->file, context_->GetNameMangler());
- bool result = table->AddFileReferenceAllowMangled(doc->file.name, doc->file.config,
- doc->file.source, dst_path, nullptr,
- context_->GetDiagnostics());
+ bool result =
+ table->AddFileReferenceMangled(doc->file.name, doc->file.config, doc->file.source,
+ dst_path, nullptr, context_->GetDiagnostics());
if (!result) {
return false;
}
@@ -1343,9 +1343,9 @@
std::unique_ptr<Id> id = util::make_unique<Id>();
id->SetSource(source.WithLine(exported_symbol.line));
- bool result = final_table_.AddResourceAllowMangled(
- res_name, ConfigDescription::DefaultConfig(), std::string(), std::move(id),
- context_->GetDiagnostics());
+ bool result =
+ final_table_.AddResourceMangled(res_name, ConfigDescription::DefaultConfig(),
+ std::string(), std::move(id), context_->GetDiagnostics());
if (!result) {
return false;
}