Commit b65dfa3e authored by jbudorick's avatar jbudorick Committed by Commit bot

[Android] Work around pm path bug in L.

Dependent on https://codereview.chromium.org/787393003/

BUG=

Review URL: https://codereview.chromium.org/796503004

Cr-Commit-Position: refs/heads/master@{#308197}
parent 6796a8b5
...@@ -256,8 +256,14 @@ class DeviceUtils(object): ...@@ -256,8 +256,14 @@ class DeviceUtils(object):
Returns: Returns:
Path to the apk on the device if it exists, None otherwise. Path to the apk on the device if it exists, None otherwise.
""" """
# 'pm path' is liable to incorrectly exit with a nonzero number starting
# in Lollipop.
# TODO(jbudorick): Check if this is fixed as new Android versions are
# released to put an upper bound on this.
should_check_return = (self.build_version_sdk <
constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP)
output = self.RunShellCommand(['pm', 'path', package], single_line=True, output = self.RunShellCommand(['pm', 'path', package], single_line=True,
check_return=True) check_return=should_check_return)
if not output: if not output:
return None return None
if not output.startswith('package:'): if not output.startswith('package:'):
......
...@@ -370,19 +370,25 @@ class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsNewImplTest): ...@@ -370,19 +370,25 @@ class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsNewImplTest):
class DeviceUtilsGetApplicationPathTest(DeviceUtilsNewImplTest): class DeviceUtilsGetApplicationPathTest(DeviceUtilsNewImplTest):
def testGetApplicationPath_exists(self): def testGetApplicationPath_exists(self):
with self.assertCall(self.call.adb.Shell('pm path android'), with self.assertCalls(
'package:/path/to/android.apk\n'): (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
(self.call.adb.Shell('pm path android'),
'package:/path/to/android.apk\n')):
self.assertEquals('/path/to/android.apk', self.assertEquals('/path/to/android.apk',
self.device.GetApplicationPath('android')) self.device.GetApplicationPath('android'))
def testGetApplicationPath_notExists(self): def testGetApplicationPath_notExists(self):
with self.assertCall(self.call.adb.Shell('pm path not.installed.app'), ''): with self.assertCalls(
(self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
(self.call.adb.Shell('pm path not.installed.app'), '')):
self.assertEquals(None, self.assertEquals(None,
self.device.GetApplicationPath('not.installed.app')) self.device.GetApplicationPath('not.installed.app'))
def testGetApplicationPath_fails(self): def testGetApplicationPath_fails(self):
with self.assertCall(self.call.adb.Shell('pm path android'), with self.assertCalls(
self.CommandError('ERROR. Is package manager running?\n')): (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
(self.call.adb.Shell('pm path android'),
self.CommandError('ERROR. Is package manager running?\n'))):
with self.assertRaises(device_errors.CommandFailedError): with self.assertRaises(device_errors.CommandFailedError):
self.device.GetApplicationPath('android') self.device.GetApplicationPath('android')
......
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