diff options
| author | 2024-07-23 17:23:05 -0700 | |
|---|---|---|
| committer | 2024-07-25 12:04:26 -0700 | |
| commit | 3bd28705f4e5790282ec7dfdd54cf74d97b539d4 (patch) | |
| tree | b324c6b67d57709528e30e7431cd2723c6f77a49 /java | |
| parent | 5800d421c34ba37681f7fb01f189122ce0b19070 (diff) | |
Fix presigned apk check for privileged apps
The validation checks that run for presigned apps currently expect that
privileged apps have uncompressed dex files but if
DONT_UNCOMPRESS_PRIV_APPS_DEXS is true (UncompressPrivAppDex false) this
doesn't have to be the case so make the validation consistent with this.
Also make TestAndroidAppImport_Preprocessed verify that extra arguments
to 'check_prebuilt_presigned_apk.py' are correct for both privileged and
non-privileged apps.
Test: m nothing --no-skip-soong-tests
Test: Add presigned, privileged android_app_import module with
compressed dex to PRODUCT_PACKAGES for aosp_cf_x86_64_phone,
lunch aosp_cf_x86_64_phone-trunk_staging-userdebug &&
m DONT_UNCOMPRESS_PRIV_APPS_DEXS=true no longer fails due to validation
error.
Change-Id: I7e22cf525cd9d99d1ecb24e4e2e99c3f9de48146
Diffstat (limited to 'java')
| -rw-r--r-- | java/app_import.go | 3 | ||||
| -rw-r--r-- | java/app_import_test.go | 93 |
2 files changed, 73 insertions, 23 deletions
diff --git a/java/app_import.go b/java/app_import.go index fa87997cf..045a89a34 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -431,6 +431,9 @@ func (a *AndroidAppImport) validatePresignedApk(ctx android.ModuleContext, srcAp var extraArgs []string if a.Privileged() { extraArgs = append(extraArgs, "--privileged") + if ctx.Config().UncompressPrivAppDex() { + extraArgs = append(extraArgs, "--uncompress-priv-app-dex") + } } if proptools.Bool(a.properties.Skip_preprocessed_apk_checks) { extraArgs = append(extraArgs, "--skip-preprocessed-apk-checks") diff --git a/java/app_import_test.go b/java/app_import_test.go index a3d748a93..54a5e7518 100644 --- a/java/app_import_test.go +++ b/java/app_import_test.go @@ -777,32 +777,79 @@ func TestAndroidTestImport_Preprocessed(t *testing.T) { } func TestAndroidAppImport_Preprocessed(t *testing.T) { - result := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, - ).RunTestWithBp(t, ` - android_app_import { - name: "foo", - apk: "prebuilts/apk/app.apk", - presigned: true, - preprocessed: true, - } - `) + for _, dontUncompressPrivAppDexs := range []bool{false, true} { + name := fmt.Sprintf("dontUncompressPrivAppDexs:%t", dontUncompressPrivAppDexs) + t.Run(name, func(t *testing.T) { + result := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.UncompressPrivAppDex = proptools.BoolPtr(!dontUncompressPrivAppDexs) + }), + ).RunTestWithBp(t, ` + android_app_import { + name: "foo", + apk: "prebuilts/apk/app.apk", + presigned: true, + preprocessed: true, + } - apkName := "foo.apk" - variant := result.ModuleForTests("foo", "android_common") - outputBuildParams := variant.Output(apkName).BuildParams - if outputBuildParams.Rule.String() != android.Cp.String() { - t.Errorf("Unexpected prebuilt android_app_import rule: " + outputBuildParams.Rule.String()) - } + android_app_import { + name: "bar", + apk: "prebuilts/apk/app.apk", + presigned: true, + privileged: true, + preprocessed: true, + } + `) + + // non-privileged app + apkName := "foo.apk" + variant := result.ModuleForTests("foo", "android_common") + outputBuildParams := variant.Output(apkName).BuildParams + if outputBuildParams.Rule.String() != android.Cp.String() { + t.Errorf("Unexpected prebuilt android_app_import rule: " + outputBuildParams.Rule.String()) + } - // Make sure compression and aligning were validated. - if outputBuildParams.Validation == nil { - t.Errorf("Expected validation rule, but was not found") - } + // Make sure compression and aligning were validated. + if outputBuildParams.Validation == nil { + t.Errorf("Expected validation rule, but was not found") + } + + validationBuildParams := variant.Output("validated-prebuilt/check.stamp").BuildParams + if validationBuildParams.Rule.String() != checkPresignedApkRule.String() { + t.Errorf("Unexpected validation rule: " + validationBuildParams.Rule.String()) + } - validationBuildParams := variant.Output("validated-prebuilt/check.stamp").BuildParams - if validationBuildParams.Rule.String() != checkPresignedApkRule.String() { - t.Errorf("Unexpected validation rule: " + validationBuildParams.Rule.String()) + expectedScriptArgs := "--preprocessed" + actualScriptArgs := validationBuildParams.Args["extraArgs"] + android.AssertStringEquals(t, "check script extraArgs", expectedScriptArgs, actualScriptArgs) + + // privileged app + apkName = "bar.apk" + variant = result.ModuleForTests("bar", "android_common") + outputBuildParams = variant.Output(apkName).BuildParams + if outputBuildParams.Rule.String() != android.Cp.String() { + t.Errorf("Unexpected prebuilt android_app_import rule: " + outputBuildParams.Rule.String()) + } + + // Make sure compression and aligning were validated. + if outputBuildParams.Validation == nil { + t.Errorf("Expected validation rule, but was not found") + } + + validationBuildParams = variant.Output("validated-prebuilt/check.stamp").BuildParams + if validationBuildParams.Rule.String() != checkPresignedApkRule.String() { + t.Errorf("Unexpected validation rule: " + validationBuildParams.Rule.String()) + } + + expectedScriptArgs = "--privileged" + if !dontUncompressPrivAppDexs { + expectedScriptArgs += " --uncompress-priv-app-dex" + } + expectedScriptArgs += " --preprocessed" + actualScriptArgs = validationBuildParams.Args["extraArgs"] + android.AssertStringEquals(t, "check script extraArgs", expectedScriptArgs, actualScriptArgs) + }) } } |