From 760c33579111e431324d0c69b980474353cd08b8 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Mon, 4 May 2020 15:40:52 -0700 Subject: [PATCH] Use aapt2 flag --rename-resources-package in soong This change uses aapt2 flag to change the package name encoded in the resources table for override apps. Runtime resource overlays will need to be handled separately. Test: app_test.go Bug: 147434671 Change-Id: I70a43c2163709afc90262d74f975ce14a556cf55 --- java/app.go | 10 +++++++++- java/app_test.go | 17 +++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/java/app.go b/java/app.go index 7ea1aae5d..0987f7473 100755 --- a/java/app.go +++ b/java/app.go @@ -494,6 +494,14 @@ func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs } +func generateAaptRenamePackageFlags(packageName string) []string { + aaptFlags := []string{} + aaptFlags = append(aaptFlags, "--rename-manifest-package "+packageName) + // Required to rename the package name in the resources table. + aaptFlags = append(aaptFlags, "--rename-resources-package "+packageName) + return aaptFlags +} + func (a *AndroidApp) OverriddenManifestPackageName() string { return a.overriddenManifestPackageName } @@ -530,7 +538,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { if !overridden { manifestPackageName = *a.overridableAppProperties.Package_name } - aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName) + aaptLinkFlags = append(aaptLinkFlags, generateAaptRenamePackageFlags(manifestPackageName)...) a.overriddenManifestPackageName = manifestPackageName } diff --git a/java/app_test.go b/java/app_test.go index e686f2780..257c80b4a 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -1748,7 +1748,7 @@ func TestOverrideAndroidApp(t *testing.T) { certFlag string lineageFlag string overrides []string - aaptFlag string + packageFlag string logging_parent string }{ { @@ -1758,7 +1758,7 @@ func TestOverrideAndroidApp(t *testing.T) { certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", lineageFlag: "", overrides: []string{"qux"}, - aaptFlag: "", + packageFlag: "", logging_parent: "", }, { @@ -1768,7 +1768,7 @@ func TestOverrideAndroidApp(t *testing.T) { certFlag: "cert/new_cert.x509.pem cert/new_cert.pk8", lineageFlag: "--lineage lineage.bin", overrides: []string{"qux", "foo"}, - aaptFlag: "", + packageFlag: "", logging_parent: "bah", }, { @@ -1778,7 +1778,7 @@ func TestOverrideAndroidApp(t *testing.T) { certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", lineageFlag: "", overrides: []string{"qux", "foo"}, - aaptFlag: "--rename-manifest-package org.dandroid.bp", + packageFlag: "org.dandroid.bp", logging_parent: "", }, } @@ -1826,12 +1826,11 @@ func TestOverrideAndroidApp(t *testing.T) { expected.logging_parent, logging_parent) } - // Check the package renaming flag, if exists. + // Check the package renaming flags, if exists. res := variant.Output("package-res.apk") aapt2Flags := res.Args["flags"] - if !strings.Contains(aapt2Flags, expected.aaptFlag) { - t.Errorf("package renaming flag, %q is missing in aapt2 link flags, %q", expected.aaptFlag, aapt2Flags) - } + checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag) + checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", expected.packageFlag) } } @@ -1968,6 +1967,7 @@ func TestOverrideAndroidTest(t *testing.T) { res := variant.Output("package-res.apk") aapt2Flags := res.Args["flags"] checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag) + checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", expected.packageFlag) checkAapt2LinkFlag(t, aapt2Flags, "rename-instrumentation-target-package", expected.targetPackageFlag) } } @@ -3180,6 +3180,7 @@ func TestOverrideRuntimeResourceOverlay(t *testing.T) { res := variant.Output("package-res.apk") aapt2Flags := res.Args["flags"] checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag) + checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", "") checkAapt2LinkFlag(t, aapt2Flags, "rename-overlay-target-package", expected.targetPackageFlag) } }