Skip to content

Commit

Permalink
[Android] Work around pm path bug in L.
Browse files Browse the repository at this point in the history
Dependent on https://codereview.chromium.org/787393003/

BUG=

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

Cr-Commit-Position: refs/heads/master@{#308197}
  • Loading branch information
jbudorick authored and Commit bot committed Dec 12, 2014
1 parent 6796a8b commit b65dfa3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion build/android/pylib/device/device_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,14 @@ def GetApplicationPath(self, package, timeout=None, retries=None):
Returns:
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,
check_return=True)
check_return=should_check_return)
if not output:
return None
if not output.startswith('package:'):
Expand Down
16 changes: 11 additions & 5 deletions build/android/pylib/device/device_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,25 @@ def testGetExternalStoragePath_fails(self):
class DeviceUtilsGetApplicationPathTest(DeviceUtilsNewImplTest):

def testGetApplicationPath_exists(self):
with self.assertCall(self.call.adb.Shell('pm path android'),
'package:/path/to/android.apk\n'):
with self.assertCalls(
(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.device.GetApplicationPath('android'))

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.device.GetApplicationPath('not.installed.app'))

def testGetApplicationPath_fails(self):
with self.assertCall(self.call.adb.Shell('pm path android'),
self.CommandError('ERROR. Is package manager running?\n')):
with self.assertCalls(
(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):
self.device.GetApplicationPath('android')

Expand Down

0 comments on commit b65dfa3

Please sign in to comment.