diff --git a/java/app.go b/java/app.go index 31f07d36e..f5a5da01b 100644 --- a/java/app.go +++ b/java/app.go @@ -751,14 +751,18 @@ type AndroidAppImportProperties struct { // A prebuilt apk to import Apk *string - // The name of a certificate in the default certificate directory, blank to use the default - // product certificate, or an android_app_certificate module name in the form ":module". + // The name of a certificate in the default certificate directory or an android_app_certificate + // module name in the form ":module". Should be empty if presigned or default_dev_cert is set. Certificate *string // Set this flag to true if the prebuilt apk is already signed. The certificate property must not // be set for presigned modules. Presigned *bool + // Sign with the default system dev certificate. Must be used judiciously. Most imported apps + // need to either specify a specific certificate or be presigned. + Default_dev_cert *bool + // Specifies that this app should be installed to the priv-app directory, // where the system will grant it additional privileges not available to // normal apps. @@ -862,11 +866,18 @@ func (a *AndroidAppImport) uncompressDex( } func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { - if String(a.properties.Certificate) == "" && !Bool(a.properties.Presigned) { - ctx.PropertyErrorf("certificate", "No certificate specified for prebuilt") + numCertPropsSet := 0 + if String(a.properties.Certificate) != "" { + numCertPropsSet++ } - if String(a.properties.Certificate) != "" && Bool(a.properties.Presigned) { - ctx.PropertyErrorf("certificate", "Certificate can't be specified for presigned modules") + if Bool(a.properties.Presigned) { + numCertPropsSet++ + } + if Bool(a.properties.Default_dev_cert) { + numCertPropsSet++ + } + if numCertPropsSet != 1 { + ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set") } _, certificates := collectAppDeps(ctx) @@ -907,7 +918,9 @@ func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext // Sign or align the package // TODO: Handle EXTERNAL if !Bool(a.properties.Presigned) { - certificates = processMainCert(a.ModuleBase, *a.properties.Certificate, certificates, ctx) + // If the certificate property is empty at this point, default_dev_cert must be set to true. + // Which makes processMainCert's behavior for the empty cert string WAI. + certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx) if len(certificates) != 1 { ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates) } diff --git a/java/app_test.go b/java/app_test.go index 564211c2c..be1ff2945 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -1164,6 +1164,35 @@ func TestAndroidAppImport_Presigned(t *testing.T) { } } +func TestAndroidAppImport_DefaultDevCert(t *testing.T) { + ctx, _ := testJava(t, ` + android_app_import { + name: "foo", + apk: "prebuilts/apk/app.apk", + default_dev_cert: true, + dex_preopt: { + enabled: true, + }, + } + `) + + variant := ctx.ModuleForTests("foo", "android_common") + + // Check dexpreopt outputs. + if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil || + variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil { + t.Errorf("can't find dexpreopt outputs") + } + + // Check cert signing flag. + signedApk := variant.Output("signed/foo.apk") + signingFlag := signedApk.Args["certificates"] + expected := "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8" + if expected != signingFlag { + t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag) + } +} + func TestAndroidAppImport_DpiVariants(t *testing.T) { bp := ` android_app_import { @@ -1177,7 +1206,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { apk: "prebuilts/apk/app_xxhdpi.apk", }, }, - certificate: "PRESIGNED", + presigned: true, dex_preopt: { enabled: true, }, @@ -1307,7 +1336,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { apk: "prebuilts/apk/app_arm64.apk", }, }, - certificate: "PRESIGNED", + presigned: true, dex_preopt: { enabled: true, }, @@ -1326,7 +1355,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) { apk: "prebuilts/apk/app_arm.apk", }, }, - certificate: "PRESIGNED", + presigned: true, dex_preopt: { enabled: true, },