More updates to tools/android modules for compatibility with python 3.

RELNOTES: None.
PiperOrigin-RevId: 179577497
diff --git a/tools/android/incremental_install.py b/tools/android/incremental_install.py
index bad2e29..254db27 100644
--- a/tools/android/incremental_install.py
+++ b/tools/android/incremental_install.py
@@ -221,7 +221,7 @@
     """Push a given string to a given path on the device in parallel."""
     local = self._CreateLocalFile()
     with open(local, "wb") as f:
-      f.write(contents)
+      f.write(contents.encode("utf-8"))
     return self.Push(local, remote)
 
   def Pull(self, remote):
@@ -237,7 +237,7 @@
     try:
       self._Exec(["pull", remote, local])
       with open(local, "rb") as f:
-        return f.read()
+        return f.read().decode("utf-8")
     except (AdbError, IOError):
       return None
 
@@ -339,7 +339,7 @@
 def GetAppPackage(stub_datafile):
   """Returns the app package specified in a stub data file."""
   with open(stub_datafile, "rb") as f:
-    return f.readlines()[1].strip()
+    return f.readlines()[1].decode("utf-8").strip()
 
 
 def UploadDexes(adb, execroot, app_dir, temp_dir, dexmanifest, full_install):
@@ -605,7 +605,7 @@
     f.result()
 
   install_manifest = [
-      name + " " + checksum for name, checksum in install_checksums.iteritems()]
+      name + " " + checksum for name, checksum in install_checksums.items()]
   adb.PushString("\n".join(install_manifest),
                  targetpath.join(app_dir, "native",
                                  "native_manifest")).result()
@@ -693,7 +693,7 @@
     adb.InstallMultiple(targetpath.join(execroot, apk), app_package)
 
   install_manifest = [
-      name + " " + checksum for name, checksum in install_checksums.iteritems()]
+      name + " " + checksum for name, checksum in install_checksums.items()]
   adb.PushString("\n".join(install_manifest),
                  targetpath.join(app_dir, "split_manifest")).result()
 
@@ -744,7 +744,7 @@
         VerifyInstallTimestamp(adb, app_package)
 
       with open(hostpath.join(execroot, dexmanifest), "rb") as f:
-        dexmanifest = f.read()
+        dexmanifest = f.read().decode("utf-8")
       UploadDexes(adb, execroot, app_dir, temp_dir, dexmanifest, bool(apk))
       # TODO(ahumesky): UploadDexes waits for all the dexes to be uploaded, and
       # then UploadResources is called. We could instead enqueue everything
@@ -776,16 +776,16 @@
     sys.exit("Error: Device unauthorized. Please check the confirmation "
              "dialog on your device.")
   except MultipleDevicesError as e:
-    sys.exit("Error: " + e.message + "\nTry specifying a device serial with "
+    sys.exit("Error: " + str(e) + "\nTry specifying a device serial with "
              "\"blaze mobile-install --adb_arg=-s --adb_arg=$ANDROID_SERIAL\"")
   except OldSdkException as e:
     sys.exit("Error: The device does not support the API level specified in "
              "the application's manifest. Check minSdkVersion in "
              "AndroidManifest.xml")
   except TimestampException as e:
-    sys.exit("Error:\n%s" % e.message)
+    sys.exit("Error:\n%s" % str(e))
   except AdbError as e:
-    sys.exit("Error:\n%s" % e.message)
+    sys.exit("Error:\n%s" % str(e))
   finally:
     shutil.rmtree(temp_dir, True)