From cde2a037f62d41b70391b4b3796507e744913423 Mon Sep 17 00:00:00 2001 From: Dario Freni Date: Sun, 27 Oct 2019 00:29:22 +0100 Subject: [PATCH] Add support for including app prebuilts in APEX. Bug: 138429615 Test: Created an APEX containing CtsShimPrebuilt and CtsShimPrivPrebuilt. Change-Id: I9d138ccfc03e4b96c9989d2681ad4e4ad5f20108 --- apex/apex.go | 13 ++++++++++ apex/apex_test.go | 61 +++++++++++++++++++++++++++++++++++++++++++---- java/app.go | 4 ++++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 629cbbf2e..799809c24 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -990,6 +990,16 @@ func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToC return } +func getCopyManifestForAndroidAppImport(app *java.AndroidAppImport, pkgName string) (fileToCopy android.Path, dirInApex string) { + appDir := "app" + if app.Privileged() { + appDir = "priv-app" + } + dirInApex = filepath.Join(appDir, pkgName) + fileToCopy = app.OutputFile() + return +} + // Context "decorator", overriding the InstallBypassMake method to always reply `true`. type flattenedApexContext struct { android.ModuleContext @@ -1159,6 +1169,9 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName)) filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil}) return true + } else if ap, ok := child.(*java.AndroidAppImport); ok { + fileToCopy, dirInApex := getCopyManifestForAndroidAppImport(ap, ctx.DeviceConfig().OverridePackageNameFor(depName)) + filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil}) } else { ctx.PropertyErrorf("apps", "%q is not an android_app module", depName) } diff --git a/apex/apex_test.go b/apex/apex_test.go index cf38caa9d..ffbee8694 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -124,7 +124,9 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory)) ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory)) + ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory)) ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory)) + ctx.RegisterModuleType("android_app_import", android.ModuleFactoryAdaptor(java.AndroidAppImportFactory)) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { @@ -254,13 +256,17 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr native_bridge_supported: true, } ` + bp = bp + java.GatherRequiredDepsForTest() fs := map[string][]byte{ - "Android.bp": []byte(bp), - "build/make/target/product/security": nil, - "apex_manifest.json": nil, - "AndroidManifest.xml": nil, - "system/sepolicy/apex/myapex-file_contexts": nil, + "Android.bp": []byte(bp), + "a.java": nil, + "PrebuiltAppFoo.apk": nil, + "PrebuiltAppFooPriv.apk": nil, + "build/make/target/product/security": nil, + "apex_manifest.json": nil, + "AndroidManifest.xml": nil, + "system/sepolicy/apex/myapex-file_contexts": nil, "system/sepolicy/apex/myapex_keytest-file_contexts": nil, "system/sepolicy/apex/otherapex-file_contexts": nil, "system/sepolicy/apex/commonapex-file_contexts": nil, @@ -289,6 +295,7 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr "myapex-arm64.apex": nil, "myapex-arm.apex": nil, "frameworks/base/api/current.txt": nil, + "framework/aidl/a.aidl": nil, "build/make/core/proguard.flags": nil, "build/make/core/proguard_basic_keeps.flags": nil, } @@ -2436,7 +2443,51 @@ func TestApexWithApps(t *testing.T) { ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") +} +func TestApexWithAppImports(t *testing.T) { + ctx, _ := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + apps: [ + "AppFooPrebuilt", + "AppFooPrivPrebuilt", + ], + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + android_app_import { + name: "AppFooPrebuilt", + apk: "PrebuiltAppFoo.apk", + presigned: true, + dex_preopt: { + enabled: false, + }, + } + + android_app_import { + name: "AppFooPrivPrebuilt", + apk: "PrebuiltAppFooPriv.apk", + privileged: true, + presigned: true, + dex_preopt: { + enabled: false, + }, + } + `) + + module := ctx.ModuleForTests("myapex", "android_common_myapex") + apexRule := module.Rule("apexRule") + copyCmds := apexRule.Args["copy_commands"] + + ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") + ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk") } func TestApexAvailable(t *testing.T) { diff --git a/java/app.go b/java/app.go index 3dbcbf468..bd8556e1d 100644 --- a/java/app.go +++ b/java/app.go @@ -985,6 +985,10 @@ func (a *AndroidAppImport) Name() string { return a.prebuilt.Name(a.ModuleBase.Name()) } +func (a *AndroidAppImport) OutputFile() android.Path { + return a.outputFile +} + var dpiVariantGroupType reflect.Type var archVariantGroupType reflect.Type