Reland: Pass apex_info.pb file to delta_generator

target_files contain META/apex_info.pb, which contains metadata about
compressed apexes. Extract this file from target_file.zip, and pass it
to delta_generator. delta_generator will then copy these data to
update_metadata

Test: generate an OTA, make sure a device running an older build can
install the OTA
Bug: 172911822

Change-Id: If0e185a32262a849d533c3316ffdf205cb6628b6
diff --git a/scripts/brillo_update_payload b/scripts/brillo_update_payload
index 439a42a..c510148 100755
--- a/scripts/brillo_update_payload
+++ b/scripts/brillo_update_payload
@@ -284,6 +284,9 @@
 # Path to the dynamic partition info file in target image if exists.
 DYNAMIC_PARTITION_INFO_FILE=""
 
+# Path to the META/apex_info.pb found in target build
+APEX_INFO_FILE=""
+
 # read_option_int <file.txt> <option_key> [default_value]
 #
 # Reads the unsigned integer value associated with |option_key| in a key=value
@@ -567,6 +570,13 @@
         "${dynamic_partitions_info}"
       DYNAMIC_PARTITION_INFO_FILE="${dynamic_partitions_info}"
     fi
+    local apex_info=$(create_tempfile "apex_info.XXXXXX")
+    CLEANUP_FILES+=("${apex_info}")
+    if unzip -l "${image}" "META/apex_info.pb" > /dev/null; then
+      extract_file "${image}" "META/apex_info.pb" \
+        "${apex_info}"
+      APEX_INFO_FILE="${apex_info}"
+    fi
   fi
 
   local part
@@ -734,6 +744,11 @@
       --dynamic_partition_info_file="${DYNAMIC_PARTITION_INFO_FILE}"
     )
   fi
+  if [[ -n "{APEX_INFO_FILE}" ]]; then
+    GENERATOR_ARGS+=(
+      --apex_info_file="${APEX_INFO_FILE}"
+    )
+  fi
 
   echo "Running delta_generator with args: ${GENERATOR_ARGS[@]}"
   "${GENERATOR}" "${GENERATOR_ARGS[@]}"