Commit b4a597e5 authored by Jim Beveridge's avatar Jim Beveridge

Fixed adb version checking per code review

parent dd59d6dc
...@@ -27,7 +27,6 @@ ADB_PATH = 'adb' ...@@ -27,7 +27,6 @@ ADB_PATH = 'adb'
APK_NAME = 'SkyShell.apk' APK_NAME = 'SkyShell.apk'
ANDROID_PACKAGE = "org.domokit.sky.shell" ANDROID_PACKAGE = "org.domokit.sky.shell"
ANDROID_COMPONENT = '%s/%s.SkyActivity' % (ANDROID_PACKAGE, ANDROID_PACKAGE) ANDROID_COMPONENT = '%s/%s.SkyActivity' % (ANDROID_PACKAGE, ANDROID_PACKAGE)
ANDROID_HOME_DIR = ""
# FIXME: Do we need to look in $DART_SDK? # FIXME: Do we need to look in $DART_SDK?
DART_PATH = 'dart' DART_PATH = 'dart'
...@@ -297,18 +296,31 @@ class SkyShellRunner(object): ...@@ -297,18 +296,31 @@ class SkyShellRunner(object):
android_home_dir = os.environ['ANDROID_HOME'] android_home_dir = os.environ['ANDROID_HOME']
ADB_PATH = os.path.join(android_home_dir, 'sdk/platform-tools/adb') ADB_PATH = os.path.join(android_home_dir, 'sdk/platform-tools/adb')
def _is_valid_adb_version(self, adb_version):
# Sample output: "Android Debug Bridge version 1.0.31"
version_fields = re.search('(\d+)\.(\d+)\.(\d+)', adb_version)
if version_fields:
major_version = int(version_fields.group(1))
minor_version = int(version_fields.group(2))
patch_version = int(version_fields.group(3))
if major_version > 1:
return True
if major_version == 1 and minor_version > 0:
return True
if major_version == 1 and minor_version == 0 and patch_version >= 32:
return True
return False
else:
logging.warn('Unrecognized adb version string. Skipping version check.')
return True
def _check_for_adb(self): def _check_for_adb(self):
try: try:
adb_version = subprocess.check_output([ADB_PATH, 'version']) adb_version = subprocess.check_output([ADB_PATH, 'version'])
# Sample output: "Android Debug Bridge version 1.0.31" if self._is_valid_adb_version(adb_version):
version_fields = adb_version.rstrip().split('.') return True
# If the string doesn't match the expected format, then skip the
# version check. adb_path = subprocess.check_output( ['which', ADB_PATH]).rstrip()
if len(version_fields) == 3 and version_fields[-1].isdigit():
minor_version = int(version_fields[-1])
if minor_version < 32:
adb_path = subprocess.check_output(
['which', ADB_PATH]).rstrip()
logging.error("'%s' is too old. Need 1.0.32 or later. " \ logging.error("'%s' is too old. Need 1.0.32 or later. " \
"Try setting ANDROID_HOME." % adb_path) "Try setting ANDROID_HOME." % adb_path)
return False return False
...@@ -322,12 +334,12 @@ class SkyShellRunner(object): ...@@ -322,12 +334,12 @@ class SkyShellRunner(object):
try: try:
# If the server is automatically restarted, then we get irrelevant # If the server is automatically restarted, then we get irrelevant
# output lines like this, which we want to ignore: # output lines like this, which we want to ignore:
# ERROR:Unexpected response from getprop: 'adb server is out of date. killing.. # adb server is out of date. killing..
# * daemon started successfully * # * daemon started successfully *
subprocess.call([ADB_PATH, 'start-server']) subprocess.call([ADB_PATH, 'start-server'])
sdk_version = subprocess.check_output([ADB_PATH, 'shell', 'getprop', sdk_version = subprocess.check_output(
'ro.build.version.sdk']).rstrip() [ADB_PATH, 'shell', 'getprop', 'ro.build.version.sdk']).rstrip()
# Sample output: "22" # Sample output: "22"
if not sdk_version.isdigit(): if not sdk_version.isdigit():
logging.error("Unexpected response from getprop: '%s'." % sdk_version) logging.error("Unexpected response from getprop: '%s'." % sdk_version)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment