apex: pass init_rc/vintf_fragments to make

For "non-updatable" devices, apex_manifest.pb is a module representing
the apex, so we need to pass common properties like init_rc and
vintf_fragments to the Make module of apex_manifest.pb so that those
files are copied when the apex is installed as flattened.

Bug: 159211312
Bug: 167383491
Test: lunch aosp_sunfish-userdebug
      OVERRIDE_TARGET_FLATTEN_APEX=true m com.android.vibrator.sunfish
      check $OUT/vendor/etc for init_rc/vintf_fragmemts
Change-Id: I5d5ce5acb9b837da2fb4e6ee8f3813707c6c3bd4
diff --git a/apex/androidmk.go b/apex/androidmk.go
index af2ec3d..1b53a67 100644
--- a/apex/androidmk.go
+++ b/apex/androidmk.go
@@ -36,7 +36,9 @@
 	return a.androidMkForType()
 }
 
-func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, moduleDir string) []string {
+func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, moduleDir string,
+	apexAndroidMkData android.AndroidMkData) []string {
+
 	// apexBundleName comes from the 'name' property; apexName comes from 'apex_name' property.
 	// An apex is installed to /system/apex/<apexBundleName> and is activated at /apex/<apexName>
 	// In many cases, the two names are the same, but could be different in general.
@@ -236,6 +238,17 @@
 			fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.Stem())
 			if fi.builtFile == a.manifestPbOut && apexType == flattenedApex {
 				if a.primaryApexType {
+					// To install companion files (init_rc, vintf_fragments)
+					// Copy some common properties of apexBundle to apex_manifest
+					commonProperties := []string{
+						"LOCAL_INIT_RC", "LOCAL_VINTF_FRAGMENTS",
+					}
+					for _, name := range commonProperties {
+						if value, ok := apexAndroidMkData.Entries.EntryMap[name]; ok {
+							fmt.Fprintln(w, name+" := "+strings.Join(value, " "))
+						}
+					}
+
 					// Make apex_manifest.pb module for this APEX to override all other
 					// modules in the APEXes being overridden by this APEX
 					var patterns []string
@@ -294,7 +307,7 @@
 			apexType := a.properties.ApexType
 			if a.installable() {
 				apexName := proptools.StringDefault(a.properties.Apex_name, name)
-				moduleNames = a.androidMkForFiles(w, name, apexName, moduleDir)
+				moduleNames = a.androidMkForFiles(w, name, apexName, moduleDir, data)
 			}
 
 			if apexType == flattenedApex {