Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _check_app_installed(self):
# Check that the Mobly Snippet app is installed for the current user.
user_id = self._adb.current_user_id
out = self._adb.shell('pm list package --user %s' % user_id)
if not utils.grep('^package:%s$' % self.package, out):
raise AppStartPreCheckError(
self._ad,
'%s is not installed for user %s.' % (self.package, user_id))
# Check that the app is instrumented.
out = self._adb.shell('pm list instrumentation')
matched_out = utils.grep(
'^instrumentation:%s/%s' %
(self.package, _INSTRUMENTATION_RUNNER_PACKAGE), out)
if not matched_out:
raise AppStartPreCheckError(
self._ad,
'%s is installed, but it is not instrumented.' % self.package)
match = re.search(r'^instrumentation:(.*)\/(.*) \(target=(.*)\)$',
matched_out[0])
target_name = match.group(3)
# Check that the instrumentation target is installed if it's not the
# same as the snippet package.
if target_name != self.package:
out = self._adb.shell('pm list package --user %s' % user_id)
if not utils.grep('^package:%s$' % target_name, out):
raise AppStartPreCheckError(
self._ad,
def start_app_and_connect(self):
"""Overrides superclass."""
# Check that sl4a is installed
out = self._adb.shell('pm list package')
if not utils.grep('com.googlecode.android_scripting', out):
raise jsonrpc_client_base.AppStartError(
self._ad,
'%s is not installed on %s' % (_APP_NAME, self._adb.serial))
self.disable_hidden_api_blacklist()
# sl4a has problems connecting after disconnection, so kill the apk and
# try connecting again.
try:
self.stop_app()
except Exception as e:
self.log.warning(e)
# Launch the app
self.device_port = _DEVICE_SIDE_PORT
self._adb.shell(_LAUNCH_CMD % self.device_port)
def _check_app_installed(self):
# Check that the Mobly Snippet app is installed for the current user.
user_id = self._adb.current_user_id
out = self._adb.shell('pm list package --user %s' % user_id)
if not utils.grep('^package:%s$' % self.package, out):
raise AppStartPreCheckError(
self._ad,
'%s is not installed for user %s.' % (self.package, user_id))
# Check that the app is instrumented.
out = self._adb.shell('pm list instrumentation')
matched_out = utils.grep(
'^instrumentation:%s/%s' %
(self.package, _INSTRUMENTATION_RUNNER_PACKAGE), out)
if not matched_out:
raise AppStartPreCheckError(
self._ad,
'%s is installed, but it is not instrumented.' % self.package)
match = re.search(r'^instrumentation:(.*)\/(.*) \(target=(.*)\)$',
matched_out[0])
target_name = match.group(3)
# Check that the instrumentation target is installed if it's not the