Set avb_hash_algorithm=sha256 for system & vendor img

This sets the hash_algorithm used in add_hashtree_footer to sha256
(which otherwise defaults to sha1).

Also set hash_algorithm flag in sign_virt_apex

Bug: 262892300
Test: (Using avbtool) Check the image_info microdroid.img &
microdroid_vendor.img
Ignore-AOSP-First: This is a cherry-pick. Change already exist in AOSP
Merged-In: I4e17e38bd2d2c4ab0e2041c25ebde74c59e289cf
Merged-In: Ibdeaa0ab9a5e0b21cb5ec88940c6a8f968f897df

Change-Id: I8c4f3bc5bda4d1e361b16121b08c43bb7047b611
(cherry picked from commit 94d7faa228c828abbbfda212f2e4abfa27d00b25)
Merged-In: I8c4f3bc5bda4d1e361b16121b08c43bb7047b611
diff --git a/apex/sign_virt_apex.py b/apex/sign_virt_apex.py
index a1e81d2..5df1fb1 100644
--- a/apex/sign_virt_apex.py
+++ b/apex/sign_virt_apex.py
@@ -239,14 +239,15 @@
         image_size = ReadBytesSize(info['Image size'])
         algorithm = info['Algorithm']
         partition_name = descriptor['Partition Name']
+        hash_algorithm = descriptor['Hash Algorithm']
         partition_size = str(image_size)
-
         cmd = ['avbtool', 'add_hashtree_footer',
                '--key', key,
                '--algorithm', algorithm,
                '--partition_name', partition_name,
                '--partition_size', partition_size,
                '--do_not_generate_fec',
+               '--hash_algorithm', hash_algorithm,
                '--image', image_path]
         if args.signing_args:
             cmd.extend(shlex.split(args.signing_args))
diff --git a/microdroid/Android.bp b/microdroid/Android.bp
index 3be7eaa..d1a93c3 100644
--- a/microdroid/Android.bp
+++ b/microdroid/Android.bp
@@ -46,6 +46,7 @@
     use_avb: true,
     avb_private_key: ":microdroid_sign_key",
     avb_algorithm: "SHA256_RSA4096",
+    avb_hash_algorithm: "sha256",
     partition_name: "system",
     deps: [
         "init_second_stage",
@@ -206,6 +207,7 @@
     },
     avb_private_key: ":microdroid_sign_key",
     avb_algorithm: "SHA256_RSA4096",
+    avb_hash_algorithm: "sha256",
     file_contexts: ":microdroid_vendor_file_contexts.gen",
 }