Create a partial implementation of $PRODUCT_OUT/misc_info.txt

This file is packaged into META/target_files.zip. It is also an implicit
input for `add_img_to_target_files` invocation, which creates additional
metadata files for target_files.zip like apex_info.pb, care_map.pb and
vbmeta_digest.txt

This CL implements the minimum fields necessary to run
`add_img_to_target_files`.

Bug: 399788119
Test: Built target_files.zip locally.
Test: Verified META/misc_info.txt exists, but is not identical to make
Change-Id: I52b9c9ff7b33e74d79b9321aa94312397a830693
diff --git a/filesystem/android_device.go b/filesystem/android_device.go
index 005dc34..78afbf5 100644
--- a/filesystem/android_device.go
+++ b/filesystem/android_device.go
@@ -111,6 +111,7 @@
 	proguardUsageZip    android.Path
 	kernelConfig        android.Path
 	kernelVersion       android.Path
+	miscInfo            android.Path
 }
 
 func AndroidDeviceFactory() android.Module {
@@ -186,6 +187,7 @@
 	allInstalledModules := a.allInstalledModules(ctx)
 
 	a.kernelConfig, a.kernelVersion = a.extractKernelVersionAndConfigs(ctx)
+	a.miscInfo = a.addMiscInfo(ctx)
 	a.buildTargetFilesZip(ctx, allInstalledModules)
 	a.buildProguardZips(ctx, allInstalledModules)
 
@@ -646,6 +648,10 @@
 	if a.kernelVersion != nil {
 		builder.Command().Textf("cp").Input(a.kernelVersion).Textf(" %s/META/", targetFilesDir.String())
 	}
+	// misc_info.txt
+	if a.miscInfo != nil {
+		builder.Command().Textf("cp").Input(a.miscInfo).Textf(" %s/META/", targetFilesDir.String())
+	}
 
 	if a.partitionProps.Super_partition_name != nil {
 		superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
@@ -660,6 +666,43 @@
 
 }
 
+// A partial implementation of make's $PRODUCT_OUT/misc_info.txt
+// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=5894?q=misc_info.txt%20f:build%2Fmake%2Fcore%2FMakefile&ss=android%2Fplatform%2Fsuperproject%2Fmain
+// This file is subsequently used by add_img_to_target_files to create additioanl metadata files like apex_info.pb
+// TODO (b/399788119): Complete the migration of misc_info.txt
+func (a *androidDevice) addMiscInfo(ctx android.ModuleContext) android.Path {
+	builder := android.NewRuleBuilder(pctx, ctx)
+	miscInfo := android.PathForModuleOut(ctx, "misc_info.txt")
+	builder.Command().
+		Textf("rm -f %s", miscInfo).
+		Textf("&& echo recovery_api_version=%s >> %s", ctx.Config().VendorConfig("recovery").String("recovery_api_version"), miscInfo).
+		Textf("&& echo fstab_version=%s >> %s", ctx.Config().VendorConfig("recovery").String("recovery_fstab_version"), miscInfo).
+		ImplicitOutput(miscInfo)
+
+	if a.partitionProps.Recovery_partition_name == nil {
+		builder.Command().Textf("echo no_recovery=true >> %s", miscInfo)
+	}
+	fsInfos := a.getFsInfos(ctx)
+	for _, partition := range android.SortedKeys(fsInfos) {
+		if fsInfos[partition].UseAvb {
+			builder.Command().Textf("echo 'avb_%s_hashtree_enable=true' >> %s", partition, miscInfo)
+		}
+	}
+	if len(a.partitionProps.Vbmeta_partitions) > 0 {
+		builder.Command().
+			Textf("echo avb_enable=true >> %s", miscInfo).
+			Textf("&& echo avb_building_vbmeta_image=true >> %s", miscInfo).
+			Textf("&& echo avb_avbtool=avbtool >> %s", miscInfo)
+	}
+	if a.partitionProps.Boot_partition_name != nil {
+		builder.Command().Textf("echo boot_images=boot.img >> %s", miscInfo)
+	}
+
+	builder.Build("misc_info", "Building misc_info")
+
+	return miscInfo
+}
+
 type ApexKeyPathInfo struct {
 	ApexKeyPath android.Path
 }