| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import posixpath | 7 import posixpath |
| 8 import re | 8 import re |
| 9 import subprocess | 9 import subprocess |
| 10 import tempfile | 10 import tempfile |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 from devil.android.perf import thermal_throttle | 40 from devil.android.perf import thermal_throttle |
| 41 from devil.android.sdk import version_codes | 41 from devil.android.sdk import version_codes |
| 42 from devil.android.tools import video_recorder | 42 from devil.android.tools import video_recorder |
| 43 | 43 |
| 44 try: | 44 try: |
| 45 from devil.android.perf import surface_stats_collector | 45 from devil.android.perf import surface_stats_collector |
| 46 except Exception: | 46 except Exception: |
| 47 surface_stats_collector = None | 47 surface_stats_collector = None |
| 48 | 48 |
| 49 | 49 |
| 50 _ARCH_TO_STACK_TOOL_ARCH = { |
| 51 'armeabi-v7a': 'arm', |
| 52 'arm64-v8a': 'arm64', |
| 53 } |
| 50 _DEVICE_COPY_SCRIPT_FILE = os.path.abspath(os.path.join( | 54 _DEVICE_COPY_SCRIPT_FILE = os.path.abspath(os.path.join( |
| 51 os.path.dirname(__file__), 'efficient_android_directory_copy.sh')) | 55 os.path.dirname(__file__), 'efficient_android_directory_copy.sh')) |
| 52 _DEVICE_COPY_SCRIPT_LOCATION = ( | 56 _DEVICE_COPY_SCRIPT_LOCATION = ( |
| 53 '/data/local/tmp/efficient_android_directory_copy.sh') | 57 '/data/local/tmp/efficient_android_directory_copy.sh') |
| 54 | 58 |
| 55 # TODO(nednguyen): Remove this method and update the client config to point to | 59 # TODO(nednguyen): Remove this method and update the client config to point to |
| 56 # the correct binary instead. | 60 # the correct binary instead. |
| 57 def _FindLocallyBuiltPath(binary_name): | 61 def _FindLocallyBuiltPath(binary_name): |
| 58 """Finds the most recently built |binary_name|.""" | 62 """Finds the most recently built |binary_name|.""" |
| 59 command = None | 63 command = None |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 This allows transparent HTTPS testing with WPR server without need | 512 This allows transparent HTTPS testing with WPR server without need |
| 509 to tweak application network stack. | 513 to tweak application network stack. |
| 510 | 514 |
| 511 Note: If this method fails with any exception, then RemoveTestCa will be | 515 Note: If this method fails with any exception, then RemoveTestCa will be |
| 512 automatically called by the network_controller_backend. | 516 automatically called by the network_controller_backend. |
| 513 """ | 517 """ |
| 514 if self._device_cert_util is not None: | 518 if self._device_cert_util is not None: |
| 515 logging.warning('Test certificate authority is already installed.') | 519 logging.warning('Test certificate authority is already installed.') |
| 516 return | 520 return |
| 517 self._device_cert_util = adb_install_cert.AndroidCertInstaller( | 521 self._device_cert_util = adb_install_cert.AndroidCertInstaller( |
| 518 self._device.adb.GetDeviceSerial(), None, ca_cert_path) | 522 self._device.adb.GetDeviceSerial(), None, ca_cert_path, |
| 523 adb_path=self._device.adb.GetAdbPath()) |
| 519 self._device_cert_util.install_cert(overwrite_cert=True) | 524 self._device_cert_util.install_cert(overwrite_cert=True) |
| 520 | 525 |
| 521 def RemoveTestCa(self): | 526 def RemoveTestCa(self): |
| 522 """Remove root CA from device installed by InstallTestCa. | 527 """Remove root CA from device installed by InstallTestCa. |
| 523 | 528 |
| 524 Note: Any exceptions raised by this method will be logged but dismissed by | 529 Note: Any exceptions raised by this method will be logged but dismissed by |
| 525 the network_controller_backend. | 530 the network_controller_backend. |
| 526 """ | 531 """ |
| 527 if self._device_cert_util is not None: | 532 if self._device_cert_util is not None: |
| 528 try: | 533 try: |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 self._device.RunShellCommand( | 647 self._device.RunShellCommand( |
| 643 ['am', 'set-debug-app', '--persistent', package]) | 648 ['am', 'set-debug-app', '--persistent', package]) |
| 644 | 649 |
| 645 def GetLogCat(self, number_of_lines=500): | 650 def GetLogCat(self, number_of_lines=500): |
| 646 """Returns most recent lines of logcat dump. | 651 """Returns most recent lines of logcat dump. |
| 647 | 652 |
| 648 Args: | 653 Args: |
| 649 number_of_lines: Number of lines of log to return. | 654 number_of_lines: Number of lines of log to return. |
| 650 """ | 655 """ |
| 651 return '\n'.join(self._device.RunShellCommand( | 656 return '\n'.join(self._device.RunShellCommand( |
| 652 ['logcat', '-d', '-t', str(number_of_lines)])) | 657 ['logcat', '-d', '-t', str(number_of_lines)], |
| 658 check_return=True, large_output=True)) |
| 653 | 659 |
| 654 def GetStandardOutput(self): | 660 def GetStandardOutput(self): |
| 655 return None | 661 return 'Cannot get standard output on Android' |
| 656 | 662 |
| 657 def GetStackTrace(self): | 663 def GetStackTrace(self): |
| 658 """Returns stack trace. | 664 """Returns stack trace. |
| 659 | 665 |
| 660 The stack trace consists of raw logcat dump, logcat dump with symbols, | 666 The stack trace consists of raw logcat dump, logcat dump with symbols, |
| 661 and stack info from tomstone files. | 667 and stack info from tomstone files. |
| 662 """ | 668 """ |
| 663 def Decorate(title, content): | 669 def Decorate(title, content): |
| 664 return "%s\n%s\n%s\n" % (title, content, '*' * 80) | 670 return "%s\n%s\n%s\n" % (title, content, '*' * 80) |
| 665 | 671 |
| 666 # Get the UI nodes that can be found on the screen | 672 # Get the UI nodes that can be found on the screen |
| 667 ret = Decorate('UI dump', '\n'.join(self.GetSystemUi().ScreenDump())) | 673 ret = Decorate('UI dump', '\n'.join(self.GetSystemUi().ScreenDump())) |
| 668 | 674 |
| 669 # Get the last lines of logcat (large enough to contain stacktrace) | 675 # Get the last lines of logcat (large enough to contain stacktrace) |
| 670 logcat = self.GetLogCat() | 676 logcat = self.GetLogCat() |
| 671 ret += Decorate('Logcat', logcat) | 677 ret += Decorate('Logcat', logcat) |
| 672 stack = os.path.join(util.GetChromiumSrcDir(), 'third_party', | 678 stack = os.path.join(util.GetChromiumSrcDir(), 'third_party', |
| 673 'android_platform', 'development', 'scripts', 'stack') | 679 'android_platform', 'development', 'scripts', 'stack') |
| 674 # Try to symbolize logcat. | 680 # Try to symbolize logcat. |
| 675 if os.path.exists(stack): | 681 if os.path.exists(stack): |
| 676 cmd = [stack] | 682 cmd = [stack] |
| 677 cmd.append('--arch=%s' % self.GetArchName()) | 683 arch = self.GetArchName() |
| 684 arch = _ARCH_TO_STACK_TOOL_ARCH.get(arch, arch) |
| 685 cmd.append('--arch=%s' % arch) |
| 678 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | 686 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
| 679 ret += Decorate('Stack from Logcat', p.communicate(input=logcat)[0]) | 687 ret += Decorate('Stack from Logcat', p.communicate(input=logcat)[0]) |
| 680 | 688 |
| 681 # Try to get tombstones. | 689 # Try to get tombstones. |
| 682 tombstones = os.path.join(util.GetChromiumSrcDir(), 'build', 'android', | 690 tombstones = os.path.join(util.GetChromiumSrcDir(), 'build', 'android', |
| 683 'tombstones.py') | 691 'tombstones.py') |
| 684 if os.path.exists(tombstones): | 692 if os.path.exists(tombstones): |
| 685 ret += Decorate('Tombstones', | 693 ret += Decorate('Tombstones', |
| 686 subprocess.Popen([tombstones, '-w', '--device', | 694 subprocess.Popen([tombstones, '-w', '--device', |
| 687 self._device.adb.GetDeviceSerial()], | 695 self._device.adb.GetDeviceSerial()], |
| 688 stdout=subprocess.PIPE).communicate()[0]) | 696 stdout=subprocess.PIPE).communicate()[0]) |
| 689 return (True, ret) | 697 return (True, ret) |
| 690 | 698 |
| 699 def GetMinidumpPath(self): |
| 700 return None |
| 701 |
| 691 def IsScreenOn(self): | 702 def IsScreenOn(self): |
| 692 """Determines if device screen is on.""" | 703 """Determines if device screen is on.""" |
| 693 return self._device.IsScreenOn() | 704 return self._device.IsScreenOn() |
| 694 | 705 |
| 695 @staticmethod | 706 @staticmethod |
| 696 def _IsScreenLocked(input_methods): | 707 def _IsScreenLocked(input_methods): |
| 697 """Parser method for IsScreenLocked() | 708 """Parser method for IsScreenLocked() |
| 698 | 709 |
| 699 Args: | 710 Args: |
| 700 input_methods: Output from dumpsys input_methods | 711 input_methods: Output from dumpsys input_methods |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 for process in psutil.process_iter(): | 753 for process in psutil.process_iter(): |
| 743 try: | 754 try: |
| 744 if psutil.version_info >= (2, 0): | 755 if psutil.version_info >= (2, 0): |
| 745 if 'adb' in process.name(): | 756 if 'adb' in process.name(): |
| 746 process.cpu_affinity([0]) | 757 process.cpu_affinity([0]) |
| 747 else: | 758 else: |
| 748 if 'adb' in process.name: | 759 if 'adb' in process.name: |
| 749 process.set_cpu_affinity([0]) | 760 process.set_cpu_affinity([0]) |
| 750 except (psutil.NoSuchProcess, psutil.AccessDenied): | 761 except (psutil.NoSuchProcess, psutil.AccessDenied): |
| 751 logging.warn('Failed to set adb process CPU affinity') | 762 logging.warn('Failed to set adb process CPU affinity') |
| OLD | NEW |