Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 520367cb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

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

parents 765fe7a5 cde2a037
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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)
				}
+56 −5
Original line number Diff line number Diff line
@@ -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,9 +256,13 @@ 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),
		"a.java":                                    nil,
		"PrebuiltAppFoo.apk":                        nil,
		"PrebuiltAppFooPriv.apk":                    nil,
		"build/make/target/product/security":        nil,
		"apex_manifest.json":                        nil,
		"AndroidManifest.xml":                       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) {
+4 −0
Original line number Diff line number Diff line
@@ -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