From 5e8fa3a24835a1ad39f758f630a61c83133eabf8 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Mon, 27 Jun 2016 16:21:42 -0700 Subject: AAPT2: Improve diff command Change-Id: Ia1e2f8482c7192ef50126b61bed7975297332767 --- tools/aapt2/diff/Diff.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tools/aapt2/diff/Diff.cpp') diff --git a/tools/aapt2/diff/Diff.cpp b/tools/aapt2/diff/Diff.cpp index 67333a228cdf..1ff6ef6cd2b1 100644 --- a/tools/aapt2/diff/Diff.cpp +++ b/tools/aapt2/diff/Diff.cpp @@ -16,6 +16,7 @@ #include "Flags.h" #include "ResourceTable.h" +#include "ValueVisitor.h" #include "io/ZipArchive.h" #include "process/IResourceTableConsumer.h" #include "process/SymbolTable.h" @@ -385,6 +386,24 @@ static bool emitResourceTableDiff(IAaptContext* context, LoadedApk* apkA, Loaded return diff; } +class ZeroingReferenceVisitor : public ValueVisitor { +public: + using ValueVisitor::visit; + + void visit(Reference* ref) override { + if (ref->name && ref->id) { + if (ref->id.value().packageId() == 0x7f) { + ref->id = {}; + } + } + } +}; + +static void zeroOutAppReferences(ResourceTable* table) { + ZeroingReferenceVisitor visitor; + visitAllValuesInTable(table, &visitor); +} + int diff(const std::vector& args) { DiffContext context; @@ -405,6 +424,10 @@ int diff(const std::vector& args) { return 1; } + // Zero out Application IDs in references. + zeroOutAppReferences(apkA->getResourceTable()); + zeroOutAppReferences(apkB->getResourceTable()); + if (emitResourceTableDiff(&context, apkA.get(), apkB.get())) { // We emitted a diff, so return 1 (failure). return 1; -- cgit v1.2.3