Move StringPool to libandroidfw
Test: verified affected tests pass
Bug: 232940948
Change-Id: I22089893d7e5013f759c39ce190bec07fa6435db
diff --git a/tools/aapt2/cmd/ApkInfo.cpp b/tools/aapt2/cmd/ApkInfo.cpp
index 7c9df4c..697b110 100644
--- a/tools/aapt2/cmd/ApkInfo.cpp
+++ b/tools/aapt2/cmd/ApkInfo.cpp
@@ -21,10 +21,10 @@
#include <iostream>
#include <memory>
-#include "Diagnostics.h"
#include "LoadedApk.h"
#include "android-base/file.h" // for O_BINARY
#include "android-base/utf8.h"
+#include "androidfw/IDiagnostics.h"
#include "androidfw/StringPiece.h"
#include "dump/DumpManifest.h"
#include "format/proto/ProtoSerialize.h"
@@ -35,7 +35,7 @@
int ExportApkInfo(LoadedApk* apk, bool include_resource_table,
const std::unordered_set<std::string>& xml_resources, pb::ApkInfo* out_apk_info,
- IDiagnostics* diag) {
+ android::IDiagnostics* diag) {
auto result = DumpBadgingProto(apk, out_apk_info->mutable_badging(), diag);
if (result != 0) {
return result;
@@ -74,14 +74,14 @@
int result =
ExportApkInfo(apk.get(), include_resource_table_, xml_resources_, &out_apk_info, diag_);
if (result != 0) {
- diag_->Error(DiagMessage() << "Failed to serialize ApkInfo into proto.");
+ diag_->Error(android::DiagMessage() << "Failed to serialize ApkInfo into proto.");
return result;
}
int mode = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
int outfd = ::android::base::utf8::open(output_path_.c_str(), mode, 0666);
if (outfd == -1) {
- diag_->Error(DiagMessage() << "Failed to open output file.");
+ diag_->Error(android::DiagMessage() << "Failed to open output file.");
return 1;
}
diff --git a/tools/aapt2/cmd/ApkInfo.h b/tools/aapt2/cmd/ApkInfo.h
index d682678..bb92a85 100644
--- a/tools/aapt2/cmd/ApkInfo.h
+++ b/tools/aapt2/cmd/ApkInfo.h
@@ -18,13 +18,13 @@
#define AAPT2_APKINFO_H
#include "Command.h"
-#include "Diagnostics.h"
+#include "androidfw/IDiagnostics.h"
namespace aapt {
class ApkInfoCommand : public Command {
public:
- explicit ApkInfoCommand(IDiagnostics* diag) : Command("apkinfo"), diag_(diag) {
+ explicit ApkInfoCommand(android::IDiagnostics* diag) : Command("apkinfo"), diag_(diag) {
SetDescription("Dump information about an APK in binary proto format.");
AddRequiredFlag("-o", "Output path", &output_path_, Command::kPath);
AddOptionalSwitch("--include-resource-table", "Include the resource table data into output.",
@@ -38,7 +38,7 @@
int Action(const std::vector<std::string>& args) override;
private:
- IDiagnostics* diag_;
+ android::IDiagnostics* diag_;
std::string output_path_;
bool include_resource_table_ = false;
std::unordered_set<std::string> xml_resources_;
diff --git a/tools/aapt2/cmd/ApkInfo_test.cpp b/tools/aapt2/cmd/ApkInfo_test.cpp
index 70539c0..97d4abe 100644
--- a/tools/aapt2/cmd/ApkInfo_test.cpp
+++ b/tools/aapt2/cmd/ApkInfo_test.cpp
@@ -43,12 +43,7 @@
EXPECT_EQ(produced_apk_info.DebugString(), expected);
}
-class NoopDiagnostics : public IDiagnostics {
- public:
- void Log(Level level, DiagMessageActual& actualMsg) override {
- }
-};
-static NoopDiagnostics noop_diag;
+static android::NoOpDiagnostics noop_diag;
TEST_F(ApkInfoTest, ApkInfoWithBadging) {
auto apk_path = file::BuildPath(
@@ -80,4 +75,4 @@
AssertProducedAndExpectedInfo(out_info_path, expected_path);
}
-} // namespace aapt
\ No newline at end of file
+} // namespace aapt
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index e27b9aa..0409f73 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -17,19 +17,17 @@
#include "Compile.h"
#include <dirent.h>
+
#include <string>
+#include "ResourceParser.h"
+#include "ResourceTable.h"
#include "android-base/errors.h"
#include "android-base/file.h"
#include "android-base/utf8.h"
#include "androidfw/ConfigDescription.h"
+#include "androidfw/IDiagnostics.h"
#include "androidfw/StringPiece.h"
-#include "google/protobuf/io/coded_stream.h"
-#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
-
-#include "Diagnostics.h"
-#include "ResourceParser.h"
-#include "ResourceTable.h"
#include "cmd/Util.h"
#include "compile/IdAssigner.h"
#include "compile/InlineXmlFormatParser.h"
@@ -39,6 +37,8 @@
#include "format/Archive.h"
#include "format/Container.h"
#include "format/proto/ProtoSerialize.h"
+#include "google/protobuf/io/coded_stream.h"
+#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "io/BigBufferStream.h"
#include "io/FileStream.h"
#include "io/FileSystem.h"
@@ -61,7 +61,7 @@
namespace aapt {
struct ResourcePathData {
- Source source;
+ android::Source source;
std::string resource_dir;
std::string name;
std::string extension;
@@ -122,9 +122,8 @@
}
}
- const Source res_path = options.source_path
- ? StringPiece(options.source_path.value())
- : StringPiece(path);
+ const android::Source res_path =
+ options.source_path ? StringPiece(options.source_path.value()) : StringPiece(path);
return ResourcePathData{res_path, dir_str.to_string(), name.to_string(),
extension.to_string(), config_str.to_string(), config};
@@ -154,8 +153,8 @@
{
auto fin = file->OpenInputStream();
if (fin->HadError()) {
- context->GetDiagnostics()->Error(DiagMessage(path_data.source)
- << "failed to open file: " << fin->GetError());
+ context->GetDiagnostics()->Error(android::DiagMessage(path_data.source)
+ << "failed to open file: " << fin->GetError());
return false;
}
@@ -191,7 +190,7 @@
// Create the file/zip entry.
if (!writer->StartEntry(output_path, 0)) {
- context->GetDiagnostics()->Error(DiagMessage(output_path) << "failed to open");
+ context->GetDiagnostics()->Error(android::DiagMessage(output_path) << "failed to open");
return false;
}
@@ -204,13 +203,13 @@
pb::ResourceTable pb_table;
SerializeTableToPb(table, &pb_table, context->GetDiagnostics());
if (!container_writer.AddResTableEntry(pb_table)) {
- context->GetDiagnostics()->Error(DiagMessage(output_path) << "failed to write");
+ context->GetDiagnostics()->Error(android::DiagMessage(output_path) << "failed to write");
return false;
}
}
if (!writer->FinishEntry()) {
- context->GetDiagnostics()->Error(DiagMessage(output_path) << "failed to finish entry");
+ context->GetDiagnostics()->Error(android::DiagMessage(output_path) << "failed to finish entry");
return false;
}
@@ -218,7 +217,7 @@
io::FileOutputStream fout_text(options.generate_text_symbols_path.value());
if (fout_text.HadError()) {
- context->GetDiagnostics()->Error(DiagMessage()
+ context->GetDiagnostics()->Error(android::DiagMessage()
<< "failed writing to'"
<< options.generate_text_symbols_path.value()
<< "': " << fout_text.GetError());
@@ -282,11 +281,11 @@
static bool WriteHeaderAndDataToWriter(const StringPiece& output_path, const ResourceFile& file,
io::KnownSizeInputStream* in, IArchiveWriter* writer,
- IDiagnostics* diag) {
+ android::IDiagnostics* diag) {
TRACE_CALL();
// Start the entry so we can write the header.
if (!writer->StartEntry(output_path, 0)) {
- diag->Error(DiagMessage(output_path) << "failed to open file");
+ diag->Error(android::DiagMessage(output_path) << "failed to open file");
return false;
}
@@ -300,20 +299,20 @@
SerializeCompiledFileToPb(file, &pb_compiled_file);
if (!container_writer.AddResFileEntry(pb_compiled_file, in)) {
- diag->Error(DiagMessage(output_path) << "failed to write entry data");
+ diag->Error(android::DiagMessage(output_path) << "failed to write entry data");
return false;
}
}
if (!writer->FinishEntry()) {
- diag->Error(DiagMessage(output_path) << "failed to finish writing data");
+ diag->Error(android::DiagMessage(output_path) << "failed to finish writing data");
return false;
}
return true;
}
static bool FlattenXmlToOutStream(const StringPiece& output_path, const xml::XmlResource& xmlres,
- ContainerWriter* container_writer, IDiagnostics* diag) {
+ ContainerWriter* container_writer, android::IDiagnostics* diag) {
pb::internal::CompiledFile pb_compiled_file;
SerializeCompiledFileToPb(xmlres.file, &pb_compiled_file);
@@ -324,7 +323,7 @@
io::StringInputStream serialized_in(serialized_xml);
if (!container_writer->AddResFileEntry(pb_compiled_file, &serialized_in)) {
- diag->Error(DiagMessage(output_path) << "failed to write entry data");
+ diag->Error(android::DiagMessage(output_path) << "failed to write entry data");
return false;
}
return true;
@@ -334,12 +333,12 @@
const file::FileType file_type = file::GetFileType(input_path);
if (file_type != file::FileType::kRegular && file_type != file::FileType::kSymlink) {
if (file_type == file::FileType::kDirectory) {
- context->GetDiagnostics()->Error(DiagMessage(input_path)
+ context->GetDiagnostics()->Error(android::DiagMessage(input_path)
<< "resource file cannot be a directory");
} else if (file_type == file::FileType::kNonExistant) {
- context->GetDiagnostics()->Error(DiagMessage(input_path) << "file not found");
+ context->GetDiagnostics()->Error(android::DiagMessage(input_path) << "file not found");
} else {
- context->GetDiagnostics()->Error(DiagMessage(input_path)
+ context->GetDiagnostics()->Error(android::DiagMessage(input_path)
<< "not a valid resource file");
}
return false;
@@ -352,14 +351,14 @@
const std::string& output_path) {
TRACE_CALL();
if (context->IsVerbose()) {
- context->GetDiagnostics()->Note(DiagMessage(path_data.source) << "compiling XML");
+ context->GetDiagnostics()->Note(android::DiagMessage(path_data.source) << "compiling XML");
}
std::unique_ptr<xml::XmlResource> xmlres;
{
auto fin = file->OpenInputStream();
if (fin->HadError()) {
- context->GetDiagnostics()->Error(DiagMessage(path_data.source)
+ context->GetDiagnostics()->Error(android::DiagMessage(path_data.source)
<< "failed to open file: " << fin->GetError());
return false;
}
@@ -389,7 +388,7 @@
// Start the entry so we can write the header.
if (!writer->StartEntry(output_path, 0)) {
- context->GetDiagnostics()->Error(DiagMessage(output_path) << "failed to open file");
+ context->GetDiagnostics()->Error(android::DiagMessage(output_path) << "failed to open file");
return false;
}
@@ -416,7 +415,8 @@
}
if (!writer->FinishEntry()) {
- context->GetDiagnostics()->Error(DiagMessage(output_path) << "failed to finish writing data");
+ context->GetDiagnostics()->Error(android::DiagMessage(output_path)
+ << "failed to finish writing data");
return false;
}
@@ -424,7 +424,7 @@
io::FileOutputStream fout_text(options.generate_text_symbols_path.value());
if (fout_text.HadError()) {
- context->GetDiagnostics()->Error(DiagMessage()
+ context->GetDiagnostics()->Error(android::DiagMessage()
<< "failed writing to'"
<< options.generate_text_symbols_path.value()
<< "': " << fout_text.GetError());
@@ -452,10 +452,10 @@
const std::string& output_path) {
TRACE_CALL();
if (context->IsVerbose()) {
- context->GetDiagnostics()->Note(DiagMessage(path_data.source) << "compiling PNG");
+ context->GetDiagnostics()->Note(android::DiagMessage(path_data.source) << "compiling PNG");
}
- BigBuffer buffer(4096);
+ android::BigBuffer buffer(4096);
ResourceFile res_file;
res_file.name = ResourceName({}, *ParseResourceType(path_data.resource_dir), path_data.name);
res_file.config = path_data.config;
@@ -465,11 +465,12 @@
{
auto data = file->OpenAsData();
if (!data) {
- context->GetDiagnostics()->Error(DiagMessage(path_data.source) << "failed to open file ");
+ context->GetDiagnostics()->Error(android::DiagMessage(path_data.source)
+ << "failed to open file ");
return false;
}
- BigBuffer crunched_png_buffer(4096);
+ android::BigBuffer crunched_png_buffer(4096);
io::BigBufferOutputStream crunched_png_buffer_out(&crunched_png_buffer);
// Ensure that we only keep the chunks we care about if we end up
@@ -486,7 +487,7 @@
std::string err;
nine_patch = NinePatch::Create(image->rows.get(), image->width, image->height, &err);
if (!nine_patch) {
- context->GetDiagnostics()->Error(DiagMessage() << err);
+ context->GetDiagnostics()->Error(android::DiagMessage() << err);
return false;
}
@@ -503,8 +504,8 @@
}
if (context->IsVerbose()) {
- context->GetDiagnostics()->Note(DiagMessage(path_data.source) << "9-patch: "
- << *nine_patch);
+ context->GetDiagnostics()->Note(android::DiagMessage(path_data.source)
+ << "9-patch: " << *nine_patch);
}
}
@@ -522,13 +523,13 @@
// The re-encoded PNG is larger than the original, and there is
// no mandatory transformation. Use the original.
if (context->IsVerbose()) {
- context->GetDiagnostics()->Note(DiagMessage(path_data.source)
+ context->GetDiagnostics()->Note(android::DiagMessage(path_data.source)
<< "original PNG is smaller than crunched PNG"
<< ", using original");
}
png_chunk_filter.Rewind();
- BigBuffer filtered_png_buffer(4096);
+ android::BigBuffer filtered_png_buffer(4096);
io::BigBufferOutputStream filtered_png_buffer_out(&filtered_png_buffer);
io::Copy(&filtered_png_buffer_out, &png_chunk_filter);
buffer.AppendBuffer(std::move(filtered_png_buffer));
@@ -538,13 +539,13 @@
// For debugging only, use the legacy PNG cruncher and compare the resulting file sizes.
// This will help catch exotic cases where the new code may generate larger PNGs.
std::stringstream legacy_stream(content.to_string());
- BigBuffer legacy_buffer(4096);
+ android::BigBuffer legacy_buffer(4096);
Png png(context->GetDiagnostics());
if (!png.process(path_data.source, &legacy_stream, &legacy_buffer, {})) {
return false;
}
- context->GetDiagnostics()->Note(DiagMessage(path_data.source)
+ context->GetDiagnostics()->Note(android::DiagMessage(path_data.source)
<< "legacy=" << legacy_buffer.size()
<< " new=" << buffer.size());
}
@@ -560,7 +561,7 @@
const std::string& output_path) {
TRACE_CALL();
if (context->IsVerbose()) {
- context->GetDiagnostics()->Note(DiagMessage(path_data.source) << "compiling file");
+ context->GetDiagnostics()->Note(android::DiagMessage(path_data.source) << "compiling file");
}
ResourceFile res_file;
@@ -571,7 +572,8 @@
auto data = file->OpenAsData();
if (!data) {
- context->GetDiagnostics()->Error(DiagMessage(path_data.source) << "failed to open file ");
+ context->GetDiagnostics()->Error(android::DiagMessage(path_data.source)
+ << "failed to open file ");
return false;
}
@@ -581,7 +583,7 @@
class CompileContext : public IAaptContext {
public:
- explicit CompileContext(IDiagnostics* diagnostics) : diagnostics_(diagnostics) {
+ explicit CompileContext(android::IDiagnostics* diagnostics) : diagnostics_(diagnostics) {
}
PackageType GetPackageType() override {
@@ -597,7 +599,7 @@
return verbose_;
}
- IDiagnostics* GetDiagnostics() override {
+ android::IDiagnostics* GetDiagnostics() override {
return diagnostics_;
}
@@ -633,7 +635,7 @@
private:
DISALLOW_COPY_AND_ASSIGN(CompileContext);
- IDiagnostics* diagnostics_;
+ android::IDiagnostics* diagnostics_;
bool verbose_ = false;
};
@@ -665,7 +667,7 @@
path, inputs->GetDirSeparator(), &err_str, options)) {
path_data = maybe_path_data.value();
} else {
- context->GetDiagnostics()->Error(DiagMessage(file->GetSource()) << err_str);
+ context->GetDiagnostics()->Error(android::DiagMessage(file->GetSource()) << err_str);
error = true;
continue;
}
@@ -688,8 +690,8 @@
}
}
} else {
- context->GetDiagnostics()->Error(DiagMessage()
- << "invalid file path '" << path_data.source << "'");
+ context->GetDiagnostics()->Error(android::DiagMessage()
+ << "invalid file path '" << path_data.source << "'");
error = true;
continue;
}
@@ -699,15 +701,16 @@
if (compile_func != &CompileFile && !options.legacy_mode
&& std::count(path_data.name.begin(), path_data.name.end(), '.') != 0) {
error = true;
- context->GetDiagnostics()->Error(DiagMessage(file->GetSource())
- << "file name cannot contain '.' other than for"
- << " specifying the extension");
+ context->GetDiagnostics()->Error(android::DiagMessage(file->GetSource())
+ << "file name cannot contain '.' other than for"
+ << " specifying the extension");
continue;
}
const std::string out_path = BuildIntermediateContainerFilename(path_data);
if (!compile_func(context, options, path_data, file, output_writer, out_path)) {
- context->GetDiagnostics()->Error(DiagMessage(file->GetSource()) << "file failed to compile");
+ context->GetDiagnostics()->Error(android::DiagMessage(file->GetSource())
+ << "file failed to compile");
error = true;
}
}
@@ -728,9 +731,10 @@
} else if (visibility_.value() == "default") {
options_.visibility = Visibility::Level::kUndefined;
} else {
- context.GetDiagnostics()->Error(
- DiagMessage() << "Unrecognized visibility level passes to --visibility: '"
- << visibility_.value() << "'. Accepted levels: public, private, default");
+ context.GetDiagnostics()->Error(android::DiagMessage()
+ << "Unrecognized visibility level passes to --visibility: '"
+ << visibility_.value()
+ << "'. Accepted levels: public, private, default");
return 1;
}
}
@@ -739,17 +743,17 @@
// Collect the resources files to compile
if (options_.res_dir && options_.res_zip) {
- context.GetDiagnostics()->Error(DiagMessage()
- << "only one of --dir and --zip can be specified");
+ context.GetDiagnostics()->Error(android::DiagMessage()
+ << "only one of --dir and --zip can be specified");
return 1;
} else if ((options_.res_dir || options_.res_zip) &&
options_.source_path && args.size() > 1) {
- context.GetDiagnostics()->Error(DiagMessage(kPath)
- << "Cannot use an overriding source path with multiple files.");
- return 1;
+ context.GetDiagnostics()->Error(android::DiagMessage(kPath)
+ << "Cannot use an overriding source path with multiple files.");
+ return 1;
} else if (options_.res_dir) {
if (!args.empty()) {
- context.GetDiagnostics()->Error(DiagMessage() << "files given but --dir specified");
+ context.GetDiagnostics()->Error(android::DiagMessage() << "files given but --dir specified");
Usage(&std::cerr);
return 1;
}
@@ -758,12 +762,12 @@
std::string err;
file_collection = io::FileCollection::Create(options_.res_dir.value(), &err);
if (!file_collection) {
- context.GetDiagnostics()->Error(DiagMessage(options_.res_dir.value()) << err);
+ context.GetDiagnostics()->Error(android::DiagMessage(options_.res_dir.value()) << err);
return 1;
}
} else if (options_.res_zip) {
if (!args.empty()) {
- context.GetDiagnostics()->Error(DiagMessage() << "files given but --zip specified");
+ context.GetDiagnostics()->Error(android::DiagMessage() << "files given but --zip specified");
Usage(&std::cerr);
return 1;
}
@@ -772,7 +776,7 @@
std::string err;
file_collection = io::ZipFileCollection::Create(options_.res_zip.value(), &err);
if (!file_collection) {
- context.GetDiagnostics()->Error(DiagMessage(options_.res_zip.value()) << err);
+ context.GetDiagnostics()->Error(android::DiagMessage(options_.res_zip.value()) << err);
return 1;
}
} else {
diff --git a/tools/aapt2/cmd/Compile.h b/tools/aapt2/cmd/Compile.h
index bd2e3d7..14a730a 100644
--- a/tools/aapt2/cmd/Compile.h
+++ b/tools/aapt2/cmd/Compile.h
@@ -17,15 +17,15 @@
#ifndef AAPT2_COMPILE_H
#define AAPT2_COMPILE_H
-#include <optional>
-
#include <androidfw/StringPiece.h>
+#include <optional>
+
+#include "Command.h"
+#include "ResourceTable.h"
+#include "androidfw/IDiagnostics.h"
#include "format/Archive.h"
#include "process/IResourceTableConsumer.h"
-#include "Command.h"
-#include "Diagnostics.h"
-#include "ResourceTable.h"
namespace aapt {
@@ -47,8 +47,8 @@
/** Parses flags and compiles resources to be used in linking. */
class CompileCommand : public Command {
public:
- explicit CompileCommand(IDiagnostics* diagnostic) : Command("compile", "c"),
- diagnostic_(diagnostic) {
+ explicit CompileCommand(android::IDiagnostics* diagnostic)
+ : Command("compile", "c"), diagnostic_(diagnostic) {
SetDescription("Compiles resources to be linked into an apk.");
AddRequiredFlag("-o", "Output path", &options_.output_path, Command::kPath);
AddOptionalFlag("--dir", "Directory to scan for resources", &options_.res_dir, Command::kPath);
@@ -81,7 +81,7 @@
int Action(const std::vector<std::string>& args) override;
private:
- IDiagnostics* diagnostic_;
+ android::IDiagnostics* diagnostic_;
CompileOptions options_;
std::optional<std::string> visibility_;
std::optional<std::string> trace_folder_;
diff --git a/tools/aapt2/cmd/Compile_test.cpp b/tools/aapt2/cmd/Compile_test.cpp
index fbfbf68..3464a76 100644
--- a/tools/aapt2/cmd/Compile_test.cpp
+++ b/tools/aapt2/cmd/Compile_test.cpp
@@ -219,7 +219,7 @@
ASSERT_NE(table, nullptr);
table->string_pool.Sort();
- const std::vector<std::unique_ptr<StringPool::Entry>>& pool_strings =
+ const std::vector<std::unique_ptr<android::StringPool::Entry>>& pool_strings =
table->string_pool.strings();
// The actual / expected vectors have the same size
@@ -316,7 +316,7 @@
std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(apk_path, &diag);
ResourceTable* resource_table = apk.get()->GetResourceTable();
- const std::vector<std::unique_ptr<StringPool::Entry>>& pool_strings =
+ const std::vector<std::unique_ptr<android::StringPool::Entry>>& pool_strings =
resource_table->string_pool.strings();
ASSERT_EQ(pool_strings.size(), 2);
diff --git a/tools/aapt2/cmd/Convert.cpp b/tools/aapt2/cmd/Convert.cpp
index d8c541d..cf58f98 100644
--- a/tools/aapt2/cmd/Convert.cpp
+++ b/tools/aapt2/cmd/Convert.cpp
@@ -18,6 +18,7 @@
#include <vector>
+#include "Diagnostics.h"
#include "LoadedApk.h"
#include "ValueVisitor.h"
#include "android-base/macros.h"
@@ -42,8 +43,9 @@
class IApkSerializer {
public:
- IApkSerializer(IAaptContext* context, const Source& source) : context_(context),
- source_(source) {}
+ IApkSerializer(IAaptContext* context, const android::Source& source)
+ : context_(context), source_(source) {
+ }
virtual bool SerializeXml(const xml::XmlResource* xml, const std::string& path, bool utf16,
IArchiveWriter* writer, uint32_t compression_flags) = 0;
@@ -54,21 +56,22 @@
protected:
IAaptContext* context_;
- Source source_;
+ android::Source source_;
};
class BinaryApkSerializer : public IApkSerializer {
public:
- BinaryApkSerializer(IAaptContext* context, const Source& source,
+ BinaryApkSerializer(IAaptContext* context, const android::Source& source,
const TableFlattenerOptions& table_flattener_options,
const XmlFlattenerOptions& xml_flattener_options)
: IApkSerializer(context, source),
table_flattener_options_(table_flattener_options),
- xml_flattener_options_(xml_flattener_options) {}
+ xml_flattener_options_(xml_flattener_options) {
+ }
bool SerializeXml(const xml::XmlResource* xml, const std::string& path, bool utf16,
IArchiveWriter* writer, uint32_t compression_flags) override {
- BigBuffer buffer(4096);
+ android::BigBuffer buffer(4096);
xml_flattener_options_.use_utf16 = utf16;
XmlFlattener flattener(&buffer, xml_flattener_options_);
if (!flattener.Consume(context_, xml)) {
@@ -80,7 +83,7 @@
}
bool SerializeTable(ResourceTable* table, IArchiveWriter* writer) override {
- BigBuffer buffer(4096);
+ android::BigBuffer buffer(4096);
TableFlattener table_flattener(table_flattener_options_, &buffer);
if (!table_flattener.Consume(context_, table)) {
return false;
@@ -95,7 +98,7 @@
if (file->type == ResourceFile::Type::kProtoXml) {
unique_ptr<io::InputStream> in = file->file->OpenInputStream();
if (in == nullptr) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
<< "failed to open file " << *file->path);
return false;
}
@@ -103,7 +106,7 @@
pb::XmlNode pb_node;
io::ProtoInputStreamReader proto_reader(in.get());
if (!proto_reader.ReadMessage(&pb_node)) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
<< "failed to parse proto XML " << *file->path);
return false;
}
@@ -111,15 +114,15 @@
std::string error;
unique_ptr<xml::XmlResource> xml = DeserializeXmlResourceFromPb(pb_node, &error);
if (xml == nullptr) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "failed to deserialize proto XML "
- << *file->path << ": " << error);
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
+ << "failed to deserialize proto XML " << *file->path
+ << ": " << error);
return false;
}
if (!SerializeXml(xml.get(), *file->path, false /*utf16*/, writer,
file->file->WasCompressed() ? ArchiveEntry::kCompress : 0u)) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
<< "failed to serialize to binary XML: " << *file->path);
return false;
}
@@ -127,7 +130,7 @@
file->type = ResourceFile::Type::kBinaryXml;
} else {
if (!io::CopyFileToArchivePreserveCompression(context_, file->file, *file->path, writer)) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
<< "failed to copy file " << *file->path);
return false;
}
@@ -145,8 +148,9 @@
class ProtoApkSerializer : public IApkSerializer {
public:
- ProtoApkSerializer(IAaptContext* context, const Source& source)
- : IApkSerializer(context, source) {}
+ ProtoApkSerializer(IAaptContext* context, const android::Source& source)
+ : IApkSerializer(context, source) {
+ }
bool SerializeXml(const xml::XmlResource* xml, const std::string& path, bool utf16,
IArchiveWriter* writer, uint32_t compression_flags) override {
@@ -166,7 +170,7 @@
if (file->type == ResourceFile::Type::kBinaryXml) {
std::unique_ptr<io::IData> data = file->file->OpenAsData();
if (!data) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
<< "failed to open file " << *file->path);
return false;
}
@@ -174,14 +178,14 @@
std::string error;
std::unique_ptr<xml::XmlResource> xml = xml::Inflate(data->data(), data->size(), &error);
if (xml == nullptr) {
- context_->GetDiagnostics()->Error(DiagMessage(source_) << "failed to parse binary XML: "
- << error);
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
+ << "failed to parse binary XML: " << error);
return false;
}
if (!SerializeXml(xml.get(), *file->path, false /*utf16*/, writer,
file->file->WasCompressed() ? ArchiveEntry::kCompress : 0u)) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
<< "failed to serialize to proto XML: " << *file->path);
return false;
}
@@ -189,7 +193,7 @@
file->type = ResourceFile::Type::kProtoXml;
} else {
if (!io::CopyFileToArchivePreserveCompression(context_, file->file, *file->path, writer)) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
+ context_->GetDiagnostics()->Error(android::DiagMessage(source_)
<< "failed to copy file " << *file->path);
return false;
}
@@ -215,7 +219,7 @@
return &symbols_;
}
- IDiagnostics* GetDiagnostics() override {
+ android::IDiagnostics* GetDiagnostics() override {
return &diag_;
}
@@ -270,7 +274,7 @@
} else if (output_format == ApkFormat::kProto) {
serializer.reset(new ProtoApkSerializer(context, apk->GetSource()));
} else {
- context->GetDiagnostics()->Error(DiagMessage(apk->GetSource())
+ context->GetDiagnostics()->Error(android::DiagMessage(apk->GetSource())
<< "Cannot convert APK to unknown format");
return 1;
}
@@ -279,7 +283,7 @@
if (!serializer->SerializeXml(apk->GetManifest(), kAndroidManifestPath, true /*utf16*/,
output_writer, (manifest != nullptr && manifest->WasCompressed())
? ArchiveEntry::kCompress : 0u)) {
- context->GetDiagnostics()->Error(DiagMessage(apk->GetSource())
+ context->GetDiagnostics()->Error(android::DiagMessage(apk->GetSource())
<< "failed to serialize AndroidManifest.xml");
return 1;
}
@@ -298,7 +302,7 @@
FileReference* file = ValueCast<FileReference>(config_value->value.get());
if (file != nullptr) {
if (file->file == nullptr) {
- context->GetDiagnostics()->Error(DiagMessage(apk->GetSource())
+ context->GetDiagnostics()->Error(android::DiagMessage(apk->GetSource())
<< "no file associated with " << *file);
return 1;
}
@@ -306,7 +310,7 @@
// Only serialize if we haven't seen this file before
if (files_written.insert(*file->path).second) {
if (!serializer->SerializeFile(file, output_writer)) {
- context->GetDiagnostics()->Error(DiagMessage(apk->GetSource())
+ context->GetDiagnostics()->Error(android::DiagMessage(apk->GetSource())
<< "failed to serialize file " << *file->path);
return 1;
}
@@ -319,7 +323,7 @@
// Converted resource table
if (!serializer->SerializeTable(converted_table, output_writer)) {
- context->GetDiagnostics()->Error(DiagMessage(apk->GetSource())
+ context->GetDiagnostics()->Error(android::DiagMessage(apk->GetSource())
<< "failed to serialize the resource table");
return 1;
}
@@ -340,8 +344,8 @@
}
if (!io::CopyFileToArchivePreserveCompression(context, file, path, output_writer)) {
- context->GetDiagnostics()->Error(DiagMessage(apk->GetSource())
- << "failed to copy file " << path);
+ context->GetDiagnostics()->Error(android::DiagMessage(apk->GetSource())
+ << "failed to copy file " << path);
return 1;
}
}
@@ -363,7 +367,7 @@
const StringPiece& path = args[0];
unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(path, context.GetDiagnostics());
if (apk == nullptr) {
- context.GetDiagnostics()->Error(DiagMessage(path) << "failed to load APK");
+ context.GetDiagnostics()->Error(android::DiagMessage(path) << "failed to load APK");
return 1;
}
@@ -386,8 +390,9 @@
} else if (output_format_.value() == ConvertCommand::kOutputFormatProto) {
format = ApkFormat::kProto;
} else {
- context.GetDiagnostics()->Error(DiagMessage(path) << "Invalid value for flag --output-format: "
- << output_format_.value());
+ context.GetDiagnostics()->Error(android::DiagMessage(path)
+ << "Invalid value for flag --output-format: "
+ << output_format_.value());
return 1;
}
diff --git a/tools/aapt2/cmd/Convert_test.cpp b/tools/aapt2/cmd/Convert_test.cpp
index f35237e..27df8c1 100644
--- a/tools/aapt2/cmd/Convert_test.cpp
+++ b/tools/aapt2/cmd/Convert_test.cpp
@@ -101,7 +101,8 @@
// Check that the raw string index has been set to the correct string pool entry
int32_t raw_index = tree.getAttributeValueStringID(0);
ASSERT_THAT(raw_index, Ne(-1));
- EXPECT_THAT(util::GetString(tree.getStrings(), static_cast<size_t>(raw_index)), Eq("007"));
+ EXPECT_THAT(android::util::GetString(tree.getStrings(), static_cast<size_t>(raw_index)),
+ Eq("007"));
}
TEST_F(ConvertTest, DuplicateEntriesWrittenOnce) {
diff --git a/tools/aapt2/cmd/Diff.cpp b/tools/aapt2/cmd/Diff.cpp
index a854146..423e939 100644
--- a/tools/aapt2/cmd/Diff.cpp
+++ b/tools/aapt2/cmd/Diff.cpp
@@ -16,10 +16,10 @@
#include "Diff.h"
-#include "android-base/macros.h"
-
+#include "Diagnostics.h"
#include "LoadedApk.h"
#include "ValueVisitor.h"
+#include "android-base/macros.h"
#include "process/IResourceTableConsumer.h"
#include "process/SymbolTable.h"
@@ -45,7 +45,7 @@
return 0x0;
}
- IDiagnostics* GetDiagnostics() override {
+ android::IDiagnostics* GetDiagnostics() override {
return &diagnostics_;
}
@@ -78,7 +78,7 @@
SymbolTable symbol_table_;
};
-static void EmitDiffLine(const Source& source, const StringPiece& message) {
+static void EmitDiffLine(const android::Source& source, const StringPiece& message) {
std::cerr << source << ": " << message << "\n";
}
@@ -385,7 +385,7 @@
return 1;
}
- IDiagnostics* diag = context.GetDiagnostics();
+ android::IDiagnostics* diag = context.GetDiagnostics();
std::unique_ptr<LoadedApk> apk_a = LoadedApk::LoadApkFromPath(args[0], diag);
std::unique_ptr<LoadedApk> apk_b = LoadedApk::LoadApkFromPath(args[1], diag);
if (!apk_a || !apk_b) {
diff --git a/tools/aapt2/cmd/Dump.cpp b/tools/aapt2/cmd/Dump.cpp
index bcce3e5..71b0802 100644
--- a/tools/aapt2/cmd/Dump.cpp
+++ b/tools/aapt2/cmd/Dump.cpp
@@ -57,8 +57,8 @@
return "UNKNOWN";
}
-static void DumpCompiledFile(const ResourceFile& file, const Source& source, off64_t offset,
- size_t len, Printer* printer) {
+static void DumpCompiledFile(const ResourceFile& file, const android::Source& source,
+ off64_t offset, size_t len, Printer* printer) {
printer->Print("Resource: ");
printer->Println(file.name.to_string());
@@ -83,7 +83,7 @@
return PackageType::kApp;
}
- IDiagnostics* GetDiagnostics() override {
+ android::IDiagnostics* GetDiagnostics() override {
return &diagnostics_;
}
@@ -138,7 +138,7 @@
print_options.show_values = !no_values_;
if (args.size() < 1) {
- diag_->Error(DiagMessage() << "No dump container specified");
+ diag_->Error(android::DiagMessage() << "No dump container specified");
return 1;
}
@@ -146,7 +146,7 @@
for (auto container : args) {
io::FileInputStream input(container);
if (input.HadError()) {
- context.GetDiagnostics()->Error(DiagMessage(container)
+ context.GetDiagnostics()->Error(android::DiagMessage(container)
<< "failed to open file: " << input.GetError());
error = true;
continue;
@@ -155,7 +155,7 @@
// Try as a compiled file.
ContainerReader reader(&input);
if (reader.HadError()) {
- context.GetDiagnostics()->Error(DiagMessage(container)
+ context.GetDiagnostics()->Error(android::DiagMessage(container)
<< "failed to read container: " << reader.GetError());
error = true;
continue;
@@ -170,7 +170,7 @@
pb::ResourceTable pb_table;
if (!entry->GetResTable(&pb_table)) {
- context.GetDiagnostics()->Error(DiagMessage(container)
+ context.GetDiagnostics()->Error(android::DiagMessage(container)
<< "failed to parse proto table: " << entry->GetError());
error = true;
continue;
@@ -179,7 +179,7 @@
ResourceTable table;
error.clear();
if (!DeserializeTableFromPb(pb_table, nullptr /*files*/, &table, &error)) {
- context.GetDiagnostics()->Error(DiagMessage(container)
+ context.GetDiagnostics()->Error(android::DiagMessage(container)
<< "failed to parse table: " << error);
error = true;
continue;
@@ -194,7 +194,7 @@
off64_t offset;
size_t length;
if (!entry->GetResFileOffsets(&pb_compiled_file, &offset, &length)) {
- context.GetDiagnostics()->Error(DiagMessage(container)
+ context.GetDiagnostics()->Error(android::DiagMessage(container)
<< "failed to parse compiled proto file: "
<< entry->GetError());
error = true;
@@ -203,14 +203,14 @@
ResourceFile file;
if (!DeserializeCompiledFileFromPb(pb_compiled_file, &file, &error)) {
- context.GetDiagnostics()->Warn(DiagMessage(container)
+ context.GetDiagnostics()->Warn(android::DiagMessage(container)
<< "failed to parse compiled file: " << error);
error = true;
continue;
}
printer_->Indent();
- DumpCompiledFile(file, Source(container), offset, length, printer_);
+ DumpCompiledFile(file, android::Source(container), offset, length, printer_);
printer_->Undent();
}
}
@@ -228,7 +228,7 @@
int DumpConfigsCommand::Dump(LoadedApk* apk) {
ResourceTable* table = apk->GetResourceTable();
if (!table) {
- GetDiagnostics()->Error(DiagMessage() << "Failed to retrieve resource table");
+ GetDiagnostics()->Error(android::DiagMessage() << "Failed to retrieve resource table");
return 1;
}
@@ -268,13 +268,13 @@
int DumpStringsCommand::Dump(LoadedApk* apk) {
ResourceTable* table = apk->GetResourceTable();
if (!table) {
- GetDiagnostics()->Error(DiagMessage() << "Failed to retrieve resource table");
+ GetDiagnostics()->Error(android::DiagMessage() << "Failed to retrieve resource table");
return 1;
}
// Load the run-time xml string pool using the flattened data
- BigBuffer buffer(4096);
- StringPool::FlattenUtf8(&buffer, table->string_pool, GetDiagnostics());
+ android::BigBuffer buffer(4096);
+ android::StringPool::FlattenUtf8(&buffer, table->string_pool, GetDiagnostics());
auto data = buffer.to_string();
android::ResStringPool pool(data.data(), data.size(), false);
Debug::DumpResStringPool(&pool, GetPrinter());
@@ -291,14 +291,14 @@
const auto table = apk->GetResourceTable();
if (!table) {
- GetDiagnostics()->Error(DiagMessage() << "Failed to retrieve resource table");
+ GetDiagnostics()->Error(android::DiagMessage() << "Failed to retrieve resource table");
return 1;
}
std::optional<ResourceTable::SearchResult> target = table->FindResource(target_style);
if (!target) {
- GetDiagnostics()->Error(
- DiagMessage() << "Target style \"" << target_style.entry << "\" does not exist");
+ GetDiagnostics()->Error(android::DiagMessage()
+ << "Target style \"" << target_style.entry << "\" does not exist");
return 1;
}
@@ -315,7 +315,7 @@
ResourceTable* table = apk->GetResourceTable();
if (!table) {
- GetDiagnostics()->Error(DiagMessage() << "Failed to retrieve resource table");
+ GetDiagnostics()->Error(android::DiagMessage() << "Failed to retrieve resource table");
return 1;
}
@@ -340,7 +340,7 @@
}
// Flatten the xml document to get a binary representation of the proto xml file
- BigBuffer buffer(4096);
+ android::BigBuffer buffer(4096);
XmlFlattenerOptions options = {};
options.keep_raw_values = true;
XmlFlattener flattener(&buffer, options);
@@ -356,7 +356,7 @@
} else if (apk->GetApkFormat() == ApkFormat::kBinary) {
io::IFile* file = apk->GetFileCollection()->FindFile(xml_file);
if (!file) {
- GetDiagnostics()->Error(DiagMessage(xml_file)
+ GetDiagnostics()->Error(android::DiagMessage(xml_file)
<< "File '" << xml_file << "' not found in APK");
error = true;
continue;
@@ -364,7 +364,7 @@
std::unique_ptr<io::IData> data = file->OpenAsData();
if (!data) {
- GetDiagnostics()->Error(DiagMessage() << "Failed to open " << xml_file);
+ GetDiagnostics()->Error(android::DiagMessage() << "Failed to open " << xml_file);
error = true;
continue;
}
@@ -372,7 +372,7 @@
// Load the run-time xml tree from the file data
tree.setTo(data->data(), data->size(), /** copyData */ true);
} else {
- GetDiagnostics()->Error(DiagMessage(apk->GetSource()) << "Unknown APK format");
+ GetDiagnostics()->Error(android::DiagMessage(apk->GetSource()) << "Unknown APK format");
error = true;
continue;
}
@@ -396,7 +396,7 @@
int DumpOverlayableCommand::Dump(LoadedApk* apk) {
ResourceTable* table = apk->GetResourceTable();
if (!table) {
- GetDiagnostics()->Error(DiagMessage() << "Failed to retrieve resource table");
+ GetDiagnostics()->Error(android::DiagMessage() << "Failed to retrieve resource table");
return 1;
}
@@ -563,13 +563,13 @@
int DumpChunks::Dump(LoadedApk* apk) {
auto file = apk->GetFileCollection()->FindFile("resources.arsc");
if (!file) {
- GetDiagnostics()->Error(DiagMessage() << "Failed to find resources.arsc in APK");
+ GetDiagnostics()->Error(android::DiagMessage() << "Failed to find resources.arsc in APK");
return 1;
}
auto data = file->OpenAsData();
if (!data) {
- GetDiagnostics()->Error(DiagMessage() << "Failed to open resources.arsc ");
+ GetDiagnostics()->Error(android::DiagMessage() << "Failed to open resources.arsc ");
return 1;
}
diff --git a/tools/aapt2/cmd/Dump.h b/tools/aapt2/cmd/Dump.h
index c7a3567..76d33d7 100644
--- a/tools/aapt2/cmd/Dump.h
+++ b/tools/aapt2/cmd/Dump.h
@@ -33,29 +33,30 @@
**/
class DumpApkCommand : public Command {
public:
- explicit DumpApkCommand(const std::string&& name, text::Printer* printer, IDiagnostics* diag)
+ explicit DumpApkCommand(const std::string&& name, text::Printer* printer,
+ android::IDiagnostics* diag)
: Command(name), printer_(printer), diag_(diag) {
- SetDescription("Dump information about an APK or APC.");
+ SetDescription("Dump information about an APK or APC.");
}
text::Printer* GetPrinter() {
return printer_;
}
- IDiagnostics* GetDiagnostics() {
+ android::IDiagnostics* GetDiagnostics() {
return diag_;
}
std::optional<std::string> GetPackageName(LoadedApk* apk) {
xml::Element* manifest_el = apk->GetManifest()->root.get();
if (!manifest_el) {
- GetDiagnostics()->Error(DiagMessage() << "No AndroidManifest.");
+ GetDiagnostics()->Error(android::DiagMessage() << "No AndroidManifest.");
return {};
}
xml::Attribute* attr = manifest_el->FindAttribute({}, "package");
if (!attr) {
- GetDiagnostics()->Error(DiagMessage() << "No package name.");
+ GetDiagnostics()->Error(android::DiagMessage() << "No package name.");
return {};
}
return attr->value;
@@ -66,7 +67,7 @@
int Action(const std::vector<std::string>& args) final {
if (args.size() < 1) {
- diag_->Error(DiagMessage() << "No dump apk specified.");
+ diag_->Error(android::DiagMessage() << "No dump apk specified.");
return 1;
}
@@ -86,13 +87,13 @@
private:
text::Printer* printer_;
- IDiagnostics* diag_;
+ android::IDiagnostics* diag_;
};
/** Command that prints contents of files generated from the compilation stage. */
class DumpAPCCommand : public Command {
public:
- explicit DumpAPCCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpAPCCommand(text::Printer* printer, android::IDiagnostics* diag)
: Command("apc"), printer_(printer), diag_(diag) {
SetDescription("Print the contents of the AAPT2 Container (APC) generated fom compilation.");
AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.",
@@ -104,7 +105,7 @@
private:
text::Printer* printer_;
- IDiagnostics* diag_;
+ android::IDiagnostics* diag_;
bool no_values_ = false;
bool verbose_ = false;
};
@@ -124,7 +125,7 @@
class DumpBadgingCommand : public DumpApkCommand {
public:
- explicit DumpBadgingCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpBadgingCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("badging", printer, diag) {
SetDescription("Print information extracted from the manifest of the APK.");
AddOptionalSwitch("--include-meta-data", "Include meta-data information.",
@@ -149,7 +150,7 @@
class DumpConfigsCommand : public DumpApkCommand {
public:
- explicit DumpConfigsCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpConfigsCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("configurations", printer, diag) {
SetDescription("Print every configuration used by a resource in the APK.");
}
@@ -159,7 +160,7 @@
class DumpPackageNameCommand : public DumpApkCommand {
public:
- explicit DumpPackageNameCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpPackageNameCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("packagename", printer, diag) {
SetDescription("Print the package name of the APK.");
}
@@ -169,7 +170,7 @@
class DumpPermissionsCommand : public DumpApkCommand {
public:
- explicit DumpPermissionsCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpPermissionsCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("permissions", printer, diag) {
SetDescription("Print the permissions extracted from the manifest of the APK.");
}
@@ -183,7 +184,7 @@
class DumpStringsCommand : public DumpApkCommand {
public:
- explicit DumpStringsCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpStringsCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("strings", printer, diag) {
SetDescription("Print the contents of the resource table string pool in the APK.");
}
@@ -194,7 +195,7 @@
/** Prints the graph of parents of a style in an APK. */
class DumpStyleParentCommand : public DumpApkCommand {
public:
- explicit DumpStyleParentCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpStyleParentCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("styleparents", printer, diag) {
SetDescription("Print the parents of a style in an APK.");
AddRequiredFlag("--style", "The name of the style to print", &style_);
@@ -208,7 +209,7 @@
class DumpTableCommand : public DumpApkCommand {
public:
- explicit DumpTableCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpTableCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("resources", printer, diag) {
SetDescription("Print the contents of the resource table from the APK.");
AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.",
@@ -225,7 +226,7 @@
class DumpXmlStringsCommand : public DumpApkCommand {
public:
- explicit DumpXmlStringsCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpXmlStringsCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("xmlstrings", printer, diag) {
SetDescription("Print the string pool of a compiled xml in an APK.");
AddRequiredFlagList("--file", "A compiled xml file to print", &files_);
@@ -239,7 +240,8 @@
class DumpChunks : public DumpApkCommand {
public:
- DumpChunks(text::Printer* printer, IDiagnostics* diag) : DumpApkCommand("chunks", printer, diag) {
+ DumpChunks(text::Printer* printer, android::IDiagnostics* diag)
+ : DumpApkCommand("chunks", printer, diag) {
SetDescription("Print the chunk information of the compiled resources.arsc in the APK.");
}
@@ -249,7 +251,7 @@
/** Prints the tree of a compiled xml in an APK. */
class DumpXmlTreeCommand : public DumpApkCommand {
public:
- explicit DumpXmlTreeCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpXmlTreeCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("xmltree", printer, diag) {
SetDescription("Print the tree of a compiled xml in an APK.");
AddRequiredFlagList("--file", "A compiled xml file to print", &files_);
@@ -263,7 +265,7 @@
class DumpOverlayableCommand : public DumpApkCommand {
public:
- explicit DumpOverlayableCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpOverlayableCommand(text::Printer* printer, android::IDiagnostics* diag)
: DumpApkCommand("overlayable", printer, diag) {
SetDescription("Print the <overlayable> resources of an APK.");
}
@@ -274,7 +276,7 @@
/** The default dump command. Performs no action because a subcommand is required. */
class DumpCommand : public Command {
public:
- explicit DumpCommand(text::Printer* printer, IDiagnostics* diag)
+ explicit DumpCommand(text::Printer* printer, android::IDiagnostics* diag)
: Command("dump", "d"), diag_(diag) {
AddOptionalSubcommand(util::make_unique<DumpAPCCommand>(printer, diag_));
AddOptionalSubcommand(util::make_unique<DumpBadgingCommand>(printer, diag_));
@@ -293,16 +295,16 @@
int Action(const std::vector<std::string>& args) override {
if (args.size() == 0) {
- diag_->Error(DiagMessage() << "no subcommand specified");
+ diag_->Error(android::DiagMessage() << "no subcommand specified");
} else {
- diag_->Error(DiagMessage() << "unknown subcommand '" << args[0] << "'");
+ diag_->Error(android::DiagMessage() << "unknown subcommand '" << args[0] << "'");
}
Usage(&std::cerr);
return 1;
}
private:
- IDiagnostics* diag_;
+ android::IDiagnostics* diag_;
};
} // namespace aapt
diff --git a/tools/aapt2/cmd/Dump_test.cpp b/tools/aapt2/cmd/Dump_test.cpp
index d018882..03da364 100644
--- a/tools/aapt2/cmd/Dump_test.cpp
+++ b/tools/aapt2/cmd/Dump_test.cpp
@@ -30,12 +30,7 @@
using DumpTest = CommandTestFixture;
-class NoopDiagnostics : public IDiagnostics {
- public:
- void Log(Level level, DiagMessageActual& actualMsg) override {
- }
-};
-static NoopDiagnostics noop_diag;
+static android::NoOpDiagnostics noop_diag;
void DumpBadgingToString(LoadedApk* loaded_apk, std::string* output, bool include_meta_data = false,
bool only_permissions = false) {
@@ -97,4 +92,4 @@
ASSERT_EQ(output, expected);
}
-} // namespace aapt
\ No newline at end of file
+} // namespace aapt
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index bd74cc7..82f2e8f 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -17,20 +17,13 @@
#include "Link.h"
#include <sys/stat.h>
-#include <cinttypes>
#include <algorithm>
+#include <cinttypes>
#include <queue>
#include <unordered_map>
#include <vector>
-#include "android-base/errors.h"
-#include "android-base/expected.h"
-#include "android-base/file.h"
-#include "android-base/stringprintf.h"
-#include "androidfw/Locale.h"
-#include "androidfw/StringPiece.h"
-
#include "AppInfo.h"
#include "Debug.h"
#include "LoadedApk.h"
@@ -38,6 +31,13 @@
#include "ResourceUtils.h"
#include "ResourceValues.h"
#include "ValueVisitor.h"
+#include "android-base/errors.h"
+#include "android-base/expected.h"
+#include "android-base/file.h"
+#include "android-base/stringprintf.h"
+#include "androidfw/IDiagnostics.h"
+#include "androidfw/Locale.h"
+#include "androidfw/StringPiece.h"
#include "cmd/Util.h"
#include "compile/IdAssigner.h"
#include "compile/XmlIdCollector.h"
@@ -98,7 +98,7 @@
class LinkContext : public IAaptContext {
public:
- explicit LinkContext(IDiagnostics* diagnostics)
+ explicit LinkContext(android::IDiagnostics* diagnostics)
: diagnostics_(diagnostics), name_mangler_({}), symbols_(&name_mangler_) {
}
@@ -110,7 +110,7 @@
package_type_ = type;
}
- IDiagnostics* GetDiagnostics() override {
+ android::IDiagnostics* GetDiagnostics() override {
return diagnostics_;
}
@@ -170,7 +170,7 @@
DISALLOW_COPY_AND_ASSIGN(LinkContext);
PackageType package_type_ = PackageType::kApp;
- IDiagnostics* diagnostics_;
+ android::IDiagnostics* diagnostics_;
NameMangler name_mangler_;
std::string compilation_package_;
uint8_t package_id_ = 0x0;
@@ -216,14 +216,16 @@
// Check that this doesn't overlap another resource.
if (DefaultSymbolTableDelegate::FindById(rewritten_id, sources) != nullptr) {
// The ID overlaps, so log a message (since this is a weird failure) and fail.
- context_->GetDiagnostics()->Error(DiagMessage() << "Failed to rewrite " << name
- << " for pre-O feature split support");
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "Failed to rewrite " << name
+ << " for pre-O feature split support");
return {};
}
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage() << "rewriting " << name << " (" << *id
- << ") -> (" << rewritten_id << ")");
+ context_->GetDiagnostics()->Note(android::DiagMessage()
+ << "rewriting " << name << " (" << *id << ") -> ("
+ << rewritten_id << ")");
}
*id = rewritten_id;
@@ -243,14 +245,14 @@
OutputFormat format, IArchiveWriter* writer) {
TRACE_CALL();
if (context->IsVerbose()) {
- context->GetDiagnostics()->Note(DiagMessage(path) << "writing to archive (keep_raw_values="
- << (keep_raw_values ? "true" : "false")
- << ")");
+ context->GetDiagnostics()->Note(android::DiagMessage(path)
+ << "writing to archive (keep_raw_values="
+ << (keep_raw_values ? "true" : "false") << ")");
}
switch (format) {
case OutputFormat::kApk: {
- BigBuffer buffer(1024);
+ android::BigBuffer buffer(1024);
XmlFlattenerOptions options = {};
options.keep_raw_values = keep_raw_values;
options.use_utf16 = utf16;
@@ -278,14 +280,15 @@
}
// Inflates an XML file from the source path.
-static std::unique_ptr<xml::XmlResource> LoadXml(const std::string& path, IDiagnostics* diag) {
+static std::unique_ptr<xml::XmlResource> LoadXml(const std::string& path,
+ android::IDiagnostics* diag) {
TRACE_CALL();
FileInputStream fin(path);
if (fin.HadError()) {
- diag->Error(DiagMessage(path) << "failed to load XML file: " << fin.GetError());
+ diag->Error(android::DiagMessage(path) << "failed to load XML file: " << fin.GetError());
return {};
}
- return xml::Inflate(&fin, diag, Source(path));
+ return xml::Inflate(&fin, diag, android::Source(path));
}
struct ResourceFileFlattenerOptions {
@@ -451,10 +454,10 @@
ResourceTable* table, FileOperation* file_op) {
TRACE_CALL();
xml::XmlResource* doc = file_op->xml_to_flatten.get();
- const Source& src = doc->file.source;
+ const android::Source& src = doc->file.source;
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage()
+ context_->GetDiagnostics()->Note(android::DiagMessage()
<< "linking " << src.path << " (" << doc->file.name << ")");
}
@@ -545,7 +548,7 @@
io::IFile* file = file_ref->file;
if (!file) {
- context_->GetDiagnostics()->Error(DiagMessage(file_ref->GetSource())
+ context_->GetDiagnostics()->Error(android::DiagMessage(file_ref->GetSource())
<< "file not found");
return false;
}
@@ -561,7 +564,7 @@
file_ref->type == ResourceFile::Type::kProtoXml)) {
std::unique_ptr<io::IData> data = file->OpenAsData();
if (!data) {
- context_->GetDiagnostics()->Error(DiagMessage(file->GetSource())
+ context_->GetDiagnostics()->Error(android::DiagMessage(file->GetSource())
<< "failed to open file");
return false;
}
@@ -569,7 +572,7 @@
if (file_ref->type == ResourceFile::Type::kProtoXml) {
pb::XmlNode pb_xml_node;
if (!pb_xml_node.ParseFromArray(data->data(), static_cast<int>(data->size()))) {
- context_->GetDiagnostics()->Error(DiagMessage(file->GetSource())
+ context_->GetDiagnostics()->Error(android::DiagMessage(file->GetSource())
<< "failed to parse proto XML");
return false;
}
@@ -577,7 +580,7 @@
std::string error;
file_op.xml_to_flatten = DeserializeXmlResourceFromPb(pb_xml_node, &error);
if (file_op.xml_to_flatten == nullptr) {
- context_->GetDiagnostics()->Error(DiagMessage(file->GetSource())
+ context_->GetDiagnostics()->Error(android::DiagMessage(file->GetSource())
<< "failed to deserialize proto XML: " << error);
return false;
}
@@ -585,7 +588,7 @@
std::string error_str;
file_op.xml_to_flatten = xml::Inflate(data->data(), data->size(), &error_str);
if (file_op.xml_to_flatten == nullptr) {
- context_->GetDiagnostics()->Error(DiagMessage(file->GetSource())
+ context_->GetDiagnostics()->Error(android::DiagMessage(file->GetSource())
<< "failed to parse binary XML: " << error_str);
return false;
}
@@ -621,10 +624,10 @@
if (drawable_entry != kDrawableVersions.end()) {
if (drawable_entry->second > context_->GetMinSdkVersion()
&& drawable_entry->second > config.sdkVersion) {
- context_->GetDiagnostics()->Error(DiagMessage(file_op.xml_to_flatten->file.source)
- << "<" << drawable_entry->first << "> elements "
- << "require a sdk version of at least "
- << (int16_t) drawable_entry->second);
+ context_->GetDiagnostics()->Error(
+ android::DiagMessage(file_op.xml_to_flatten->file.source)
+ << "<" << drawable_entry->first << "> elements "
+ << "require a sdk version of at least " << (int16_t)drawable_entry->second);
error = true;
continue;
}
@@ -642,7 +645,7 @@
if (doc->file.config != file_op.config) {
// Only add the new versioned configurations.
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage(doc->file.source)
+ context_->GetDiagnostics()->Note(android::DiagMessage(doc->file.source)
<< "auto-versioning resource from config '"
<< config << "' -> '" << doc->file.config << "'");
}
@@ -680,12 +683,12 @@
return !error;
}
-static bool WriteStableIdMapToPath(IDiagnostics* diag,
+static bool WriteStableIdMapToPath(android::IDiagnostics* diag,
const std::unordered_map<ResourceName, ResourceId>& id_map,
const std::string& id_map_path) {
io::FileOutputStream fout(id_map_path);
if (fout.HadError()) {
- diag->Error(DiagMessage(id_map_path) << "failed to open: " << fout.GetError());
+ diag->Error(android::DiagMessage(id_map_path) << "failed to open: " << fout.GetError());
return false;
}
@@ -700,17 +703,17 @@
fout.Flush();
if (fout.HadError()) {
- diag->Error(DiagMessage(id_map_path) << "failed writing to file: " << fout.GetError());
+ diag->Error(android::DiagMessage(id_map_path) << "failed writing to file: " << fout.GetError());
return false;
}
return true;
}
-static bool LoadStableIdMap(IDiagnostics* diag, const std::string& path,
+static bool LoadStableIdMap(android::IDiagnostics* diag, const std::string& path,
std::unordered_map<ResourceName, ResourceId>* out_id_map) {
std::string content;
if (!android::base::ReadFileToString(path, &content, true /*follow_symlinks*/)) {
- diag->Error(DiagMessage(path) << "failed reading stable ID file");
+ diag->Error(android::DiagMessage(path) << "failed reading stable ID file");
return false;
}
@@ -725,7 +728,7 @@
auto iter = std::find(line.begin(), line.end(), '=');
if (iter == line.end()) {
- diag->Error(DiagMessage(Source(path, line_no)) << "missing '='");
+ diag->Error(android::DiagMessage(android::Source(path, line_no)) << "missing '='");
return false;
}
@@ -733,8 +736,8 @@
StringPiece res_name_str =
util::TrimWhitespace(line.substr(0, std::distance(line.begin(), iter)));
if (!ResourceUtils::ParseResourceName(res_name_str, &name)) {
- diag->Error(DiagMessage(Source(path, line_no)) << "invalid resource name '" << res_name_str
- << "'");
+ diag->Error(android::DiagMessage(android::Source(path, line_no))
+ << "invalid resource name '" << res_name_str << "'");
return false;
}
@@ -744,8 +747,8 @@
std::optional<ResourceId> maybe_id = ResourceUtils::ParseResourceId(res_id_str);
if (!maybe_id) {
- diag->Error(DiagMessage(Source(path, line_no)) << "invalid resource ID '" << res_id_str
- << "'");
+ diag->Error(android::DiagMessage(android::Source(path, line_no))
+ << "invalid resource ID '" << res_id_str << "'");
return false;
}
@@ -835,20 +838,21 @@
auto asset_source = util::make_unique<AssetManagerSymbolSource>();
for (const std::string& path : options_.include_paths) {
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage() << "including " << path);
+ context_->GetDiagnostics()->Note(android::DiagMessage() << "including " << path);
}
std::string error;
auto zip_collection = io::ZipFileCollection::Create(path, &error);
if (zip_collection == nullptr) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed to open APK: " << error);
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed to open APK: " << error);
return false;
}
if (zip_collection->FindFile(kProtoResourceTablePath) != nullptr) {
// Load this as a static library include.
std::unique_ptr<LoadedApk> static_apk = LoadedApk::LoadProtoApkFromFileCollection(
- Source(path), std::move(zip_collection), context_->GetDiagnostics());
+ android::Source(path), std::move(zip_collection), context_->GetDiagnostics());
if (static_apk == nullptr) {
return false;
}
@@ -857,7 +861,8 @@
// Can't include static libraries when not building a static library (they have no IDs
// assigned).
context_->GetDiagnostics()->Error(
- DiagMessage(path) << "can't include static library when not building a static lib");
+ android::DiagMessage(path)
+ << "can't include static library when not building a static lib");
return false;
}
@@ -869,7 +874,8 @@
if (options_.no_static_lib_packages && !table->packages.empty()) {
auto lib_package_result = GetStaticLibraryPackage(table);
if (!lib_package_result.has_value()) {
- context_->GetDiagnostics()->Error(DiagMessage(path) << lib_package_result.error());
+ context_->GetDiagnostics()->Error(android::DiagMessage(path)
+ << lib_package_result.error());
return false;
}
lib_package_result.value()->name = context_->GetCompilationPackage();
@@ -880,7 +886,7 @@
static_library_includes_.push_back(std::move(static_apk));
} else {
if (!asset_source->AddAssetPath(path)) {
- context_->GetDiagnostics()->Error(DiagMessage()
+ context_->GetDiagnostics()->Error(android::DiagMessage()
<< "failed to load include path " << path);
return false;
}
@@ -913,7 +919,8 @@
return true;
}
- std::optional<AppInfo> ExtractAppInfoFromManifest(xml::XmlResource* xml_res, IDiagnostics* diag) {
+ std::optional<AppInfo> ExtractAppInfoFromManifest(xml::XmlResource* xml_res,
+ android::IDiagnostics* diag) {
TRACE_CALL();
// Make sure the first element is <manifest> with package attribute.
xml::Element* manifest_el = xml::FindRootElement(xml_res->root.get());
@@ -924,13 +931,13 @@
AppInfo app_info;
if (!manifest_el->namespace_uri.empty() || manifest_el->name != "manifest") {
- diag->Error(DiagMessage(xml_res->file.source) << "root tag must be <manifest>");
+ diag->Error(android::DiagMessage(xml_res->file.source) << "root tag must be <manifest>");
return {};
}
xml::Attribute* package_attr = manifest_el->FindAttribute({}, "package");
if (!package_attr) {
- diag->Error(DiagMessage(xml_res->file.source)
+ diag->Error(android::DiagMessage(xml_res->file.source)
<< "<manifest> must have a 'package' attribute");
return {};
}
@@ -940,7 +947,7 @@
manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCode")) {
std::optional<uint32_t> maybe_code = ResourceUtils::ParseInt(version_code_attr->value);
if (!maybe_code) {
- diag->Error(DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
+ diag->Error(android::DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
<< "invalid android:versionCode '" << version_code_attr->value << "'");
return {};
}
@@ -951,9 +958,9 @@
manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCodeMajor")) {
std::optional<uint32_t> maybe_code = ResourceUtils::ParseInt(version_code_major_attr->value);
if (!maybe_code) {
- diag->Error(DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
- << "invalid android:versionCodeMajor '"
- << version_code_major_attr->value << "'");
+ diag->Error(android::DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
+ << "invalid android:versionCodeMajor '" << version_code_major_attr->value
+ << "'");
return {};
}
app_info.version_code_major = maybe_code.value();
@@ -963,7 +970,7 @@
manifest_el->FindAttribute(xml::kSchemaAndroid, "revisionCode")) {
std::optional<uint32_t> maybe_code = ResourceUtils::ParseInt(revision_code_attr->value);
if (!maybe_code) {
- diag->Error(DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
+ diag->Error(android::DiagMessage(xml_res->file.source.WithLine(manifest_el->line_number))
<< "invalid android:revisionCode '" << revision_code_attr->value << "'");
return {};
}
@@ -1016,15 +1023,15 @@
// Special case the occurrence of an ID that is being generated
// for the 'android' package. This is due to legacy reasons.
if (ValueCast<Id>(config_value->value.get()) && package->name == "android") {
- context_->GetDiagnostics()->Warn(DiagMessage(config_value->value->GetSource())
- << "generated id '" << res_name
- << "' for external package '" << package->name
- << "'");
+ context_->GetDiagnostics()->Warn(
+ android::DiagMessage(config_value->value->GetSource())
+ << "generated id '" << res_name << "' for external package '" << package->name
+ << "'");
} else {
- context_->GetDiagnostics()->Error(DiagMessage(config_value->value->GetSource())
- << "defined resource '" << res_name
- << "' for external package '" << package->name
- << "'");
+ context_->GetDiagnostics()->Error(
+ android::DiagMessage(config_value->value->GetSource())
+ << "defined resource '" << res_name << "' for external package '"
+ << package->name << "'");
error = true;
}
}
@@ -1048,8 +1055,9 @@
for (const auto& entry : type->entries) {
if (entry->id) {
ResourceNameRef res_name(package->name, type->named_type, entry->name);
- context_->GetDiagnostics()->Error(DiagMessage() << "resource " << res_name << " has ID "
- << entry->id.value() << " assigned");
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "resource " << res_name << " has ID "
+ << entry->id.value() << " assigned");
return false;
}
}
@@ -1058,7 +1066,7 @@
return true;
}
- bool VerifyLocaleFormat(xml::XmlResource* manifest, IDiagnostics* diag) {
+ bool VerifyLocaleFormat(xml::XmlResource* manifest, android::IDiagnostics* diag) {
// Skip it if the Manifest doesn't declare the localeConfig attribute within the <application>
// element.
const xml::Element* application = manifest->root->FindChild("", "application");
@@ -1084,18 +1092,19 @@
const std::string& path = value->value->GetSource().path;
std::unique_ptr<xml::XmlResource> localeConfig_xml = LoadXml(path, diag);
if (!localeConfig_xml) {
- diag->Error(DiagMessage(path) << "can't load the XML");
+ diag->Error(android::DiagMessage(path) << "can't load the XML");
return false;
}
xml::Element* localeConfig_el = xml::FindRootElement(localeConfig_xml->root.get());
if (!localeConfig_el) {
- diag->Error(DiagMessage(path) << "no root tag defined");
+ diag->Error(android::DiagMessage(path) << "no root tag defined");
return false;
}
if (localeConfig_el->name != "locale-config") {
- diag->Error(DiagMessage(path) << "invalid element name: " << localeConfig_el->name
- << ", expected: locale-config");
+ diag->Error(android::DiagMessage(path)
+ << "invalid element name: " << localeConfig_el->name
+ << ", expected: locale-config");
return false;
}
@@ -1109,15 +1118,15 @@
// Start to verify the locale format
ConfigDescription config;
if (!ConfigDescription::Parse(valid_name, &config)) {
- diag->Error(DiagMessage(path) << "invalid configuration: " << locale_name);
+ diag->Error(android::DiagMessage(path) << "invalid configuration: " << locale_name);
return false;
}
} else {
- diag->Error(DiagMessage(path) << "the attribute android:name is not found");
+ diag->Error(android::DiagMessage(path) << "the attribute android:name is not found");
return false;
}
} else {
- diag->Error(DiagMessage(path)
+ diag->Error(android::DiagMessage(path)
<< "invalid element name: " << child_el->name << ", expected: locale");
return false;
}
@@ -1147,10 +1156,11 @@
TRACE_CALL();
switch (format) {
case OutputFormat::kApk: {
- BigBuffer buffer(1024);
+ android::BigBuffer buffer(1024);
TableFlattener flattener(options_.table_flattener_options, &buffer);
if (!flattener.Consume(context_, table)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed to flatten resource table");
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed to flatten resource table");
return false;
}
@@ -1183,7 +1193,7 @@
out_path = options_.generate_java_class_path.value();
file::AppendPath(&out_path, file::PackageToPath(out_package));
if (!file::mkdirs(out_path)) {
- context_->GetDiagnostics()->Error(DiagMessage()
+ context_->GetDiagnostics()->Error(android::DiagMessage()
<< "failed to create directory '" << out_path << "'");
return false;
}
@@ -1192,8 +1202,9 @@
fout = util::make_unique<io::FileOutputStream>(out_path);
if (fout->HadError()) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed writing to '" << out_path
- << "': " << fout->GetError());
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed writing to '" << out_path
+ << "': " << fout->GetError());
return false;
}
}
@@ -1202,7 +1213,7 @@
if (out_text_symbols_path) {
fout_text = util::make_unique<io::FileOutputStream>(out_text_symbols_path.value());
if (fout_text->HadError()) {
- context_->GetDiagnostics()->Error(DiagMessage()
+ context_->GetDiagnostics()->Error(android::DiagMessage()
<< "failed writing to '" << out_text_symbols_path.value()
<< "': " << fout_text->GetError());
return false;
@@ -1211,7 +1222,7 @@
JavaClassGenerator generator(context_, table, java_options);
if (!generator.Generate(package_name_to_generate, out_package, fout.get(), fout_text.get())) {
- context_->GetDiagnostics()->Error(DiagMessage(out_path) << generator.GetError());
+ context_->GetDiagnostics()->Error(android::DiagMessage(out_path) << generator.GetError());
return false;
}
@@ -1335,8 +1346,8 @@
file::AppendPath(&out_path, file::PackageToPath(package_utf8));
if (!file::mkdirs(out_path)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed to create directory '" << out_path
- << "'");
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed to create directory '" << out_path << "'");
return false;
}
@@ -1344,8 +1355,8 @@
io::FileOutputStream fout(out_path);
if (fout.HadError()) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed to open '" << out_path
- << "': " << fout.GetError());
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed to open '" << out_path
+ << "': " << fout.GetError());
return false;
}
@@ -1354,8 +1365,8 @@
fout.Flush();
if (fout.HadError()) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed writing to '" << out_path
- << "': " << fout.GetError());
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed writing to '" << out_path
+ << "': " << fout.GetError());
return false;
}
return true;
@@ -1370,8 +1381,8 @@
const std::string& out_path = out.value();
io::FileOutputStream fout(out_path);
if (fout.HadError()) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed to open '" << out_path
- << "': " << fout.GetError());
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed to open '" << out_path
+ << "': " << fout.GetError());
return false;
}
@@ -1380,8 +1391,8 @@
fout.Flush();
if (fout.HadError()) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed writing to '" << out_path
- << "': " << fout.GetError());
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed writing to '" << out_path
+ << "': " << fout.GetError());
return false;
}
return true;
@@ -1390,12 +1401,13 @@
bool MergeStaticLibrary(const std::string& input, bool override) {
TRACE_CALL();
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage() << "merging static library " << input);
+ context_->GetDiagnostics()->Note(android::DiagMessage()
+ << "merging static library " << input);
}
std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(input, context_->GetDiagnostics());
if (apk == nullptr) {
- context_->GetDiagnostics()->Error(DiagMessage(input) << "invalid static library");
+ context_->GetDiagnostics()->Error(android::DiagMessage(input) << "invalid static library");
return false;
}
@@ -1406,7 +1418,7 @@
auto lib_package_result = GetStaticLibraryPackage(table);
if (!lib_package_result.has_value()) {
- context_->GetDiagnostics()->Error(DiagMessage(input) << lib_package_result.error());
+ context_->GetDiagnostics()->Error(android::DiagMessage(input) << lib_package_result.error());
return false;
}
@@ -1425,12 +1437,12 @@
// Clear the package name, so as to make the resources look like they are coming from the
// local package.
pkg->name = "";
- result = table_merger_->Merge(Source(input), table, override);
+ result = table_merger_->Merge(android::Source(input), table, override);
} else {
// This is the proper way to merge libraries, where the package name is
// preserved and resource names are mangled.
- result = table_merger_->MergeAndMangle(Source(input), pkg->name, table);
+ result = table_merger_->MergeAndMangle(android::Source(input), pkg->name, table);
}
if (!result) {
@@ -1442,7 +1454,7 @@
return true;
}
- bool MergeExportedSymbols(const Source& source,
+ bool MergeExportedSymbols(const android::Source& source,
const std::vector<SourcedResourceName>& exported_symbols) {
TRACE_CALL();
// Add the exports of this file to the table.
@@ -1472,7 +1484,7 @@
bool MergeCompiledFile(const ResourceFile& compiled_file, io::IFile* file, bool override) {
TRACE_CALL();
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage()
+ context_->GetDiagnostics()->Note(android::DiagMessage()
<< "merging '" << compiled_file.name
<< "' from compiled file " << compiled_file.source);
}
@@ -1491,14 +1503,14 @@
bool MergeArchive(const std::string& input, bool override) {
TRACE_CALL();
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage() << "merging archive " << input);
+ context_->GetDiagnostics()->Note(android::DiagMessage() << "merging archive " << input);
}
std::string error_str;
std::unique_ptr<io::ZipFileCollection> collection =
io::ZipFileCollection::Create(input, &error_str);
if (!collection) {
- context_->GetDiagnostics()->Error(DiagMessage(input) << error_str);
+ context_->GetDiagnostics()->Error(android::DiagMessage(input) << error_str);
return false;
}
@@ -1538,31 +1550,32 @@
// where we could have other files like classes.dex.
bool MergeFile(io::IFile* file, bool override) {
TRACE_CALL();
- const Source& src = file->GetSource();
+ const android::Source& src = file->GetSource();
if (util::EndsWith(src.path, ".xml") || util::EndsWith(src.path, ".png")) {
// Since AAPT compiles these file types and appends .flat to them, seeing
// their raw extensions is a sign that they weren't compiled.
const StringPiece file_type = util::EndsWith(src.path, ".xml") ? "XML" : "PNG";
- context_->GetDiagnostics()->Error(DiagMessage(src) << "uncompiled " << file_type
- << " file passed as argument. Must be "
- "compiled first into .flat file.");
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
+ << "uncompiled " << file_type
+ << " file passed as argument. Must be "
+ "compiled first into .flat file.");
return false;
} else if (!util::EndsWith(src.path, ".apc") && !util::EndsWith(src.path, ".flat")) {
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Warn(DiagMessage(src) << "ignoring unrecognized file");
+ context_->GetDiagnostics()->Warn(android::DiagMessage(src) << "ignoring unrecognized file");
return true;
}
}
std::unique_ptr<io::InputStream> input_stream = file->OpenInputStream();
if (input_stream == nullptr) {
- context_->GetDiagnostics()->Error(DiagMessage(src) << "failed to open file");
+ context_->GetDiagnostics()->Error(android::DiagMessage(src) << "failed to open file");
return false;
}
if (input_stream->HadError()) {
- context_->GetDiagnostics()->Error(DiagMessage(src)
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
<< "failed to open file: " << input_stream->GetError());
return false;
}
@@ -1571,7 +1584,7 @@
ContainerReader reader(input_stream.get());
if (reader.HadError()) {
- context_->GetDiagnostics()->Error(DiagMessage(src)
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
<< "failed to read file: " << reader.GetError());
return false;
}
@@ -1581,21 +1594,22 @@
TRACE_NAME(std::string("Process ResTable:") + file->GetSource().path);
pb::ResourceTable pb_table;
if (!entry->GetResTable(&pb_table)) {
- context_->GetDiagnostics()->Error(DiagMessage(src) << "failed to read resource table: "
- << entry->GetError());
+ context_->GetDiagnostics()->Error(
+ android::DiagMessage(src) << "failed to read resource table: " << entry->GetError());
return false;
}
ResourceTable table;
std::string error;
if (!DeserializeTableFromPb(pb_table, nullptr /*files*/, &table, &error)) {
- context_->GetDiagnostics()->Error(DiagMessage(src)
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
<< "failed to deserialize resource table: " << error);
return false;
}
if (!table_merger_->Merge(src, &table, override)) {
- context_->GetDiagnostics()->Error(DiagMessage(src) << "failed to merge resource table");
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
+ << "failed to merge resource table");
return false;
}
} else if (entry->Type() == ContainerEntryType::kResFile) {
@@ -1604,15 +1618,15 @@
off64_t offset;
size_t len;
if (!entry->GetResFileOffsets(&pb_compiled_file, &offset, &len)) {
- context_->GetDiagnostics()->Error(DiagMessage(src) << "failed to get resource file: "
- << entry->GetError());
+ context_->GetDiagnostics()->Error(
+ android::DiagMessage(src) << "failed to get resource file: " << entry->GetError());
return false;
}
ResourceFile resource_file;
std::string error;
if (!DeserializeCompiledFileFromPb(pb_compiled_file, &resource_file, &error)) {
- context_->GetDiagnostics()->Error(DiagMessage(src)
+ context_->GetDiagnostics()->Error(android::DiagMessage(src)
<< "failed to read compiled header: " << error);
return false;
}
@@ -1641,10 +1655,10 @@
auto iter = merged_assets.find(full_key);
if (iter == merged_assets.end()) {
- merged_assets.emplace(std::move(full_key),
- util::make_unique<io::RegularFile>(Source(std::move(full_path))));
+ merged_assets.emplace(std::move(full_key), util::make_unique<io::RegularFile>(
+ android::Source(std::move(full_path))));
} else if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Warn(DiagMessage(iter->second->GetSource())
+ context_->GetDiagnostics()->Warn(android::DiagMessage(iter->second->GetSource())
<< "asset file overrides '" << full_path << "'");
}
}
@@ -1729,10 +1743,10 @@
continue;
}
- context_->GetDiagnostics()->Note(DiagMessage() << "generating "
- << round_icon_reference->name.value()
- << " with config \"" << config_value->config
- << "\" for round icon compatibility");
+ context_->GetDiagnostics()->Note(android::DiagMessage()
+ << "generating " << round_icon_reference->name.value()
+ << " with config \"" << config_value->config
+ << "\" for round icon compatibility");
CloningValueTransformer cloner(&table->string_pool);
auto value = icon_reference->Transform(cloner);
@@ -1758,7 +1772,7 @@
if (util::IsAndroidSharedUserId(context_->GetCompilationPackage(), shared_user_id)) {
return true;
}
- DiagMessage error_msg(manifest_el->line_number);
+ android::DiagMessage error_msg(manifest_el->line_number);
error_msg << "attribute 'sharedUserId' in <manifest> tag is not a valid shared user id: '"
<< shared_user_id << "'";
if (options_.manifest_fixer_options.warn_validation) {
@@ -1834,7 +1848,7 @@
ResourceFileFlattener file_flattener(file_flattener_options, context_, keep_set);
if (!file_flattener.Flatten(table, writer)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed linking file resources");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed linking file resources");
return false;
}
@@ -1865,8 +1879,8 @@
if (context_->IsVerbose()) {
context_->GetDiagnostics()->Note(
- DiagMessage() << "rewriting resource package name for feature split to '"
- << new_package_name << "'");
+ android::DiagMessage() << "rewriting resource package name for feature split to '"
+ << new_package_name << "'");
}
package_to_rewrite->name = new_package_name;
}
@@ -1886,7 +1900,7 @@
}
if (!success) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed to write resource table");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed to write resource table");
}
return success;
}
@@ -1947,7 +1961,7 @@
// Verify we're building a regular app.
if (context_->GetPackageType() != PackageType::kApp) {
context_->GetDiagnostics()->Error(
- DiagMessage() << "package 'android' can only be built as a regular app");
+ android::DiagMessage() << "package 'android' can only be built as a regular app");
return 1;
}
}
@@ -1960,7 +1974,7 @@
table_merger_ = util::make_unique<TableMerger>(context_, &final_table_, table_merger_options);
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage()
+ context_->GetDiagnostics()->Note(android::DiagMessage()
<< StringPrintf("linking package '%s' using package ID %02x",
context_->GetCompilationPackage().data(),
context_->GetPackageId()));
@@ -1981,14 +1995,14 @@
for (const std::string& input : input_files) {
if (!MergePath(input, false)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed parsing input");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed parsing input");
return 1;
}
}
for (const std::string& input : options_.overlay_files) {
if (!MergePath(input, true)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed parsing overlays");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed parsing overlays");
return 1;
}
}
@@ -2001,14 +2015,15 @@
PrivateAttributeMover mover;
if (context_->GetPackageId() == kAndroidPackageId &&
!mover.Consume(context_, &final_table_)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed moving private attributes");
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed moving private attributes");
return 1;
}
// Assign IDs if we are building a regular app.
IdAssigner id_assigner(&options_.stable_id_map);
if (!id_assigner.Consume(context_, &final_table_)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed assigning IDs");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed assigning IDs");
return 1;
}
@@ -2052,7 +2067,7 @@
// are just identifiers.
if (context_->GetMinSdkVersion() < SDK_O && context_->GetPackageType() == PackageType::kApp) {
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage()
+ context_->GetDiagnostics()->Note(android::DiagMessage()
<< "enabling pre-O feature split ID rewriting");
}
context_->GetExternalSymbols()->SetDelegate(
@@ -2063,7 +2078,7 @@
// We want to force any references to these to fail the build.
if (!options_.no_resource_removal) {
if (!NoDefaultResourceRemover{}.Consume(context_, &final_table_)) {
- context_->GetDiagnostics()->Error(DiagMessage()
+ context_->GetDiagnostics()->Error(android::DiagMessage()
<< "failed removing resources with no defaults");
return 1;
}
@@ -2071,19 +2086,19 @@
ReferenceLinker linker;
if (!options_.merge_only && !linker.Consume(context_, &final_table_)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed linking references");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed linking references");
return 1;
}
if (context_->GetPackageType() == PackageType::kStaticLib) {
if (!options_.products.empty()) {
- context_->GetDiagnostics()->Warn(DiagMessage()
+ context_->GetDiagnostics()->Warn(android::DiagMessage()
<< "can't select products when building static library");
}
} else {
ProductFilter product_filter(options_.products);
if (!product_filter.Consume(context_, &final_table_)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed stripping products");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed stripping products");
return 1;
}
}
@@ -2091,14 +2106,14 @@
if (!options_.no_auto_version) {
AutoVersioner versioner;
if (!versioner.Consume(context_, &final_table_)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed versioning styles");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed versioning styles");
return 1;
}
}
if (context_->GetPackageType() != PackageType::kStaticLib && context_->GetMinSdkVersion() > 0) {
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage()
+ context_->GetDiagnostics()->Note(android::DiagMessage()
<< "collapsing resource versions for minimum SDK "
<< context_->GetMinSdkVersion());
}
@@ -2117,9 +2132,8 @@
ConfigDescription config_description;
if (!ConfigDescription::Parse(config_string, &config_description)) {
- context_->GetDiagnostics()->Error(DiagMessage()
- << "failed to parse --excluded-configs "
- << config_string);
+ context_->GetDiagnostics()->Error(
+ android::DiagMessage() << "failed to parse --excluded-configs " << config_string);
return 1;
}
@@ -2128,7 +2142,8 @@
ResourceExcluder excluder(excluded_configs);
if (!excluder.Consume(context_, &final_table_)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed excluding configurations");
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed excluding configurations");
return 1;
}
}
@@ -2136,7 +2151,7 @@
if (!options_.no_resource_deduping) {
ResourceDeduper deduper;
if (!deduper.Consume(context_, &final_table_)) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed deduping resources");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed deduping resources");
return 1;
}
}
@@ -2148,7 +2163,7 @@
if (context_->GetPackageType() == PackageType::kStaticLib) {
if (options_.table_splitter_options.config_filter != nullptr ||
!options_.table_splitter_options.preferred_densities.empty()) {
- context_->GetDiagnostics()->Warn(DiagMessage()
+ context_->GetDiagnostics()->Warn(android::DiagMessage()
<< "can't strip resources when building static library");
}
} else {
@@ -2159,7 +2174,7 @@
AdjustSplitConstraintsForMinSdk(context_->GetMinSdkVersion(), options_.split_constraints);
if (origConstraintSize != options_.split_constraints.size()) {
- context_->GetDiagnostics()->Warn(DiagMessage()
+ context_->GetDiagnostics()->Warn(android::DiagMessage()
<< "requested to split resources prior to min sdk of "
<< context_->GetMinSdkVersion());
}
@@ -2174,7 +2189,7 @@
auto split_constraints_iter = options_.split_constraints.begin();
for (std::unique_ptr<ResourceTable>& split_table : table_splitter.splits()) {
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage(*path_iter)
+ context_->GetDiagnostics()->Note(android::DiagMessage(*path_iter)
<< "generating split with configurations '"
<< util::Joiner(split_constraints_iter->configs, ", ")
<< "'");
@@ -2182,7 +2197,7 @@
std::unique_ptr<IArchiveWriter> archive_writer = MakeArchiveWriter(*path_iter);
if (!archive_writer) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed to create archive");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed to create archive");
return 1;
}
@@ -2192,7 +2207,7 @@
XmlReferenceLinker linker(&final_table_);
if (!linker.Consume(context_, split_manifest.get())) {
- context_->GetDiagnostics()->Error(DiagMessage()
+ context_->GetDiagnostics()->Error(android::DiagMessage()
<< "failed to create Split AndroidManifest.xml");
return 1;
}
@@ -2210,7 +2225,7 @@
// Start writing the base APK.
std::unique_ptr<IArchiveWriter> archive_writer = MakeArchiveWriter(options_.output_path);
if (!archive_writer) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed to create archive");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed to create archive");
return 1;
}
@@ -2254,7 +2269,7 @@
}
if (error) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed processing manifest");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed processing manifest");
return 1;
}
@@ -2327,7 +2342,7 @@
const std::string path = arg.substr(1, arg.size() - 1);
std::string error;
if (!file::AppendArgsFromFile(path, &arg_list, &error)) {
- context.GetDiagnostics()->Error(DiagMessage(path) << error);
+ context.GetDiagnostics()->Error(android::DiagMessage(path) << error);
return 1;
}
} else {
@@ -2341,7 +2356,7 @@
const std::string path = arg.substr(1, arg.size() - 1);
std::string error;
if (!file::AppendArgsFromFile(path, &options_.overlay_files, &error)) {
- context.GetDiagnostics()->Error(DiagMessage(path) << error);
+ context.GetDiagnostics()->Error(android::DiagMessage(path) << error);
return 1;
}
} else {
@@ -2354,9 +2369,9 @@
}
if (int{shared_lib_} + int{static_lib_} + int{proto_format_} > 1) {
- context.GetDiagnostics()->Error(
- DiagMessage()
- << "only one of --shared-lib, --static-lib, or --proto_format can be defined");
+ context.GetDiagnostics()
+ ->Error(android::DiagMessage()
+ << "only one of --shared-lib, --static-lib, or --proto_format can be defined");
return 1;
}
@@ -2364,15 +2379,16 @@
// If a shared library styleable in a public R.java uses a private attribute, attempting to
// reference the private attribute within the styleable array will cause a link error because
// the private attribute will not be emitted in the public R.java.
- context.GetDiagnostics()->Error(DiagMessage()
+ context.GetDiagnostics()->Error(android::DiagMessage()
<< "--shared-lib cannot currently be used in combination with"
<< " --private-symbols");
return 1;
}
if (options_.merge_only && !static_lib_) {
- context.GetDiagnostics()->Error(
- DiagMessage() << "the --merge-only flag can be only used when building a static library");
+ context.GetDiagnostics()
+ ->Error(android::DiagMessage()
+ << "the --merge-only flag can be only used when building a static library");
return 1;
}
@@ -2393,15 +2409,16 @@
if (package_id_) {
if (context.GetPackageType() != PackageType::kApp) {
context.GetDiagnostics()->Error(
- DiagMessage() << "can't specify --package-id when not building a regular app");
+ android::DiagMessage() << "can't specify --package-id when not building a regular app");
return 1;
}
const std::optional<uint32_t> maybe_package_id_int =
ResourceUtils::ParseInt(package_id_.value());
if (!maybe_package_id_int) {
- context.GetDiagnostics()->Error(DiagMessage() << "package ID '" << package_id_.value()
- << "' is not a valid integer");
+ context.GetDiagnostics()->Error(android::DiagMessage()
+ << "package ID '" << package_id_.value()
+ << "' is not a valid integer");
return 1;
}
@@ -2410,7 +2427,7 @@
|| package_id_int == kFrameworkPackageId
|| (!options_.allow_reserved_package_id && package_id_int < kAppPackageId)) {
context.GetDiagnostics()->Error(
- DiagMessage() << StringPrintf(
+ android::DiagMessage() << StringPrintf(
"invalid package ID 0x%02x. Must be in the range 0x7f-0xff.", package_id_int));
return 1;
}
@@ -2474,7 +2491,7 @@
const std::string path = regex.substr(1, regex.size() -1);
std::string error;
if (!file::AppendSetArgsFromFile(path, &options_.extensions_to_not_compress, &error)) {
- context.GetDiagnostics()->Error(DiagMessage(path) << error);
+ context.GetDiagnostics()->Error(android::DiagMessage(path) << error);
return 1;
}
} else {
diff --git a/tools/aapt2/cmd/Link.h b/tools/aapt2/cmd/Link.h
index d8c76e2..a5623cb 100644
--- a/tools/aapt2/cmd/Link.h
+++ b/tools/aapt2/cmd/Link.h
@@ -20,12 +20,12 @@
#include <regex>
#include "Command.h"
-#include "Diagnostics.h"
#include "Resource.h"
-#include "split/TableSplitter.h"
+#include "androidfw/IDiagnostics.h"
#include "format/binary/TableFlattener.h"
#include "format/proto/ProtoSerialize.h"
#include "link/ManifestFixer.h"
+#include "split/TableSplitter.h"
#include "trace/TraceBuffer.h"
namespace aapt {
@@ -111,8 +111,7 @@
class LinkCommand : public Command {
public:
- explicit LinkCommand(IDiagnostics* diag) : Command("link", "l"),
- diag_(diag) {
+ explicit LinkCommand(android::IDiagnostics* diag) : Command("link", "l"), diag_(diag) {
SetDescription("Links resources into an apk.");
AddRequiredFlag("-o", "Output path.", &options_.output_path, Command::kPath);
AddRequiredFlag("--manifest", "Path to the Android manifest to build.",
@@ -316,7 +315,7 @@
int Action(const std::vector<std::string>& args) override;
private:
- IDiagnostics* diag_;
+ android::IDiagnostics* diag_;
LinkOptions options_;
std::vector<std::string> overlay_arg_list_;
diff --git a/tools/aapt2/cmd/Link_test.cpp b/tools/aapt2/cmd/Link_test.cpp
index 7b1236a..683ccad 100644
--- a/tools/aapt2/cmd/Link_test.cpp
+++ b/tools/aapt2/cmd/Link_test.cpp
@@ -19,6 +19,7 @@
#include <android-base/file.h>
#include "AppInfo.h"
+#include "Diagnostics.h"
#include "LoadedApk.h"
#include "test/Test.h"
@@ -87,7 +88,8 @@
// Check that the raw string index has been set to the correct string pool entry
int32_t raw_index = tree.getAttributeValueStringID(0);
ASSERT_THAT(raw_index, Ne(-1));
- EXPECT_THAT(util::GetString(tree.getStrings(), static_cast<size_t>(raw_index)), Eq("007"));
+ EXPECT_THAT(android::util::GetString(tree.getStrings(), static_cast<size_t>(raw_index)),
+ Eq("007"));
}
TEST_F(LinkTest, NoCompressAssets) {
@@ -410,7 +412,7 @@
static void BuildApk(const std::vector<SourceXML>& source_files, const std::string& apk_path,
LinkCommandBuilder&& link_args, CommandTestFixture* fixture,
- IDiagnostics* diag) {
+ android::IDiagnostics* diag) {
TemporaryDir res_dir;
TemporaryDir compiled_res_dir;
for (auto& source_file : source_files) {
@@ -423,7 +425,7 @@
static void BuildSDK(const std::vector<SourceXML>& source_files, const std::string& apk_path,
const std::string& java_root_path, CommandTestFixture* fixture,
- IDiagnostics* diag) {
+ android::IDiagnostics* diag) {
auto android_manifest = ManifestBuilder(fixture).SetPackageName("android").Build();
auto android_link_args = LinkCommandBuilder(fixture)
@@ -435,7 +437,7 @@
}
static void BuildNonFinalizedSDK(const std::string& apk_path, const std::string& java_path,
- CommandTestFixture* fixture, IDiagnostics* diag) {
+ CommandTestFixture* fixture, android::IDiagnostics* diag) {
const std::string android_values =
R"(<resources>
<public type="attr" name="finalized_res" id="0x01010001"/>
@@ -471,7 +473,7 @@
}
static void BuildFinalizedSDK(const std::string& apk_path, const std::string& java_path,
- CommandTestFixture* fixture, IDiagnostics* diag) {
+ CommandTestFixture* fixture, android::IDiagnostics* diag) {
const std::string android_values =
R"(<resources>
<public type="attr" name="finalized_res" id="0x01010001"/>
@@ -511,7 +513,7 @@
static void BuildAppAgainstSDK(const std::string& apk_path, const std::string& java_path,
const std::string& sdk_path, CommandTestFixture* fixture,
- IDiagnostics* diag) {
+ android::IDiagnostics* diag) {
const std::string app_values =
R"(<resources xmlns:android="http://schemas.android.com/apk/res/android">
<attr name="bar" />
diff --git a/tools/aapt2/cmd/Optimize.cpp b/tools/aapt2/cmd/Optimize.cpp
index e1370fd..4033983 100644
--- a/tools/aapt2/cmd/Optimize.cpp
+++ b/tools/aapt2/cmd/Optimize.cpp
@@ -19,18 +19,17 @@
#include <memory>
#include <vector>
-#include "android-base/file.h"
-#include "android-base/stringprintf.h"
-
-#include "androidfw/ConfigDescription.h"
-#include "androidfw/ResourceTypes.h"
-#include "androidfw/StringPiece.h"
-
#include "Diagnostics.h"
#include "LoadedApk.h"
#include "ResourceUtils.h"
#include "SdkConstants.h"
#include "ValueVisitor.h"
+#include "android-base/file.h"
+#include "android-base/stringprintf.h"
+#include "androidfw/ConfigDescription.h"
+#include "androidfw/IDiagnostics.h"
+#include "androidfw/ResourceTypes.h"
+#include "androidfw/StringPiece.h"
#include "cmd/Util.h"
#include "configuration/ConfigurationParser.h"
#include "filter/AbiFilter.h"
@@ -69,7 +68,7 @@
return PackageType::kApp;
}
- IDiagnostics* GetDiagnostics() override {
+ android::IDiagnostics* GetDiagnostics() override {
return &diagnostics_;
}
@@ -130,12 +129,12 @@
int Run(std::unique_ptr<LoadedApk> apk) {
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(DiagMessage() << "Optimizing APK...");
+ context_->GetDiagnostics()->Note(android::DiagMessage() << "Optimizing APK...");
}
if (!options_.resources_exclude_list.empty()) {
ResourceFilter filter(options_.resources_exclude_list);
if (!filter.Consume(context_, apk->GetResourceTable())) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed filtering resources");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed filtering resources");
return 1;
}
}
@@ -147,20 +146,21 @@
ResourceDeduper deduper;
if (!deduper.Consume(context_, apk->GetResourceTable())) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed deduping resources");
+ context_->GetDiagnostics()->Error(android::DiagMessage() << "failed deduping resources");
return 1;
}
if (options_.shorten_resource_paths) {
ResourcePathShortener shortener(options_.table_flattener_options.shortened_path_map);
if (!shortener.Consume(context_, apk->GetResourceTable())) {
- context_->GetDiagnostics()->Error(DiagMessage() << "failed shortening resource paths");
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed shortening resource paths");
return 1;
}
if (options_.shortened_paths_map_path
&& !WriteShortenedPathsMap(options_.table_flattener_options.shortened_path_map,
options_.shortened_paths_map_path.value())) {
- context_->GetDiagnostics()->Error(DiagMessage()
+ context_->GetDiagnostics()->Error(android::DiagMessage()
<< "failed to write shortened resource paths to file");
return 1;
}
@@ -183,9 +183,10 @@
auto split_constraints_iter = options_.split_constraints.begin();
for (std::unique_ptr<ResourceTable>& split_table : splitter.splits()) {
if (context_->IsVerbose()) {
- context_->GetDiagnostics()->Note(
- DiagMessage(*path_iter) << "generating split with configurations '"
- << util::Joiner(split_constraints_iter->configs, ", ") << "'");
+ context_->GetDiagnostics()->Note(android::DiagMessage(*path_iter)
+ << "generating split with configurations '"
+ << util::Joiner(split_constraints_iter->configs, ", ")
+ << "'");
}
// Generate an AndroidManifest.xml for each split.
@@ -228,7 +229,7 @@
private:
bool WriteSplitApk(ResourceTable* table, xml::XmlResource* manifest, IArchiveWriter* writer) {
- BigBuffer manifest_buffer(4096);
+ android::BigBuffer manifest_buffer(4096);
XmlFlattener xml_flattener(&manifest_buffer, {});
if (!xml_flattener.Consume(context_, manifest)) {
return false;
@@ -255,7 +256,7 @@
if (file_ref->file == nullptr) {
ResourceNameRef name(pkg->name, type->named_type, entry->name);
- context_->GetDiagnostics()->Warn(DiagMessage(file_ref->GetSource())
+ context_->GetDiagnostics()->Warn(android::DiagMessage(file_ref->GetSource())
<< "file for resource " << name << " with config '"
<< config_value->config << "' not found");
continue;
@@ -276,7 +277,7 @@
}
}
- BigBuffer table_buffer(4096);
+ android::BigBuffer table_buffer(4096);
TableFlattener table_flattener(options_.table_flattener_options, &table_buffer);
if (!table_flattener.Consume(context_, table)) {
return false;
@@ -311,18 +312,18 @@
auto split_line = util::Split(line, '#');
if (split_line.size() < 2) {
- context->GetDiagnostics()->Error(DiagMessage(line) << "No # found in line");
+ context->GetDiagnostics()->Error(android::DiagMessage(line) << "No # found in line");
return false;
}
StringPiece resource_string = split_line[0];
StringPiece directives = split_line[1];
ResourceNameRef resource_name;
if (!ResourceUtils::ParseResourceName(resource_string, &resource_name)) {
- context->GetDiagnostics()->Error(DiagMessage(line) << "Malformed resource name");
+ context->GetDiagnostics()->Error(android::DiagMessage(line) << "Malformed resource name");
return false;
}
if (!resource_name.package.empty()) {
- context->GetDiagnostics()->Error(DiagMessage(line)
+ context->GetDiagnostics()->Error(android::DiagMessage(line)
<< "Package set for resource. Only use type/name");
return false;
}
@@ -341,7 +342,7 @@
bool ExtractConfig(const std::string& path, IAaptContext* context, OptimizeOptions* options) {
std::string content;
if (!android::base::ReadFileToString(path, &content, true /*follow_symlinks*/)) {
- context->GetDiagnostics()->Error(DiagMessage(path) << "failed reading config file");
+ context->GetDiagnostics()->Error(android::DiagMessage(path) << "failed reading config file");
return false;
}
return ParseConfig(content, context, options);
@@ -356,7 +357,7 @@
auto app_info = ExtractAppInfoFromBinaryManifest(*manifest, context->GetDiagnostics());
if (!app_info) {
- context->GetDiagnostics()->Error(DiagMessage()
+ context->GetDiagnostics()->Error(android::DiagMessage()
<< "failed to extract data from AndroidManifest.xml");
return false;
}
@@ -376,7 +377,7 @@
const std::string& apk_path = args[0];
OptimizeContext context;
context.SetVerbose(verbose_);
- IDiagnostics* diag = context.GetDiagnostics();
+ android::IDiagnostics* diag = context.GetDiagnostics();
if (config_path_) {
std::string& path = config_path_.value();
@@ -384,12 +385,12 @@
if (for_path) {
options_.apk_artifacts = for_path.value().WithDiagnostics(diag).Parse(apk_path);
if (!options_.apk_artifacts) {
- diag->Error(DiagMessage() << "Failed to parse the output artifact list");
+ diag->Error(android::DiagMessage() << "Failed to parse the output artifact list");
return 1;
}
} else {
- diag->Error(DiagMessage() << "Could not parse config file " << path);
+ diag->Error(android::DiagMessage() << "Could not parse config file " << path);
return 1;
}
@@ -411,11 +412,13 @@
// Since we know that we are going to process the APK (not just print targets), make sure we
// have somewhere to write them to.
if (!options_.output_dir) {
- diag->Error(DiagMessage() << "Output directory is required when using a configuration file");
+ diag->Error(android::DiagMessage()
+ << "Output directory is required when using a configuration file");
return 1;
}
} else if (print_only_) {
- diag->Error(DiagMessage() << "Asked to print artifacts without providing a configurations");
+ diag->Error(android::DiagMessage()
+ << "Asked to print artifacts without providing a configurations");
return 1;
}
diff --git a/tools/aapt2/cmd/Optimize_test.cpp b/tools/aapt2/cmd/Optimize_test.cpp
index ac681e8..d180c87 100644
--- a/tools/aapt2/cmd/Optimize_test.cpp
+++ b/tools/aapt2/cmd/Optimize_test.cpp
@@ -17,9 +17,9 @@
#include "Optimize.h"
#include "AppInfo.h"
-#include "Diagnostics.h"
#include "LoadedApk.h"
#include "Resource.h"
+#include "androidfw/IDiagnostics.h"
#include "test/Test.h"
using testing::Contains;
diff --git a/tools/aapt2/cmd/Util.cpp b/tools/aapt2/cmd/Util.cpp
index 3244fb8..c3a6ed1 100644
--- a/tools/aapt2/cmd/Util.cpp
+++ b/tools/aapt2/cmd/Util.cpp
@@ -34,10 +34,12 @@
namespace aapt {
-std::optional<uint16_t> ParseTargetDensityParameter(const StringPiece& arg, IDiagnostics* diag) {
+std::optional<uint16_t> ParseTargetDensityParameter(const StringPiece& arg,
+ android::IDiagnostics* diag) {
ConfigDescription preferred_density_config;
if (!ConfigDescription::Parse(arg, &preferred_density_config)) {
- diag->Error(DiagMessage() << "invalid density '" << arg << "' for --preferred-density option");
+ diag->Error(android::DiagMessage()
+ << "invalid density '" << arg << "' for --preferred-density option");
return {};
}
@@ -46,14 +48,14 @@
if (preferred_density_config.diff(ConfigDescription::DefaultConfig()) !=
ConfigDescription::CONFIG_DENSITY) {
- diag->Error(DiagMessage() << "invalid preferred density '" << arg << "'. "
- << "Preferred density must only be a density value");
+ diag->Error(android::DiagMessage() << "invalid preferred density '" << arg << "'. "
+ << "Preferred density must only be a density value");
return {};
}
return preferred_density_config.density;
}
-bool ParseSplitParameter(const StringPiece& arg, IDiagnostics* diag, std::string* out_path,
+bool ParseSplitParameter(const StringPiece& arg, android::IDiagnostics* diag, std::string* out_path,
SplitConstraints* out_split) {
CHECK(diag != nullptr);
CHECK(out_path != nullptr);
@@ -67,9 +69,9 @@
std::vector<std::string> parts = util::Split(arg, sSeparator);
if (parts.size() != 2) {
- diag->Error(DiagMessage() << "invalid split parameter '" << arg << "'");
- diag->Note(DiagMessage() << "should be --split path/to/output.apk" << sSeparator
- << "<config>[,<config>...].");
+ diag->Error(android::DiagMessage() << "invalid split parameter '" << arg << "'");
+ diag->Note(android::DiagMessage() << "should be --split path/to/output.apk" << sSeparator
+ << "<config>[,<config>...].");
return false;
}
@@ -78,8 +80,8 @@
for (const StringPiece& config_str : util::Tokenize(parts[1], ',')) {
ConfigDescription config;
if (!ConfigDescription::Parse(config_str, &config)) {
- diag->Error(DiagMessage() << "invalid config '" << config_str << "' in split parameter '"
- << arg << "'");
+ diag->Error(android::DiagMessage()
+ << "invalid config '" << config_str << "' in split parameter '" << arg << "'");
return false;
}
out_split->configs.insert(config);
@@ -88,7 +90,7 @@
}
std::unique_ptr<IConfigFilter> ParseConfigFilterParameters(const std::vector<std::string>& args,
- IDiagnostics* diag) {
+ android::IDiagnostics* diag) {
std::unique_ptr<AxisConfigFilter> filter = util::make_unique<AxisConfigFilter>();
for (const std::string& config_arg : args) {
for (const StringPiece& config_str : util::Tokenize(config_arg, ',')) {
@@ -97,12 +99,13 @@
if (lv.InitFromFilterString(config_str)) {
lv.WriteTo(&config);
} else if (!ConfigDescription::Parse(config_str, &config)) {
- diag->Error(DiagMessage() << "invalid config '" << config_str << "' for -c option");
+ diag->Error(android::DiagMessage()
+ << "invalid config '" << config_str << "' for -c option");
return {};
}
if (config.density != 0) {
- diag->Warn(DiagMessage() << "ignoring density '" << config << "' for -c option");
+ diag->Warn(android::DiagMessage() << "ignoring density '" << config << "' for -c option");
} else {
filter->AddConfig(config);
}
@@ -331,7 +334,7 @@
}
std::optional<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
- IDiagnostics* diag) {
+ android::IDiagnostics* diag) {
// Make sure the first element is <manifest> with package attribute.
const xml::Element* manifest_el = xml_res.root.get();
if (manifest_el == nullptr) {
@@ -341,20 +344,21 @@
AppInfo app_info;
if (!manifest_el->namespace_uri.empty() || manifest_el->name != "manifest") {
- diag->Error(DiagMessage(xml_res.file.source) << "root tag must be <manifest>");
+ diag->Error(android::DiagMessage(xml_res.file.source) << "root tag must be <manifest>");
return {};
}
const xml::Attribute* package_attr = manifest_el->FindAttribute({}, "package");
if (!package_attr) {
- diag->Error(DiagMessage(xml_res.file.source) << "<manifest> must have a 'package' attribute");
+ diag->Error(android::DiagMessage(xml_res.file.source)
+ << "<manifest> must have a 'package' attribute");
return {};
}
std::string error_msg;
std::optional<std::string> maybe_package = ExtractCompiledString(*package_attr, &error_msg);
if (!maybe_package) {
- diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
+ diag->Error(android::DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
<< "invalid package name: " << error_msg);
return {};
}
@@ -364,7 +368,7 @@
manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCode")) {
std::optional<uint32_t> maybe_code = ExtractCompiledInt(*version_code_attr, &error_msg);
if (!maybe_code) {
- diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
+ diag->Error(android::DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
<< "invalid android:versionCode: " << error_msg);
return {};
}
@@ -375,8 +379,8 @@
manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCodeMajor")) {
std::optional<uint32_t> maybe_code = ExtractCompiledInt(*version_code_major_attr, &error_msg);
if (!maybe_code) {
- diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
- << "invalid android:versionCodeMajor: " << error_msg);
+ diag->Error(android::DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
+ << "invalid android:versionCodeMajor: " << error_msg);
return {};
}
app_info.version_code_major = maybe_code.value();
@@ -386,7 +390,7 @@
manifest_el->FindAttribute(xml::kSchemaAndroid, "revisionCode")) {
std::optional<uint32_t> maybe_code = ExtractCompiledInt(*revision_code_attr, &error_msg);
if (!maybe_code) {
- diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
+ diag->Error(android::DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
<< "invalid android:revisionCode: " << error_msg);
return {};
}
@@ -397,7 +401,7 @@
std::optional<std::string> maybe_split_name =
ExtractCompiledString(*split_name_attr, &error_msg);
if (!maybe_split_name) {
- diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
+ diag->Error(android::DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
<< "invalid split name: " << error_msg);
return {};
}
@@ -409,7 +413,7 @@
uses_sdk_el->FindAttribute(xml::kSchemaAndroid, "minSdkVersion")) {
std::optional<int> maybe_sdk = ExtractSdkVersion(*min_sdk, &error_msg);
if (!maybe_sdk) {
- diag->Error(DiagMessage(xml_res.file.source.WithLine(uses_sdk_el->line_number))
+ diag->Error(android::DiagMessage(xml_res.file.source.WithLine(uses_sdk_el->line_number))
<< "invalid android:minSdkVersion: " << error_msg);
return {};
}
diff --git a/tools/aapt2/cmd/Util.h b/tools/aapt2/cmd/Util.h
index 1b98eb4..7af27f5 100644
--- a/tools/aapt2/cmd/Util.h
+++ b/tools/aapt2/cmd/Util.h
@@ -19,11 +19,10 @@
#include <regex>
-#include "androidfw/StringPiece.h"
-
#include "AppInfo.h"
-#include "Diagnostics.h"
#include "SdkConstants.h"
+#include "androidfw/IDiagnostics.h"
+#include "androidfw/StringPiece.h"
#include "filter/ConfigFilter.h"
#include "split/TableSplitter.h"
#include "xml/XmlDom.h"
@@ -33,18 +32,18 @@
// Parses a configuration density (ex. hdpi, xxhdpi, 234dpi, anydpi, etc).
// Returns Nothing and logs a human friendly error message if the string was not legal.
std::optional<uint16_t> ParseTargetDensityParameter(const android::StringPiece& arg,
- IDiagnostics* diag);
+ android::IDiagnostics* diag);
// Parses a string of the form 'path/to/output.apk:<config>[,<config>...]' and fills in
// `out_path` with the path and `out_split` with the set of ConfigDescriptions.
// Returns false and logs a human friendly error message if the string was not legal.
-bool ParseSplitParameter(const android::StringPiece& arg, IDiagnostics* diag, std::string* out_path,
- SplitConstraints* out_split);
+bool ParseSplitParameter(const android::StringPiece& arg, android::IDiagnostics* diag,
+ std::string* out_path, SplitConstraints* out_split);
// Parses a set of config filter strings of the form 'en,fr-rFR' and returns an IConfigFilter.
// Returns nullptr and logs a human friendly error message if the string was not legal.
std::unique_ptr<IConfigFilter> ParseConfigFilterParameters(const std::vector<std::string>& args,
- IDiagnostics* diag);
+ android::IDiagnostics* diag);
// Adjust the SplitConstraints so that their SDK version is stripped if it
// is less than or equal to the min_sdk. Otherwise the resources that have had
@@ -60,7 +59,7 @@
// Extracts relevant info from the AndroidManifest.xml.
std::optional<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
- IDiagnostics* diag);
+ android::IDiagnostics* diag);
// Returns a copy of 'name' which conforms to the regex '[a-zA-Z]+[a-zA-Z0-9_]*' by
// replacing nonconforming characters with underscores.
diff --git a/tools/aapt2/cmd/Util_test.cpp b/tools/aapt2/cmd/Util_test.cpp
index ac1f981..91accfe 100644
--- a/tools/aapt2/cmd/Util_test.cpp
+++ b/tools/aapt2/cmd/Util_test.cpp
@@ -102,7 +102,7 @@
TEST (UtilTest, ParseSplitParameters) {
- IDiagnostics* diagnostics = test::ContextBuilder().Build().get()->GetDiagnostics();
+ android::IDiagnostics* diagnostics = test::ContextBuilder().Build().get()->GetDiagnostics();
std::string path;
SplitConstraints constraints;
ConfigDescription expected_configuration;
@@ -356,7 +356,7 @@
TEST (UtilTest, AdjustSplitConstraintsForMinSdk) {
std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
- IDiagnostics* diagnostics = context.get()->GetDiagnostics();
+ android::IDiagnostics* diagnostics = context.get()->GetDiagnostics();
std::vector<SplitConstraints> test_constraints;
std::string path;