aapt2 flag for target manifest package override

This change adds an aapt2 flag, rename-instrumentation-target-package,
when an android test's instrumention target module's manifest package
name is overridden.

Bug: 122957760
Test: app_test.go, atest DocumentsUITests
Change-Id: I7116a51ec5ec9d61a20cd28509b3af0e383730d7
This commit is contained in:
Jaewoong Jung 2019-02-27 16:26:28 -08:00
parent ef36053829
commit 4102e5dca3
2 changed files with 38 additions and 0 deletions

View File

@ -93,6 +93,8 @@ type AndroidApp struct {
// the install APK name is normally the same as the module name, but can be overridden with PRODUCT_PACKAGE_NAME_OVERRIDES.
installApkName string
additionalAaptFlags []string
}
func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
@ -222,6 +224,8 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName)
}
aaptLinkFlags = append(aaptLinkFlags, a.additionalAaptFlags...)
a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...)
// apps manifests are handled by aapt, don't let Module see them
@ -441,6 +445,13 @@ type AndroidTest struct {
}
func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Check if the instrumentation target package is overridden before generating build actions.
if a.appTestProperties.Instrumentation_for != nil {
manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(*a.appTestProperties.Instrumentation_for)
if overridden {
a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+manifestPackageName)
}
}
a.generateAndroidBuildActions(ctx)
a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites)

View File

@ -747,3 +747,30 @@ func TestPackageNameOverride(t *testing.T) {
})
}
}
func TestInstrumentationTargetOverridden(t *testing.T) {
bp := `
android_app {
name: "foo",
srcs: ["a.java"],
}
android_test {
name: "bar",
instrumentation_for: "foo",
}
`
config := testConfig(nil)
config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"}
ctx := testAppContext(config, bp, nil)
run(t, ctx, config)
bar := ctx.ModuleForTests("bar", "android_common")
res := bar.Output("package-res.apk")
aapt2Flags := res.Args["flags"]
e := "--rename-instrumentation-target-package org.dandroid.bp"
if !strings.Contains(aapt2Flags, e) {
t.Errorf("target package renaming flag, %q is missing in aapt2 link flags, %q", e, aapt2Flags)
}
}