aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaewoong Jung <jungjw@google.com>2019-08-22 14:25:58 -0700
committerRashed Abdel-Tawab <rashed@linux.com>2019-09-27 20:31:01 -0700
commit98d8c8837a533bd7e5caf5f3d3c1104c6d8b492d (patch)
tree8cae0e164e1842af639f304cdc24c096f20e1ce8
parentf57e181870a4f2d63835ca9b1187f319908f33f9 (diff)
downloadbuild_soong-98d8c8837a533bd7e5caf5f3d3c1104c6d8b492d.tar.gz
build_soong-98d8c8837a533bd7e5caf5f3d3c1104c6d8b492d.tar.bz2
build_soong-98d8c8837a533bd7e5caf5f3d3c1104c6d8b492d.zip
Add default_dev_cert to android_app_import
Test: app_test.go Bug: 122333215 Bug: 128610294 Change-Id: I4be98a57ffec0885258ed7d7bb2badc8b2798750
-rw-r--r--java/app.go27
-rw-r--r--java/app_test.go35
2 files changed, 52 insertions, 10 deletions
diff --git a/java/app.go b/java/app.go
index cea45572..52e103bd 100644
--- a/java/app.go
+++ b/java/app.go
@@ -703,14 +703,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.
@@ -812,11 +816,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 Bool(a.properties.Presigned) {
+ numCertPropsSet++
+ }
+ if Bool(a.properties.Default_dev_cert) {
+ numCertPropsSet++
}
- if String(a.properties.Certificate) != "" && Bool(a.properties.Presigned) {
- ctx.PropertyErrorf("certificate", "Certificate can't be specified for presigned modules")
+ if numCertPropsSet != 1 {
+ ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
}
_, certificates := collectAppDeps(ctx)
@@ -847,7 +858,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 a5c4fbc7..fc33eacd 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -1237,6 +1237,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 {
@@ -1250,7 +1279,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) {
apk: "prebuilts/apk/app_xxhdpi.apk",
},
},
- certificate: "PRESIGNED",
+ presigned: true,
dex_preopt: {
enabled: true,
},
@@ -1381,7 +1410,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) {
apk: "prebuilts/apk/app_arm64.apk",
},
},
- certificate: "PRESIGNED",
+ presigned: true,
dex_preopt: {
enabled: true,
},
@@ -1400,7 +1429,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) {
apk: "prebuilts/apk/app_arm.apk",
},
},
- certificate: "PRESIGNED",
+ presigned: true,
dex_preopt: {
enabled: true,
},