From ce320f86a084cb29d5f4e24aee221e9e4dd4fb47 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Tue, 7 May 2024 00:53:28 +0000 Subject: Pass --non-updatable-system flag to aapt2 when versionCode is unspecified This change modifies the flags passed to aapt2 when generating the APKs. Currently, the version code of the platform sdk version is passed to aapt2 when the bp module definition does not explicitly specify the `--version-code` flag in "aaptflags" parameter. This change modifies such behavior so that the newly introduced `--non-updatable-system` flag is passed instead of implicitly passing the `--version-code`. If "versionCode" is explicitly specified in the app manifest, the `--non-updatable-system` flag is overriden and is a no-op. This way, the build continues to stay agnostic to the content of the manifest files. This flag is not passed for build actions of android_test modules, as test targets do not set `versionCode`. Test: m nothing --no-skip-soong-tests && manually inspect aapt2 build rules Bug: 311724570 Change-Id: Ie3e50506d90da1d28b8039e29d76859b1927b5e2 --- java/app_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'java/app_test.go') diff --git a/java/app_test.go b/java/app_test.go index 804949435..988a5b17d 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -4477,5 +4477,54 @@ func TestAppMinSdkVersionOverride(t *testing.T) { fooOverride.BuildParams.Args["args"], "--minSdkVersion 33", ) +} + +func TestNonUpdatableSystem(t *testing.T) { + ctx := testApp(t, ` + android_app { + name: "foo", + srcs: ["a.java"], + sdk_version: "current", + aaptflags: [ + "--version-code 1", + ], + } + android_app { + name: "bar", + srcs: ["a.java"], + sdk_version: "current", + } + android_test { + name: "baz", + srcs: ["a.java"], + sdk_version: "current", + } + android_test_helper_app { + name: "baz_helper", + srcs: ["a.java"], + sdk_version: "current", + } + `) + + hasNonUpdatableSystemFlag := func(module android.TestingModule) bool { + moduleAapt2LinkRule := module.Rule("android/soong/java.aapt2Link") + linkFlags := moduleAapt2LinkRule.Args["flags"] + return strings.Contains(linkFlags, "--non-updatable-system") + } + + foo := ctx.ModuleForTests("foo", "android_common") + android.AssertBoolEquals(t, "app should not pass `--non-updatable-flags` when --version-code is specified", + false, hasNonUpdatableSystemFlag(foo)) + + bar := ctx.ModuleForTests("bar", "android_common") + android.AssertBoolEquals(t, "app should pass `--non-updatable-flags` when --version-code is not specified", + true, hasNonUpdatableSystemFlag(bar)) + + baz := ctx.ModuleForTests("baz", "android_common") + android.AssertBoolEquals(t, "test should not pass `--non-updatable-flags` even if --version-code is not specified", + false, hasNonUpdatableSystemFlag(baz)) + baz_helper := ctx.ModuleForTests("baz_helper", "android_common") + android.AssertBoolEquals(t, "test should not pass `--non-updatable-flags` even if --version-code is not specified", + false, hasNonUpdatableSystemFlag(baz_helper)) } -- cgit v1.2.3-59-g8ed1b