More updates to tools/android modules for compatibility with python 3.
RELNOTES: None.
PiperOrigin-RevId: 179577497
diff --git a/tools/android/incremental_install_test.py b/tools/android/incremental_install_test.py
index 1181a59..5eee83f 100644
--- a/tools/android/incremental_install_test.py
+++ b/tools/android/incremental_install_test.py
@@ -49,7 +49,7 @@
if cmd == "push":
# "/test/adb push local remote"
with open(args[2], "rb") as f:
- content = f.read()
+ content = f.read().decode("utf-8")
self.files[args[3]] = content
elif cmd == "pull":
# "/test/adb pull remote local"
@@ -58,7 +58,7 @@
content = self.files.get(remote)
if content is not None:
with open(local, "wb") as f:
- f.write(content)
+ f.write(content.encode("utf-8"))
else:
returncode = 1
stderr = "remote object '%s' does not exist\n" % remote
@@ -69,7 +69,7 @@
elif cmd == "install-multiple":
if args[3] == "-p":
with open(args[5], "rb") as f:
- content = f.read()
+ content = f.read().decode("utf-8")
self.split_apks.add(content)
else:
self.package_timestamp = self._last_package_timestamp
@@ -133,11 +133,12 @@
# Write the stub datafile which contains the package name of the app.
with open(self._STUB_DATAFILE, "wb") as f:
- f.write("\n".join([self._OLD_APP_PACKGE, self._APP_PACKAGE]))
+ f.write(("\n".join([self._OLD_APP_PACKGE, self._APP_PACKAGE]))
+ .encode("utf-8"))
# Write the local resource apk file.
with open(self._RESOURCE_APK, "wb") as f:
- f.write("resource apk")
+ f.write(b"resource apk")
# Mock out subprocess.Popen to use our mock adb.
self._popen_patch = mock.patch.object(incremental_install, "subprocess")
@@ -157,7 +158,7 @@
def _CreateLocalManifest(self, *lines):
content = "\n".join(lines)
with open(self._DEXMANIFEST, "wb") as f:
- f.write(content)
+ f.write(content.encode("utf-8"))
return content
def _CreateRemoteManifest(self, *lines):
@@ -205,7 +206,7 @@
self._CreateZip()
with open("dex1", "wb") as f:
- f.write("content3")
+ f.write(b"content3")
manifest = self._CreateLocalManifest(
"zip1 zp1 ip1 0",
@@ -224,10 +225,10 @@
def testSplitInstallToPristineDevice(self):
with open("split1", "wb") as f:
- f.write("split_content1")
+ f.write(b"split_content1")
with open("main", "wb") as f:
- f.write("main_Content")
+ f.write(b"main_Content")
self._CallIncrementalInstall(
incremental=False, split_main_apk="main", split_apks=["split1"])
@@ -235,10 +236,10 @@
def testSplitInstallUnchanged(self):
with open("split1", "wb") as f:
- f.write("split_content1")
+ f.write(b"split_content1")
with open("main", "wb") as f:
- f.write("main_Content")
+ f.write(b"main_Content")
self._CallIncrementalInstall(
incremental=False, split_main_apk="main", split_apks=["split1"])
@@ -250,17 +251,17 @@
def testSplitInstallChanges(self):
with open("split1", "wb") as f:
- f.write("split_content1")
+ f.write(b"split_content1")
with open("main", "wb") as f:
- f.write("main_Content")
+ f.write(b"main_Content")
self._CallIncrementalInstall(
incremental=False, split_main_apk="main", split_apks=["split1"])
self.assertEqual(set(["split_content1"]), self._mock_adb.split_apks)
with open("split1", "wb") as f:
- f.write("split_content2")
+ f.write(b"split_content2")
self._mock_adb.split_apks = set()
self._CallIncrementalInstall(
incremental=False, split_main_apk="main", split_apks=["split1"])
@@ -269,7 +270,7 @@
def testMissingNativeManifestWithIncrementalInstall(self):
self._CreateZip()
with open("liba.so", "wb") as f:
- f.write("liba_1")
+ f.write(b"liba_1")
# Upload a library to the device.
native_libs = ["armeabi-v7a:liba.so"]
@@ -285,7 +286,7 @@
def testNonIncrementalInstallOverwritesNativeLibs(self):
self._CreateZip()
with open("liba.so", "wb") as f:
- f.write("liba_1")
+ f.write(b"liba_1")
# Upload a library to the device.
native_libs = ["armeabi-v7a:liba.so"]
@@ -305,7 +306,7 @@
def testNativeAbiCompatibility(self):
self._CreateZip()
with open("liba.so", "wb") as f:
- f.write("liba")
+ f.write(b"liba")
native_libs = ["armeabi:liba.so"]
self._mock_adb.SetAbi("arm64-v8a")
@@ -315,9 +316,9 @@
def testUploadNativeLibs(self):
self._CreateZip()
with open("liba.so", "wb") as f:
- f.write("liba_1")
+ f.write(b"liba_1")
with open("libb.so", "wb") as f:
- f.write("libb_1")
+ f.write(b"libb_1")
native_libs = ["armeabi-v7a:liba.so", "armeabi-v7a:libb.so"]
self._CallIncrementalInstall(incremental=False, native_libs=native_libs)
@@ -326,7 +327,7 @@
# Change a library
with open("libb.so", "wb") as f:
- f.write("libb_2")
+ f.write(b"libb_2")
self._CallIncrementalInstall(incremental=True, native_libs=native_libs)
self.assertEqual("libb_2", self._GetDeviceFile("native/libb.so"))
@@ -520,7 +521,7 @@
self._CreateZip()
with open("dex1", "wb") as f:
- f.write("content3")
+ f.write(b"content3")
self._CreateLocalManifest(
"zip1 zp1 ip1 0",
@@ -536,7 +537,7 @@
self._CreateZip()
with open("dex1", "wb") as f:
- f.write("content3")
+ f.write(b"content3")
self._CreateLocalManifest(
"zip1 zp1 ip1 0",