OLD | NEW |
1 # Copyright (C) 2012 Google Inc. All rights reserved. | 1 # Copyright (C) 2012 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 306 |
307 def _log_info(self, message): | 307 def _log_info(self, message): |
308 _log.info('[%s] %s', self._device_serial, message) | 308 _log.info('[%s] %s', self._device_serial, message) |
309 | 309 |
310 def _log_debug(self, message): | 310 def _log_debug(self, message): |
311 if self._debug_logging: | 311 if self._debug_logging: |
312 _log.debug('[%s] %s', self._device_serial, message) | 312 _log.debug('[%s] %s', self._device_serial, message) |
313 | 313 |
314 @staticmethod | 314 @staticmethod |
315 def _determine_adb_version(adb_command_path, executive, debug_logging): | 315 def _determine_adb_version(adb_command_path, executive, debug_logging): |
316 re_version = re.compile('^.*version ([\d\.]+)') | 316 re_version = re.compile(r'^.*version ([\d\.]+)') |
317 try: | 317 try: |
318 output = executive.run_command([adb_command_path, 'version'], error_
handler=executive.ignore_error, | 318 output = executive.run_command([adb_command_path, 'version'], error_
handler=executive.ignore_error, |
319 debug_logging=debug_logging) | 319 debug_logging=debug_logging) |
320 except OSError: | 320 except OSError: |
321 return None | 321 return None |
322 | 322 |
323 result = re_version.match(output) | 323 result = re_version.match(output) |
324 if not output or not result: | 324 if not output or not result: |
325 return None | 325 return None |
326 | 326 |
(...skipping 22 matching lines...) Expand all Loading... |
349 | 349 |
350 if self._default_devices: | 350 if self._default_devices: |
351 self._usable_devices = [ | 351 self._usable_devices = [ |
352 AndroidCommands(executive, d, self._debug_logging) | 352 AndroidCommands(executive, d, self._debug_logging) |
353 for d in self._default_devices] | 353 for d in self._default_devices] |
354 return self._usable_devices | 354 return self._usable_devices |
355 | 355 |
356 # Example "adb devices" command output: | 356 # Example "adb devices" command output: |
357 # List of devices attached | 357 # List of devices attached |
358 # 0123456789ABCDEF device | 358 # 0123456789ABCDEF device |
359 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) | 359 re_device = re.compile(r'^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) |
360 | 360 |
361 result = executive.run_command([AndroidCommands.adb_command_path(executi
ve, debug_logging=self._debug_logging), 'devices'], | 361 result = executive.run_command([AndroidCommands.adb_command_path(executi
ve, debug_logging=self._debug_logging), 'devices'], |
362 error_handler=executive.ignore_error, deb
ug_logging=self._debug_logging) | 362 error_handler=executive.ignore_error, deb
ug_logging=self._debug_logging) |
363 devices = re_device.findall(result) | 363 devices = re_device.findall(result) |
364 if not devices: | 364 if not devices: |
365 return [] | 365 return [] |
366 | 366 |
367 for device_serial in sorted(devices): | 367 for device_serial in sorted(devices): |
368 commands = AndroidCommands(executive, device_serial, self._debug_log
ging) | 368 commands = AndroidCommands(executive, device_serial, self._debug_log
ging) |
369 if self._battery_level_for_device(commands) < AndroidDevices.MINIMUM
_BATTERY_PERCENTAGE: | 369 if self._battery_level_for_device(commands) < AndroidDevices.MINIMUM
_BATTERY_PERCENTAGE: |
(...skipping 22 matching lines...) Expand all Loading... |
392 def set_device_prepared(self, device_serial): | 392 def set_device_prepared(self, device_serial): |
393 self._prepared_devices.append(device_serial) | 393 self._prepared_devices.append(device_serial) |
394 | 394 |
395 # Private methods | 395 # Private methods |
396 def _battery_level_for_device(self, commands): | 396 def _battery_level_for_device(self, commands): |
397 battery_status = commands.run(['shell', 'dumpsys', 'battery']) | 397 battery_status = commands.run(['shell', 'dumpsys', 'battery']) |
398 if 'Error' in battery_status or "Can't find service: battery" in battery
_status: | 398 if 'Error' in battery_status or "Can't find service: battery" in battery
_status: |
399 _log.warning('Unable to read the battery level from device with seri
al "%s".', commands.get_serial()) | 399 _log.warning('Unable to read the battery level from device with seri
al "%s".', commands.get_serial()) |
400 return 0 | 400 return 0 |
401 | 401 |
402 return int(re.findall('level: (\d+)', battery_status)[0]) | 402 return int(re.findall(r'level: (\d+)', battery_status)[0]) |
403 | 403 |
404 def _is_device_screen_on(self, commands): | 404 def _is_device_screen_on(self, commands): |
405 power_status = commands.run(['shell', 'dumpsys', 'power']) | 405 power_status = commands.run(['shell', 'dumpsys', 'power']) |
406 return 'mScreenOn=true' in power_status or 'mScreenOn=SCREEN_ON_BIT' in
power_status or 'Display Power: state=ON' in power_status | 406 return 'mScreenOn=true' in power_status or 'mScreenOn=SCREEN_ON_BIT' in
power_status or 'Display Power: state=ON' in power_status |
407 | 407 |
408 | 408 |
409 class AndroidPort(base.Port): | 409 class AndroidPort(base.Port): |
410 port_name = 'android' | 410 port_name = 'android' |
411 | 411 |
412 # Avoid initializing the adb path [worker count]+1 times by storing it as a
static member. | 412 # Avoid initializing the adb path [worker count]+1 times by storing it as a
static member. |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 return None | 753 return None |
754 | 754 |
755 def _perfhost_path(self): | 755 def _perfhost_path(self): |
756 if self._have_searched_for_perf_host: | 756 if self._have_searched_for_perf_host: |
757 return self._cached_perf_host_path | 757 return self._cached_perf_host_path |
758 self._have_searched_for_perf_host = True | 758 self._have_searched_for_perf_host = True |
759 self._cached_perf_host_path = self._find_perfhost_binary() | 759 self._cached_perf_host_path = self._find_perfhost_binary() |
760 return self._cached_perf_host_path | 760 return self._cached_perf_host_path |
761 | 761 |
762 def _first_ten_lines_of_profile(self, perf_output): | 762 def _first_ten_lines_of_profile(self, perf_output): |
763 match = re.search("^#[^\n]*\n((?: [^\n]*\n){1,10})", perf_output, re.MUL
TILINE) | 763 match = re.search(r"^#[^\n]*\n((?: [^\n]*\n){1,10})", perf_output, re.MU
LTILINE) |
764 return match.group(1) if match else None | 764 return match.group(1) if match else None |
765 | 765 |
766 def profile_after_exit(self): | 766 def profile_after_exit(self): |
767 perf_exitcode = self._perf_process.wait() | 767 perf_exitcode = self._perf_process.wait() |
768 if perf_exitcode != 0: | 768 if perf_exitcode != 0: |
769 _log.debug("Perf failed (exit code: %i), can't process results.", pe
rf_exitcode) | 769 _log.debug("Perf failed (exit code: %i), can't process results.", pe
rf_exitcode) |
770 return | 770 return |
771 | 771 |
772 self._android_commands.pull('/data/perf.data', self._output_path) | 772 self._android_commands.pull('/data/perf.data', self._output_path) |
773 | 773 |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 return command | 1307 return command |
1308 | 1308 |
1309 def _read_prompt(self, deadline): | 1309 def _read_prompt(self, deadline): |
1310 last_char = '' | 1310 last_char = '' |
1311 while True: | 1311 while True: |
1312 current_char = self._server_process.read_stdout(deadline, 1) | 1312 current_char = self._server_process.read_stdout(deadline, 1) |
1313 if current_char == ' ': | 1313 if current_char == ' ': |
1314 if last_char in ('#', '$'): | 1314 if last_char in ('#', '$'): |
1315 return | 1315 return |
1316 last_char = current_char | 1316 last_char = current_char |
OLD | NEW |