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.

Exempt-From-Owner-Approval: cherry-pick from master

Bug: 148002117
Test: m

Merged-In: Ibb90bcefb77fa6b2dad77cb2facc6079de9ab154
(cherry picked from commit cfaa1643e8aea1a045655274757a62f936ca235b)
Change-Id: Ibb90bcefb77fa6b2dad77cb2facc6079de9ab154
diff --git a/apex/builder.go b/apex/builder.go
index 3d557e4..2701a36 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -252,16 +252,41 @@
 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))