示例#1
0
    def GetAllConnectedDevices(cls):
        device_serials = adb_commands.GetAttachedDevices()
        # The monsoon provides power for the device, so for devices with no
        # real battery, we need to turn them on after the monsoon enables voltage
        # output to the device.
        if not device_serials:
            try:
                m = monsoon.Monsoon(wait=False)
                m.SetUsbPassthrough(1)
                m.SetVoltage(3.8)
                m.SetMaxCurrent(8)
                logging.warn("""
Monsoon power monitor detected, but no Android devices.

The Monsoon's power output has been enabled. Please now ensure that:

  1. The Monsoon's front and back USB are connected to the host.
  2. The device is connected to the Monsoon's main and USB channels.
  3. The device is turned on.

Waiting for device...
""")
                util.WaitFor(adb_commands.GetAttachedDevices, 600)
                device_serials = adb_commands.GetAttachedDevices()
            except IOError:
                return []
        return [cls(s) for s in device_serials]
示例#2
0
 def _GetDeviceAddresses(self, excluded_iface):
     """Returns the IP addresses on all connected devices.
 Excludes interface |excluded_iface| on the selected device.
 """
     my_device = self._adb.GetDevice()
     addresses = []
     for device in adb_commands.GetAttachedDevices():
         adb = adb_commands.AdbCommands(device).Adb()
         if device == my_device:
             excluded = excluded_iface
         else:
             excluded = 'no interfaces excluded on other devices'
         addresses += [
             line.split()[2] for line in adb.RunShellCommand('netcfg')
             if excluded not in line
         ]
     return addresses
示例#3
0
    def testSetUpCommandLineFlagsCmdRemoved(self):
        """Test that the command line file is removed if it did not exist before.

    Requires a device connected to the host.
    """
        serial = adb_commands.GetAttachedDevices()[0]
        cmd_file = '/data/local/tmp/test_cmd'
        adb = adb_commands.AdbCommands(device=serial)
        backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd')
        startup_args = ['--some', '--test', '--args']
        device = adb.device()
        device.RunShellCommand(['rm', '-f', cmd_file], check_return=True)
        with android_command_line_backend.SetUpCommandLineFlags(
                adb, backend_settings, startup_args):
            self.assertEqual('chrome --some --test --args',
                             device.ReadFile(cmd_file).strip())
        self.assertFalse(device.FileExists(cmd_file))
示例#4
0
    def testSetUpCommandLineFlagsCmdRestored(self):
        """Test that a previous command line file is restored.

    Requires a device connected to the host.
    """
        serial = options_for_unittests.GetCopy().device
        if not serial:
            serial = adb_commands.GetAttachedDevices()[0]
        cmd_file = '/data/local/tmp/test_cmd'
        adb = adb_commands.AdbCommands(device=serial)
        backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd')
        startup_args = ['--some', '--test', '--args']
        device = adb.device()
        device.WriteFile(cmd_file, 'chrome --args --to --save')
        with android_command_line_backend.SetUpCommandLineFlags(
                adb, backend_settings, startup_args):
            self.assertEqual('chrome --some --test --args',
                             device.ReadFile(cmd_file).strip())
        self.assertEqual('chrome --args --to --save',
                         device.ReadFile(cmd_file).strip())
        device.RunShellCommand(['rm', '-f', cmd_file], check_return=True)
示例#5
0
def FindAllAvailableBrowsers(finder_options, logging=real_logging):
    """Finds all the desktop browsers available on this machine."""
    if not CanFindAvailableBrowsers(logging=logging):
        logging.info('No adb command found. ' +
                     'Will not try searching for Android browsers.')
        return []

    device = None
    if finder_options.android_device:
        devices = [finder_options.android_device]
    else:
        devices = adb_commands.GetAttachedDevices()

    if len(devices) == 0:
        logging.info('No android devices found.')
        return []

    if len(devices) > 1:
        logging.warn(
            'Multiple devices attached. Please specify one of the following:\n'
            + '\n'.join(['  --device=%s' % d for d in devices]))
        return []

    device = devices[0]

    adb = adb_commands.AdbCommands(device=device)

    if sys.platform.startswith('linux'):
        # Host side workaround for crbug.com/268450 (adb instability)
        # The adb server has a race which is mitigated by binding to a single core.
        import psutil  # pylint: disable=F0401
        pids = [p.pid for p in psutil.process_iter() if 'adb' in p.name]
        with open(os.devnull, 'w') as devnull:
            for pid in pids:
                ret = subprocess.call(['taskset', '-p', '-c', '0',
                                       str(pid)],
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE,
                                      stdin=devnull)
                if ret:
                    logging.warn('Failed to taskset %d (%s)', pid, ret)

        if not os.environ.get('BUILDBOT_BUILDERNAME'):
            # Killing adbd before running tests has proven to make them less likely to
            # flake out during the test. We skip this if Telemetry is running under a
            # buildbot because build/android/test_runner.py wrapper already took care
            # of it before starting the shards.
            adb_commands.CleanupLeftoverProcesses()

    packages = adb.RunShellCommand('pm list packages')
    possible_browsers = []

    for name, package_info in CHROME_PACKAGE_NAMES.iteritems():
        [package, backend_settings, local_apk] = package_info
        b = PossibleAndroidBrowser(name, finder_options,
                                   backend_settings(adb, package), local_apk)

        if 'package:' + package in packages or b.HaveLocalAPK():
            possible_browsers.append(b)

    if possible_browsers:
        installed_prebuilt_tools = adb_commands.SetupPrebuiltTools(adb)
        if not installed_prebuilt_tools:
            logging.error(
                'Android device detected, however prebuilt android tools could not '
                'be used. To run on Android you must build them first:\n'
                '  $ ninja -C out/Release android_tools')
            return []

    return possible_browsers
