releasetools: Fix the tag replacement for ro.build.vendor.fingerprint.

For devices using derived fingerprint (i.e. /system/build.prop doesn't
contain ro.build.fingerprint, but has ro.build.thumbprint instead), the
current code (in android.os.Build) doesn't have a matching logic to do
the same for ro.vendor.build.fingerprint. This means we will see
ro.build.thumbprint in /system/build.prop, while there's no matching
ro.vendor.build.thumbprint in /vendor/build.prop.

From signing script point of view, it should just apply the tag
replacement (e.g. test-keys -> release-keys) for whatever it sees when
signing a target_files.zip.

This CL also adds unit tests for EditTags() and RewriteProps().

Fixes: 27950003
Test: Use 'sign_target_files_apks.py' to sign a target that uses derived
      fingerprint and vendor partition. Check VENDOR/build.prop.
Test: python -m unittest test_sign_target_files_apks
Change-Id: I09019da970840cd82f54b68a32b4e94984bc1d8d
diff --git a/tools/releasetools/sign_target_files_apks.py b/tools/releasetools/sign_target_files_apks.py
index f559b29..7bfc04b 100755
--- a/tools/releasetools/sign_target_files_apks.py
+++ b/tools/releasetools/sign_target_files_apks.py
@@ -278,7 +278,7 @@
       if stat.S_ISLNK(info.external_attr >> 16):
         new_data = data
       else:
-        new_data = RewriteProps(data, misc_info)
+        new_data = RewriteProps(data)
       common.ZipWriteStr(output_tf_zip, out_info, new_data)
 
     elif info.filename.endswith("mac_permissions.xml"):
@@ -385,8 +385,14 @@
 
 
 def EditTags(tags):
-  """Given a string containing comma-separated tags, apply the edits
-  specified in OPTIONS.tag_changes and return the updated string."""
+  """Applies the edits to the tag string as specified in OPTIONS.tag_changes.
+
+  Args:
+    tags: The input string that contains comma-separated tags.
+
+  Returns:
+    The updated tags (comma-separated and sorted).
+  """
   tags = set(tags.split(","))
   for ch in OPTIONS.tag_changes:
     if ch[0] == "-":
@@ -396,20 +402,27 @@
   return ",".join(sorted(tags))
 
 
-def RewriteProps(data, misc_info):
+def RewriteProps(data):
+  """Rewrites the system properties in the given string.
+
+  Each property is expected in 'key=value' format. The properties that contain
+  build tags (i.e. test-keys, dev-keys) will be updated accordingly by calling
+  EditTags().
+
+  Args:
+    data: Input string, separated by newlines.
+
+  Returns:
+    The string with modified properties.
+  """
   output = []
   for line in data.split("\n"):
     line = line.strip()
     original_line = line
     if line and line[0] != '#' and "=" in line:
       key, value = line.split("=", 1)
-      if (key in ("ro.build.fingerprint", "ro.vendor.build.fingerprint")
-          and misc_info.get("oem_fingerprint_properties") is None):
-        pieces = value.split("/")
-        pieces[-1] = EditTags(pieces[-1])
-        value = "/".join(pieces)
-      elif (key in ("ro.build.thumbprint", "ro.vendor.build.thumbprint")
-            and misc_info.get("oem_fingerprint_properties") is not None):
+      if key in ("ro.build.fingerprint", "ro.build.thumbprint",
+                 "ro.vendor.build.fingerprint", "ro.vendor.build.thumbprint"):
         pieces = value.split("/")
         pieces[-1] = EditTags(pieces[-1])
         value = "/".join(pieces)