Add default_dev_cert to android_app_import
Test: app_test.go Bug: 122333215 Bug: 128610294 Change-Id: I4be98a57ffec0885258ed7d7bb2badc8b2798750
This commit is contained in:
parent
bdefa541d9
commit
961d4fdd5b
2 changed files with 52 additions and 10 deletions
27
java/app.go
27
java/app.go
|
@ -751,14 +751,18 @@ type AndroidAppImportProperties struct {
|
||||||
// A prebuilt apk to import
|
// A prebuilt apk to import
|
||||||
Apk *string
|
Apk *string
|
||||||
|
|
||||||
// The name of a certificate in the default certificate directory, blank to use the default
|
// The name of a certificate in the default certificate directory or an android_app_certificate
|
||||||
// product certificate, or an android_app_certificate module name in the form ":module".
|
// module name in the form ":module". Should be empty if presigned or default_dev_cert is set.
|
||||||
Certificate *string
|
Certificate *string
|
||||||
|
|
||||||
// Set this flag to true if the prebuilt apk is already signed. The certificate property must not
|
// Set this flag to true if the prebuilt apk is already signed. The certificate property must not
|
||||||
// be set for presigned modules.
|
// be set for presigned modules.
|
||||||
Presigned *bool
|
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,
|
// Specifies that this app should be installed to the priv-app directory,
|
||||||
// where the system will grant it additional privileges not available to
|
// where the system will grant it additional privileges not available to
|
||||||
// normal apps.
|
// normal apps.
|
||||||
|
@ -862,11 +866,18 @@ func (a *AndroidAppImport) uncompressDex(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
if String(a.properties.Certificate) == "" && !Bool(a.properties.Presigned) {
|
numCertPropsSet := 0
|
||||||
ctx.PropertyErrorf("certificate", "No certificate specified for prebuilt")
|
if String(a.properties.Certificate) != "" {
|
||||||
|
numCertPropsSet++
|
||||||
}
|
}
|
||||||
if String(a.properties.Certificate) != "" && Bool(a.properties.Presigned) {
|
if Bool(a.properties.Presigned) {
|
||||||
ctx.PropertyErrorf("certificate", "Certificate can't be specified for presigned modules")
|
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)
|
_, certificates := collectAppDeps(ctx)
|
||||||
|
@ -907,7 +918,9 @@ func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext
|
||||||
// Sign or align the package
|
// Sign or align the package
|
||||||
// TODO: Handle EXTERNAL
|
// TODO: Handle EXTERNAL
|
||||||
if !Bool(a.properties.Presigned) {
|
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 {
|
if len(certificates) != 1 {
|
||||||
ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates)
|
ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func TestAndroidAppImport_DpiVariants(t *testing.T) {
|
||||||
bp := `
|
bp := `
|
||||||
android_app_import {
|
android_app_import {
|
||||||
|
@ -1177,7 +1206,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) {
|
||||||
apk: "prebuilts/apk/app_xxhdpi.apk",
|
apk: "prebuilts/apk/app_xxhdpi.apk",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
certificate: "PRESIGNED",
|
presigned: true,
|
||||||
dex_preopt: {
|
dex_preopt: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
|
@ -1307,7 +1336,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) {
|
||||||
apk: "prebuilts/apk/app_arm64.apk",
|
apk: "prebuilts/apk/app_arm64.apk",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
certificate: "PRESIGNED",
|
presigned: true,
|
||||||
dex_preopt: {
|
dex_preopt: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
|
@ -1326,7 +1355,7 @@ func TestAndroidAppImport_ArchVariants(t *testing.T) {
|
||||||
apk: "prebuilts/apk/app_arm.apk",
|
apk: "prebuilts/apk/app_arm.apk",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
certificate: "PRESIGNED",
|
presigned: true,
|
||||||
dex_preopt: {
|
dex_preopt: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue