py2to3: update tools/android/*.py to PY3

Details:
- use six.ensure_str / six.ensure_bytes
- use absl.flags instead of gflags
- put third_party/py/abseil:srcs into @bazel_tools
  so the embedded Android tools can also use it
- remove python_version = "PY2" from py_binary and
  py_test rules (the default is "PY3"), except in
  BUILD.tools, to preserve PY2 compatibility for
  running Bazel (its embedded Python tools)
- added srcs_version = "PY2AND3" to BUILD.tools to
  make it explicit that these libraries are meant
  to be py2 and py3 compatible

See https://github.com/bazelbuild/bazel/issues/10127

PiperOrigin-RevId: 278320319
diff --git a/tools/android/incremental_install_test.py b/tools/android/incremental_install_test.py
index 5eee83f..359eacd 100644
--- a/tools/android/incremental_install_test.py
+++ b/tools/android/incremental_install_test.py
@@ -1,3 +1,4 @@
+# Lint as: python2, python3
 # pylint: disable=g-direct-third-party-import
 # Copyright 2015 The Bazel Authors. All rights reserved.
 #
@@ -15,12 +16,18 @@
 
 """Unit tests for stubify_incremental_install."""
 
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
 import os
 import unittest
 import zipfile
 
-from tools.android import incremental_install
 from third_party.py import mock
+import six
+
+from tools.android import incremental_install
 
 
 class MockAdb(object):
@@ -58,7 +65,7 @@
       content = self.files.get(remote)
       if content is not None:
         with open(local, "wb") as f:
-          f.write(content.encode("utf-8"))
+          f.write(six.ensure_binary(content, "utf-8"))
       else:
         returncode = 1
         stderr = "remote object '%s' does not exist\n" % remote
@@ -86,16 +93,16 @@
       self.shell_cmdlns.append(shell_cmdln)
       if shell_cmdln.startswith(("mkdir", "am", "monkey", "input")):
         pass
-      elif shell_cmdln.startswith("dumpsys package "):
+      elif six.ensure_str(shell_cmdln).startswith("dumpsys package "):
         if self.package_timestamp is not None:
           timestamp = "firstInstallTime=%s" % self.package_timestamp
         else:
           timestamp = ""
         return self._CreatePopenMock(0, timestamp, "")
-      elif shell_cmdln.startswith("rm"):
+      elif six.ensure_str(shell_cmdln).startswith("rm"):
         file_path = shell_cmdln.split()[2]
         self.files.pop(file_path, None)
-      elif shell_cmdln.startswith("getprop ro.product.cpu.abi"):
+      elif six.ensure_str(shell_cmdln).startswith("getprop ro.product.cpu.abi"):
         return self._CreatePopenMock(0, self.abi, "")
       else:
         raise Exception("Unknown shell command line: %s" % shell_cmdln)