From cfaa1643e8aea1a045655274757a62f936ca235b Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 28 Feb 2020 16:51:07 +0900 Subject: [PATCH] bundle config contains (path,manifest) pairs of embedded APKs If an APEX contains APKs and the manifest package name of the APKs are overridden (either via override_android_app orPRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES), that the path to the APK (relative in the APEX) and the overridden manifest package name is recorded in the bundle config file. Bug: 148002117 Test: m Change-Id: Ibb90bcefb77fa6b2dad77cb2facc6079de9ab154 --- apex/apex.go | 7 +++++++ apex/apex_test.go | 9 ++++++++- apex/builder.go | 25 +++++++++++++++++++++++++ java/app.go | 7 +++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/apex/apex.go b/apex/apex.go index c7911624a..bef4e4254 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1410,6 +1410,7 @@ type apexFile struct { jacocoReportClassesFile android.Path // only for javalibs and apps certificate java.Certificate // only for apps + overriddenPackageName string // only for apps isJniLib bool } @@ -1917,6 +1918,12 @@ func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface { af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp) af.jacocoReportClassesFile = aapp.JacocoReportClassesFile() af.certificate = aapp.Certificate() + + if app, ok := aapp.(interface { + OverriddenManifestPackageName() string + }); ok { + af.overriddenPackageName = app.OverriddenManifestPackageName() + } return af } diff --git a/apex/apex_test.go b/apex/apex_test.go index 0c01238ac..bd53b1546 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -87,6 +87,12 @@ func withTargets(targets map[android.OsType][]android.Target) testCustomizer { } } +func withManifestPackageNameOverrides(specs []string) testCustomizer { + return func(fs map[string][]byte, config android.Config) { + config.TestProductVariables.ManifestPackageNameOverrides = specs + } +} + func withBinder32bit(fs map[string][]byte, config android.Config) { config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) } @@ -3714,12 +3720,13 @@ func TestAppBundle(t *testing.T) { system_modules: "none", apex_available: [ "myapex" ], } - `) + `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config") content := bundleConfigRule.Args["content"] ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) + ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`) } func TestMain(m *testing.M) { diff --git a/apex/builder.go b/apex/builder.go index b2b1b19a4..38a2a5346 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -263,16 +263,41 @@ func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApe func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath { output := android.PathForModuleOut(ctx, "bundle_config.json") + type ApkConfig struct { + Package_name string `json:"package_name"` + Apk_path string `json:"path"` + } config := struct { Compression struct { Uncompressed_glob []string `json:"uncompressed_glob"` } `json:"compression"` + Apex_config struct { + Apex_embedded_apk_config []ApkConfig `json:"apex_embedded_apk_config,omitempty"` + } `json:"apex_config,omitempty"` }{} config.Compression.Uncompressed_glob = []string{ "apex_payload.img", "apex_manifest.*", } + + // collect the manifest names and paths of android apps + // if their manifest names are overridden + for _, fi := range a.filesInfo { + if fi.class != app { + continue + } + packageName := fi.overriddenPackageName + if packageName != "" { + config.Apex_config.Apex_embedded_apk_config = append( + config.Apex_config.Apex_embedded_apk_config, + ApkConfig{ + Package_name: packageName, + Apk_path: fi.Path(), + }) + } + } + j, err := json.Marshal(config) if err != nil { panic(fmt.Errorf("error while marshalling to %q: %#v", output, err)) diff --git a/java/app.go b/java/app.go index ed4462ca7..fc3ce97fb 100755 --- a/java/app.go +++ b/java/app.go @@ -147,6 +147,8 @@ type AndroidApp struct { additionalAaptFlags []string noticeOutputs android.NoticeOutputs + + overriddenManifestPackageName string } func (a *AndroidApp) IsInstallable() bool { @@ -271,6 +273,10 @@ func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs } +func (a *AndroidApp) OverriddenManifestPackageName() string { + return a.overriddenManifestPackageName +} + func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis) @@ -304,6 +310,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { manifestPackageName = *a.overridableAppProperties.Package_name } aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName) + a.overriddenManifestPackageName = manifestPackageName } aaptLinkFlags = append(aaptLinkFlags, a.additionalAaptFlags...)