add UnmountAll function to OTA script; support radio images w/path

Three unrelated changes:

- change the add-radio-file makefile function to support adding files
  with paths.  (The path part of the pathname is stripped off.)

- add an UnmountAll function to the OTA script generation code, so
  that we can explicitly unmount everything we've mounted (in addition
  to doing it automatically at the end of the script).

- add the updater API version to the info object passed to
  device-specific code.

Change-Id: Ia62b15403c1cc8fce8d9910f291450c8077e49f4
diff --git a/core/definitions.mk b/core/definitions.mk
index 0df723a..7e7f9f1 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1690,12 +1690,12 @@
 # INSTALLED_RADIOIMAGE_TARGET.
 # $(1): filename
 define add-radio-file
-  $(eval $(call add-radio-file-internal,$(1)))
+  $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
 endef
 define add-radio-file-internal
-INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(1)
-ALL_PREBUILT += $$(PRODUCT_OUT)/$(1)
-$$(PRODUCT_OUT)/$(1) : $$(LOCAL_PATH)/$(1) | $$(ACP)
+INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
+ALL_PREBUILT += $$(PRODUCT_OUT)/$(2)
+$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
 	$$(transform-prebuilt-to-target)
 endef
 
diff --git a/tools/releasetools/amend_generator.py b/tools/releasetools/amend_generator.py
index f8f4344..f3dceca 100644
--- a/tools/releasetools/amend_generator.py
+++ b/tools/releasetools/amend_generator.py
@@ -192,6 +192,9 @@
     """Append text verbatim to the output script."""
     self.script.append(extra)
 
+  def UnmountAll(self):
+    pass
+
   def AddToZip(self, input_zip, output_zip, input_path=None):
     """Write the accumulated script to the output_zip file.  input_zip
     is used as the source for any ancillary binaries needed by the
diff --git a/tools/releasetools/both_generator.py b/tools/releasetools/both_generator.py
index df2a659..c042ae6 100644
--- a/tools/releasetools/both_generator.py
+++ b/tools/releasetools/both_generator.py
@@ -55,6 +55,7 @@
   def SetPermissionsRecursive(self, *a): self._DoBoth("SetPermissionsRecursive", *a)
   def MakeSymlinks(self, *a): self._DoBoth("MakeSymlinks", *a)
   def AppendExtra(self, *a): self._DoBoth("AppendExtra", *a)
+  def UnmountAll(self, *a): self._DoBoth("UnmountAll", *a)
 
   def AddToZip(self, input_zip, output_zip, input_path=None):
     self._DoBoth("AddToZip", input_zip, output_zip, input_path)
diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py
index d1902e1..64bd547 100644
--- a/tools/releasetools/edify_generator.py
+++ b/tools/releasetools/edify_generator.py
@@ -213,14 +213,18 @@
     """Append text verbatim to the output script."""
     self.script.append(extra)
 
+  def UnmountAll(self):
+    for p in sorted(self.mounts):
+      self.script.append('unmount("%s");' % (p,))
+    self.mounts = set()
+
   def AddToZip(self, input_zip, output_zip, input_path=None):
     """Write the accumulated script to the output_zip file.  input_zip
     is used as the source for the 'updater' binary needed to run
     script.  If input_path is not None, it will be used as a local
     path for the binary instead of input_zip."""
 
-    for p in sorted(self.mounts):
-      self.script.append('unmount("%s");' % (p,))
+    self.UnmountAll()
 
     common.ZipWriteStr(output_zip, "META-INF/com/google/android/updater-script",
                        "\n".join(self.script) + "\n")
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index f129da1..dddaafc 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -340,6 +340,7 @@
 
   device_specific = common.DeviceSpecificParams(
       input_zip=input_zip,
+      input_version=GetRecoveryAPIVersion(input_zip),
       output_zip=output_zip,
       script=script,
       input_tmp=OPTIONS.input_tmp)
@@ -393,6 +394,7 @@
   if OPTIONS.extra_script is not None:
     script.AppendExtra(OPTIONS.extra_script)
 
+  script.UnmountAll()
   script.AddToZip(input_zip, output_zip)
 
 
@@ -562,6 +564,7 @@
 
 def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
   source_version = GetRecoveryAPIVersion(source_zip)
+  target_version = GetRecoveryAPIVersion(target_zip)
 
   if OPTIONS.script_mode == 'amend':
     script = amend_generator.AmendGenerator()
@@ -580,7 +583,9 @@
 
   device_specific = common.DeviceSpecificParams(
       source_zip=source_zip,
+      source_version=source_version,
       target_zip=target_zip,
+      target_version=target_version,
       output_zip=output_zip,
       script=script)