Move AllowMissingDependencies handling into processMainCert
I046d75dbbd4f21f4a2b6851f558e430e9879fcff fixed android_app modules
with missing certificate dependencies when AllowMissingDependencies
was set, but the same problem can occur in android_app_import and
android_rro modules. Move the AllowMissingDependencies handling
into processMainCert so that it applies to all of them.
Bug: 246649647
Test: TestAppImportMissingCertificateAllowMissingDependencies
Change-Id: Ic7dd3e61e0e3af15c53b583cf680b1e52394a018
diff --git a/java/app.go b/java/app.go
index bccd37f..7f37ff3 100755
--- a/java/app.go
+++ b/java/app.go
@@ -526,7 +526,8 @@
// Reads and prepends a main cert from the default cert dir if it hasn't been set already, i.e. it
// isn't a cert module reference. Also checks and enforces system cert restriction if applicable.
-func processMainCert(m android.ModuleBase, certPropValue string, certificates []Certificate, ctx android.ModuleContext) []Certificate {
+func processMainCert(m android.ModuleBase, certPropValue string, certificates []Certificate,
+ ctx android.ModuleContext) (mainCertificate Certificate, allCertificates []Certificate) {
if android.SrcIsModule(certPropValue) == "" {
var mainCert Certificate
if certPropValue != "" {
@@ -558,7 +559,22 @@
}
}
- return certificates
+ if len(certificates) > 0 {
+ mainCertificate = certificates[0]
+ } else {
+ // This can be reached with an empty certificate list if AllowMissingDependencies is set
+ // and the certificate property for this module is a module reference to a missing module.
+ if !ctx.Config().AllowMissingDependencies() && len(ctx.GetMissingDependencies()) > 0 {
+ panic("Should only get here if AllowMissingDependencies set and there are missing dependencies")
+ }
+ // Set a certificate to avoid panics later when accessing it.
+ mainCertificate = Certificate{
+ Key: android.PathForModuleOut(ctx, "missing.pk8"),
+ Pem: android.PathForModuleOut(ctx, "missing.pem"),
+ }
+ }
+
+ return mainCertificate, certificates
}
func (a *AndroidApp) InstallApkName() string {
@@ -632,29 +648,14 @@
dexJarFile := a.dexBuildActions(ctx)
- jniLibs, prebuiltJniPackages, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
+ jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx)
if ctx.Failed() {
return
}
- certificates := processMainCert(a.ModuleBase, a.getCertString(ctx), certificateDeps, ctx)
-
- // This can be reached with an empty certificate list if AllowMissingDependencies is set
- // and the certificate property for this module is a module reference to a missing module.
- if len(certificates) > 0 {
- a.certificate = certificates[0]
- } else {
- if !ctx.Config().AllowMissingDependencies() && len(ctx.GetMissingDependencies()) > 0 {
- panic("Should only get here if AllowMissingDependencies set and there are missing dependencies")
- }
- // Set a certificate to avoid panics later when accessing it.
- a.certificate = Certificate{
- Key: android.PathForModuleOut(ctx, "missing.pk8"),
- Pem: android.PathForModuleOut(ctx, "missing.pem"),
- }
- }
+ a.certificate, certificates = processMainCert(a.ModuleBase, a.getCertString(ctx), certificates, ctx)
// Build a final signed app package.
packageFile := android.PathForModuleOut(ctx, a.installApkName+".apk")