Add avb info of bootimages in misc_info.txt

Make built $ANDROID_PRODUCT_OUT/misc_info.txt contains the avb
information of the installed boot images. This info overlaps with the
contents of the buildPropFile of the `bootImg` modules, but
- Only some of the entries are written to misc_info.txt
- misc_info.txt contains the "partition qualified" key. e.g.
  avb_init_boot_algorithm and not avb_algorithm

This CL adds a secondary `propFileForMiscInfo` to the build actions
of bootimg. This file will be propagated to android_device via a
provider and cat'd to the misc_info.txt created by android_device

(There are still a lot of diffs between Make and Soong misc_info.txt)

Bug: 398036609
Test: Built Soong's misc_info.txt
Change-Id: I0c49ebaf7a2bac934dca05bcdab65b8521b891ed
diff --git a/filesystem/android_device.go b/filesystem/android_device.go
index bd887c7..3f6348d 100644
--- a/filesystem/android_device.go
+++ b/filesystem/android_device.go
@@ -789,6 +789,21 @@
 			ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
 		}
 	}
+	bootImgNames := []*string{
+		a.partitionProps.Boot_partition_name,
+		a.partitionProps.Init_boot_partition_name,
+		a.partitionProps.Vendor_boot_partition_name,
+	}
+	for _, bootImgName := range bootImgNames {
+		if bootImgName == nil {
+			continue
+		}
+
+		bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(bootImgName), filesystemDepTag)
+		bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider)
+		// cat avb_ metadata of the boot images
+		builder.Command().Text("cat").Input(bootImgInfo.PropFileForMiscInfo).Textf(" >> %s", miscInfo)
+	}
 
 	builder.Build("misc_info", "Building misc_info")
 
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go
index c06c200..7959365 100644
--- a/filesystem/bootimg.go
+++ b/filesystem/bootimg.go
@@ -238,11 +238,12 @@
 	// Set BootimgInfo for building target_files.zip
 	dtbPath := b.getDtbPath(ctx)
 	android.SetProvider(ctx, BootimgInfoProvider, BootimgInfo{
-		Cmdline:    b.properties.Cmdline,
-		Kernel:     kernelPath,
-		Dtb:        dtbPath,
-		Bootconfig: b.getBootconfigPath(ctx),
-		Output:     output,
+		Cmdline:             b.properties.Cmdline,
+		Kernel:              kernelPath,
+		Dtb:                 dtbPath,
+		Bootconfig:          b.getBootconfigPath(ctx),
+		Output:              output,
+		PropFileForMiscInfo: b.buildPropFileForMiscInfo(ctx),
 	})
 
 	extractedPublicKey := android.PathForModuleOut(ctx, b.partitionName()+".avbpubkey")
@@ -285,11 +286,12 @@
 var BootimgInfoProvider = blueprint.NewProvider[BootimgInfo]()
 
 type BootimgInfo struct {
-	Cmdline    []string
-	Kernel     android.Path
-	Dtb        android.Path
-	Bootconfig android.Path
-	Output     android.Path
+	Cmdline             []string
+	Kernel              android.Path
+	Dtb                 android.Path
+	Bootconfig          android.Path
+	Output              android.Path
+	PropFileForMiscInfo android.Path
 }
 
 func (b *bootimg) getKernelPath(ctx android.ModuleContext) android.Path {
@@ -508,6 +510,25 @@
 	return propFile, deps
 }
 
+func (b *bootimg) buildPropFileForMiscInfo(ctx android.ModuleContext) android.Path {
+	var sb strings.Builder
+	addStr := func(name string, value string) {
+		fmt.Fprintf(&sb, "%s=%s\n", name, value)
+	}
+
+	bootImgType := proptools.String(b.properties.Boot_image_type)
+	addStr("avb_"+bootImgType+"_add_hash_footer_args", "TODO(b/398036609)")
+	if b.properties.Avb_private_key != nil {
+		addStr("avb_"+bootImgType+"_algorithm", proptools.StringDefault(b.properties.Avb_algorithm, "SHA256_RSA4096"))
+		addStr("avb_"+bootImgType+"_key_path", android.PathForModuleSrc(ctx, proptools.String(b.properties.Avb_private_key)).String())
+		addStr("avb_"+bootImgType+"_rollback_index_location", strconv.Itoa(proptools.Int(b.properties.Avb_rollback_index_location)))
+	}
+
+	propFile := android.PathForModuleOut(ctx, "prop_for_misc_info")
+	android.WriteFileRuleVerbatim(ctx, propFile, sb.String())
+	return propFile
+}
+
 var _ android.AndroidMkEntriesProvider = (*bootimg)(nil)
 
 // Implements android.AndroidMkEntriesProvider