Merge "Add support for including app prebuilts in APEX."

This commit is contained in:
Treehugger Robot 2019-10-29 23:02:38 +00:00 committed by Gerrit Code Review
commit 520367cbd3
3 changed files with 73 additions and 5 deletions

View File

@ -990,6 +990,16 @@ func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToC
return 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`. // Context "decorator", overriding the InstallBypassMake method to always reply `true`.
type flattenedApexContext struct { type flattenedApexContext struct {
android.ModuleContext android.ModuleContext
@ -1159,6 +1169,9 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName)) fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil}) filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
return true 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 { } else {
ctx.PropertyErrorf("apps", "%q is not an android_app module", depName) ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
} }

View File

@ -124,7 +124,9 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr
ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory)) ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory)) 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", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
ctx.RegisterModuleType("android_app_import", android.ModuleFactoryAdaptor(java.AndroidAppImportFactory))
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
@ -254,13 +256,17 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr
native_bridge_supported: true, native_bridge_supported: true,
} }
` `
bp = bp + java.GatherRequiredDepsForTest()
fs := map[string][]byte{ fs := map[string][]byte{
"Android.bp": []byte(bp), "Android.bp": []byte(bp),
"build/make/target/product/security": nil, "a.java": nil,
"apex_manifest.json": nil, "PrebuiltAppFoo.apk": nil,
"AndroidManifest.xml": nil, "PrebuiltAppFooPriv.apk": nil,
"system/sepolicy/apex/myapex-file_contexts": 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/myapex_keytest-file_contexts": nil,
"system/sepolicy/apex/otherapex-file_contexts": nil, "system/sepolicy/apex/otherapex-file_contexts": nil,
"system/sepolicy/apex/commonapex-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-arm64.apex": nil,
"myapex-arm.apex": nil, "myapex-arm.apex": nil,
"frameworks/base/api/current.txt": nil, "frameworks/base/api/current.txt": nil,
"framework/aidl/a.aidl": nil,
"build/make/core/proguard.flags": nil, "build/make/core/proguard.flags": nil,
"build/make/core/proguard_basic_keeps.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/app/AppFoo/AppFoo.apk")
ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.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) { func TestApexAvailable(t *testing.T) {

View File

@ -985,6 +985,10 @@ func (a *AndroidAppImport) Name() string {
return a.prebuilt.Name(a.ModuleBase.Name()) return a.prebuilt.Name(a.ModuleBase.Name())
} }
func (a *AndroidAppImport) OutputFile() android.Path {
return a.outputFile
}
var dpiVariantGroupType reflect.Type var dpiVariantGroupType reflect.Type
var archVariantGroupType reflect.Type var archVariantGroupType reflect.Type