Check if zlib is compatible.

Add a --zlib_fingerprint flag in delta_generator to check if the zlib of
source image is compatible, and only enable IMGDIFF operation if it is.

Test: Added unittest to check /etc/zlib_fingerprint
Bug: 27156099

Change-Id: Ida346a99430c95cdc8a43e1055d6efa08f07ca25
diff --git a/scripts/brillo_update_payload b/scripts/brillo_update_payload
index 75b089d..a3eec4b 100755
--- a/scripts/brillo_update_payload
+++ b/scripts/brillo_update_payload
@@ -200,6 +200,9 @@
 # Path to the postinstall config file in target image if exists.
 POSTINSTALL_CONFIG_FILE=""
 
+# The fingerprint of zlib in the source image.
+ZLIB_FINGERPRINT=""
+
 # read_option_int <file.txt> <option_key> [default_value]
 #
 # Reads the unsigned integer value associated with |option_key| in a key=value
@@ -307,6 +310,11 @@
   # updater supports a newer major version.
   FORCE_MAJOR_VERSION="1"
 
+  if [[ "${partitions_array}" == "SRC_PARTITIONS" ]]; then
+    # Copy from zlib_fingerprint in source image to stdout.
+    ZLIB_FINGERPRINT=$(e2cp "${root}":/etc/zlib_fingerprint -)
+  fi
+
   # When generating legacy Chrome OS images, we need to use "boot" and "system"
   # for the partition names to be compatible with updating Brillo devices with
   # Chrome OS images.
@@ -380,6 +388,10 @@
 Disabling deltas for this source version."
       exit ${EX_UNSUPPORTED_DELTA}
     fi
+
+    if [[ "${FORCE_MINOR_VERSION}" -ge 4 ]]; then
+      ZLIB_FINGERPRINT=$(unzip -p "${image}" "META/zlib_fingerprint.txt")
+    fi
   else
     # Target image
     local postinstall_config=$(create_tempfile "postinstall_config.XXXXXX")
@@ -475,6 +487,9 @@
     if [[ -n "${FORCE_MINOR_VERSION}" ]]; then
       GENERATOR_ARGS+=( --minor_version="${FORCE_MINOR_VERSION}" )
     fi
+    if [[ -n "${ZLIB_FINGERPRINT}" ]]; then
+      GENERATOR_ARGS+=( --zlib_fingerprint="${ZLIB_FINGERPRINT}" )
+    fi
   fi
 
   if [[ -n "${FORCE_MAJOR_VERSION}" ]]; then