diff options
author | 2018-11-07 16:49:02 -0500 | |
---|---|---|
committer | 2018-12-20 18:19:25 -0500 | |
commit | c76940363197de1772b761aa38e819b55fb80cb7 (patch) | |
tree | 28c9afa0e073be59b396dbe8aebc6a118deca382 /tools/aapt2/LoadedApk.cpp | |
parent | 9da2ff0fdc6af2153c12701ae8344f10f9a26413 (diff) |
Resource Path Obfuscation
This CL allows aapt2 to obfuscate resource paths within the output apk
and move resources to shorter obfuscated paths. This reduces apk size
when there is a large number of resources since the path metadata exists
in 4 places in the apk.
This CL adds two arguments to aapt2, one to enable resource path
obfuscation and one to point to a path to output the path map to (for
later debugging).
Test: make aapt2_tests
Bug: b/75965637
Change-Id: I9cacafe1d17800d673566b2d61b0b88f3fb8d60c
Diffstat (limited to 'tools/aapt2/LoadedApk.cpp')
-rw-r--r-- | tools/aapt2/LoadedApk.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tools/aapt2/LoadedApk.cpp b/tools/aapt2/LoadedApk.cpp index b353ff00a23f..45719ef474cd 100644 --- a/tools/aapt2/LoadedApk.cpp +++ b/tools/aapt2/LoadedApk.cpp @@ -223,8 +223,17 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, ResourceTable* split_table io::IFile* file = iterator->Next(); std::string path = file->GetSource().path; + std::string output_path = path; + bool is_resource = path.find("res/") == 0; + if (is_resource) { + auto it = options.shortened_path_map.find(path); + if (it != options.shortened_path_map.end()) { + output_path = it->second; + } + } + // Skip resources that are not referenced if requested. - if (path.find("res/") == 0 && referenced_resources.find(path) == referenced_resources.end()) { + if (is_resource && referenced_resources.find(output_path) == referenced_resources.end()) { if (context->IsVerbose()) { context->GetDiagnostics()->Note(DiagMessage() << "Removing resource '" << path << "' from APK."); @@ -283,7 +292,8 @@ bool LoadedApk::WriteToArchive(IAaptContext* context, ResourceTable* split_table return false; } } else { - if (!io::CopyFileToArchivePreserveCompression(context, file, path, writer)) { + if (!io::CopyFileToArchivePreserveCompression( + context, file, output_path, writer)) { return false; } } |