def load_device(self, serial=None): """Creates an AndroidDevice for the given serial number. If no serial is given, it will read from the ANDROID_SERIAL environmental variable. If the environmental variable is not set, then it will read from 'adb devices' if there is only one. """ serials = android_device.list_adb_devices() if not serials: raise Error('No adb device found!') # No serial provided, try to pick up the device automatically. if not serial: env_serial = os.environ.get('ANDROID_SERIAL', None) if env_serial is not None: serial = env_serial elif len(serials) == 1: serial = serials[0] else: raise Error( 'Expected one phone, but %d found. Use the -s flag or ' 'specify ANDROID_SERIAL.' % len(serials)) if serial not in serials: raise Error('Device "%s" is not found by adb.' % serial) ads = android_device.get_instances([serial]) assert len(ads) == 1 self._ad = ads[0]
def load_device(self, serial=None): """Creates an AndroidDevice for the given serial number. If no serial is given, it will be read from 'adb devices' if there is only one. """ serials = android_device.list_adb_devices() if not serials: raise Error('No adb device found!') # No serial provided, try to pick up the device automatically. if not serial: if len(serials) != 1: raise Error( 'Expected one phone, but %d found. Use the -s flag.' % len(serials)) serial = serials[0] if serial not in serials: raise Error('Device "%s" is not found by adb.' % serial) ads = android_device.get_instances([serial]) assert len(ads) == 1 self._ad = ads[0]
def _wait_for_device(self, ad): while ad.serial not in android_device.list_adb_devices(): pass ad.adb.wait_for_device()