From 5780d57a7116643c6d9eac735982ac44bd6b0189 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 10 Jul 2023 15:15:27 -0700 Subject: [PATCH] Copy imported APKs to output filename android_app_import and android_test_import modules with processed: true and skip_preprocessed_apk_checks are used directly from the source tree. If the source file name doesn t match the module name and the file is used as test data it can result in the wrong filename being used. Copy the source file to an output file with the correct name first. Bug: 290376750 Test: m CtsAppSecurityHostTestCases Change-Id: I4a6dd1c5e48db7085ea41035def31f0844948a46 --- java/app_import.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/java/app_import.go b/java/app_import.go index 842721728..e25bcd1b7 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -335,11 +335,19 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext // Sign or align the package if package has not been preprocessed if proptools.Bool(a.properties.Preprocessed) { - output := srcApk + var output android.WritablePath if !proptools.Bool(a.properties.Skip_preprocessed_apk_checks) { - writableOutput := android.PathForModuleOut(ctx, "validated-prebuilt", apkFilename) - a.validatePreprocessedApk(ctx, srcApk, writableOutput) - output = writableOutput + output = android.PathForModuleOut(ctx, "validated-prebuilt", apkFilename) + a.validatePreprocessedApk(ctx, srcApk, output) + } else { + // If using the input APK unmodified, still make a copy of it so that the output filename has the + // right basename. + output = android.PathForModuleOut(ctx, apkFilename) + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cp, + Input: srcApk, + Output: output, + }) } a.outputFile = output a.certificate = PresignedCertificate