示例#6
0
def FindAllAvailableBrowsers(finder_options, logging=real_logging):
    """Finds all the desktop browsers available on this machine."""
    if not CanFindAvailableBrowsers(logging=logging):
        logging.info('No adb command found. ' +
                     'Will not try searching for Android browsers.')
        return []

    device = None
    if finder_options.android_device:
        devices = [finder_options.android_device]
    else:
        devices = adb_commands.GetAttachedDevices()

    if len(devices) == 0:
        logging.info('No android devices found.')
        return []

    if len(devices) > 1:
        logging.warn('Multiple devices attached. ' +
                     'Please specify a device explicitly.')
        return []

    device = devices[0]

    adb = adb_commands.AdbCommands(device=device)

    if sys.platform.startswith('linux'):
        # Host side workaround for crbug.com/268450 (adb instability)
        # The adb server has a race which is mitigated by binding to a single core.
        import psutil  # pylint: disable=F0401
        pids = [p.pid for p in psutil.process_iter() if 'adb' in p.name]
        with open(os.devnull, 'w') as devnull:
            for pid in pids:
                ret = subprocess.call(['taskset', '-p', '-c', '0',
                                       str(pid)],
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE,
                                      stdin=devnull)
                if ret:
                    logging.warn('Failed to taskset %d (%s)', pid, ret)

        # Experimental device side workaround for crbug.com/268450 (adb instability)
        # The /sbin/adbd process on the device appears to hang which causes adb to
        # report that the device is offline. Our working theory is that killing
        # the process and allowing it to be automatically relaunched will allow us
        # to run for longer before it hangs.
        if not finder_options.keep_test_server_ports:
            # This would break forwarder connections, so we cannot do this if
            # instructed to keep server ports open.
            logging.info('Killing adbd on device')
            adb.KillAll('adbd')
            logging.info('Waiting for adbd to restart')
            adb.Adb().Adb().SendCommand('wait-for-device')

    packages = adb.RunShellCommand('pm list packages')
    possible_browsers = []

    for name, package_info in CHROME_PACKAGE_NAMES.iteritems():
        [package, backend_settings, local_apk] = package_info
        b = PossibleAndroidBrowser(name, finder_options,
                                   backend_settings(adb, package), local_apk)

        if 'package:' + package in packages or b.HaveLocalAPK():
            possible_browsers.append(b)

    # See if the "forwarder" is installed -- we need this to host content locally
    # but make it accessible to the device.
    if (len(possible_browsers) and not finder_options.android_rndis
            and not adb_commands.HasForwarder()):
        logging.warn('telemetry detected an android device. However,')
        logging.warn('Chrome\'s port-forwarder app is not available.')
        logging.warn(
            'Falling back to prebuilt binaries, but to build locally: ')
        logging.warn('  ninja -C out/Release forwarder2 md5sum')
        logging.warn('')
        logging.warn('')
        if not adb_commands.SetupPrebuiltTools(device):
            return []
    return possible_browsers
示例#7
0
def GetAdb():
    devices = adb_commands.GetAttachedDevices()
    assert len(devices) == 1
    adb = adb_commands.AdbCommands(devices[0])
    adb_commands.SetupPrebuiltTools(adb)
    return adb
示例#8
0
 def _GetDevices():
   if finder_options.android_device:
     return [finder_options.android_device]
   else:
     return adb_commands.GetAttachedDevices()
示例#9
0
 def _SetupAdbCommands(self):
   serial = adb_commands.GetAttachedDevices()[0]
   self.adb = adb_commands.AdbCommands(device=serial)
   self.device = self.adb.device()
示例#10
0
 def __init__(self, application, database):
   self._serial = adb_commands.GetAttachedDevices()[0]
   self._adb = adb_commands.AdbCommands(device=self._serial)
   self._device = self._adb.device()
   self._db = '/data/data/%s/databases/%s' % (application, database)