From 0582cb639f2942d6c6379ba0a5b113f8b9ba6820 Mon Sep 17 00:00:00 2001
From: Tao Bao <tbao@google.com>
Date: Thu, 21 Dec 2017 11:47:01 -0800
Subject: [PATCH] releasetools: Remove the dead code for blockimgdiff_version
 <= 2.

The code is on infeasible path since we already have assertions in
common.BlockDifference().

Also remove the dead code that checks for OPTIONS.info_dict, as we
already set that in ota_from_target_files.main(), for both of A/B and
non-A/B.

Test: Generate incremental OTAs w/ and w/o the CL, and get identical
      packages.
Change-Id: Ifb8fc101e78f5ce58c60c8e49028b66ce0d20246
---
 tools/releasetools/common.py                |  8 ++--
 tools/releasetools/ota_from_target_files.py | 49 ++++++++-------------
 2 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 829b8db9a..12e757dab 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -1431,11 +1431,9 @@ class BlockDifference(object):
     self.disable_imgdiff = disable_imgdiff
 
     if version is None:
-      version = 1
-      if OPTIONS.info_dict:
-        version = max(
-            int(i) for i in
-            OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
+      version = max(
+          int(i) for i in
+          OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
     assert version >= 3
     self.version = version
 
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index c39deb120..d5ac9224a 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -682,11 +682,10 @@ def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip):
   system_src = GetImage("system", OPTIONS.source_tmp)
   system_tgt = GetImage("system", OPTIONS.target_tmp)
 
-  blockimgdiff_version = 1
-  if OPTIONS.info_dict:
-    blockimgdiff_version = max(
-        int(i) for i in
-        OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
+  blockimgdiff_version = max(
+      int(i) for i in
+      OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
+  assert blockimgdiff_version >= 3
 
   # Check the first block of the source system partition for remount R/W only
   # if the filesystem is ext4.
@@ -784,32 +783,20 @@ else if get_stage("%(bcb_dev)s") != "3/3" then
 
   device_specific.IncrementalOTA_VerifyBegin()
 
-  # When blockimgdiff version is less than 3 (non-resumable block-based OTA),
-  # patching on a device that's already on the target build will damage the
-  # system. Because operations like move don't check the block state, they
-  # always apply the changes unconditionally.
-  if blockimgdiff_version <= 2:
-    if source_oem_props is None:
-      script.AssertSomeFingerprint(source_fp)
-    else:
-      script.AssertSomeThumbprint(
-          GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
-
-  else: # blockimgdiff_version > 2
-    if source_oem_props is None and target_oem_props is None:
-      script.AssertSomeFingerprint(source_fp, target_fp)
-    elif source_oem_props is not None and target_oem_props is not None:
-      script.AssertSomeThumbprint(
-          GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
-          GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
-    elif source_oem_props is None and target_oem_props is not None:
-      script.AssertFingerprintOrThumbprint(
-          source_fp,
-          GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict))
-    else:
-      script.AssertFingerprintOrThumbprint(
-          target_fp,
-          GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
+  if source_oem_props is None and target_oem_props is None:
+    script.AssertSomeFingerprint(source_fp, target_fp)
+  elif source_oem_props is not None and target_oem_props is not None:
+    script.AssertSomeThumbprint(
+        GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
+        GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
+  elif source_oem_props is None and target_oem_props is not None:
+    script.AssertFingerprintOrThumbprint(
+        source_fp,
+        GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict))
+  else:
+    script.AssertFingerprintOrThumbprint(
+        target_fp,
+        GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
 
   # Check the required cache size (i.e. stashed blocks).
   size = []