def SetProperties(device, options): try: device.EnableRoot() except device_errors.CommandFailedError as e: logging.warning(str(e)) _ConfigureLocalProperties(device, options.enable_java_debug) device_settings.ConfigureContentSettings( device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) if options.disable_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_LOCATION_SETTINGS) if options.disable_mock_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_MOCK_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_MOCK_LOCATION_SETTINGS) device_settings.SetLockScreenSettings(device) if options.disable_network: device_settings.ConfigureContentSettings( device, device_settings.NETWORK_DISABLED_SETTINGS)
def SetProperties(device, options): try: device.EnableRoot() except device_errors.CommandFailedError as e: logging.warning(str(e)) _ConfigureLocalProperties(device, options.enable_java_debug) device_settings.ConfigureContentSettings( device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) if options.disable_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_LOCATION_SETTINGS) device_settings.SetLockScreenSettings(device) if options.disable_network: device_settings.ConfigureContentSettings( device, device_settings.NETWORK_DISABLED_SETTINGS) if options.min_battery_level is not None: try: battery = battery_utils.BatteryUtils(device) battery.ChargeDeviceToLevel(options.min_battery_level) except device_errors.CommandFailedError as e: logging.exception('Unable to charge device to specified level.') if options.max_battery_temp is not None: try: battery = battery_utils.BatteryUtils(device) battery.LetBatteryCoolToTemperature(options.max_battery_temp) except device_errors.CommandFailedError as e: logging.exception( 'Unable to let battery cool to specified temperature.')
def ProvisionDevice(device, options): try: if not options.skip_wipe: WipeDeviceIfPossible(device, options.reboot_timeout) try: device.EnableRoot() except device_errors.CommandFailedError as e: logging.warning(str(e)) _ConfigureLocalProperties(device, options.enable_java_debug) device_settings.ConfigureContentSettings( device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) if options.disable_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_LOCATION_SETTINGS) device_settings.SetLockScreenSettings(device) if options.disable_network: device_settings.ConfigureContentSettings( device, device_settings.NETWORK_DISABLED_SETTINGS) if options.wait_for_battery: try: battery_info = device.old_interface.GetBatteryInfo() except Exception as e: battery_info = {} logging.error('Unable to obtain battery info for %s, %s', str(device), e) while int(battery_info.get('level', 100)) < options.min_battery_level: if not device.old_interface.IsDeviceCharging(): if device.old_interface.CanControlUsbCharging(): device.old_interface.EnableUsbCharging() else: logging.error('Device is not charging') break logging.info('Waiting for device to charge. Current level=%s', battery_info.get('level', 0)) time.sleep(60) battery_info = device.old_interface.GetBatteryInfo() if not options.skip_wipe: device.Reboot(True, timeout=options.reboot_timeout, retries=0) device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', time.gmtime()), as_root=True) props = device.RunShellCommand('getprop') for prop in props: logging.info(' %s' % prop) if options.auto_reconnect: PushAndLaunchAdbReboot(device, options.target) except (errors.WaitForResponseTimedOutError, device_errors.CommandTimeoutError): logging.info('Timed out waiting for device %s. Adding to blacklist.', str(device)) # Device black list is reset by bb_device_status_check.py per build. device_blacklist.ExtendBlacklist([str(device)]) except device_errors.CommandFailedError: logging.exception('Failed to provision device %s. Adding to blacklist.', str(device)) device_blacklist.ExtendBlacklist([str(device)])
def ProvisionDevice(device, options): if options.reboot_timeout: reboot_timeout = options.reboot_timeout elif (device.build_version_sdk >= constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP else: reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP try: if not options.skip_wipe: WipeDeviceIfPossible(device, reboot_timeout, options) try: device.EnableRoot() except device_errors.CommandFailedError as e: logging.warning(str(e)) _ConfigureLocalProperties(device, options.enable_java_debug) device_settings.ConfigureContentSettings( device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) if options.disable_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_LOCATION_SETTINGS) device_settings.SetLockScreenSettings(device) if options.disable_network: device_settings.ConfigureContentSettings( device, device_settings.NETWORK_DISABLED_SETTINGS) if options.min_battery_level is not None: try: battery = battery_utils.BatteryUtils(device) battery.ChargeDeviceToLevel(options.min_battery_level) except device_errors.CommandFailedError as e: logging.exception( 'Unable to charge device to specified level.') if not options.skip_wipe: device.Reboot(True, timeout=reboot_timeout, retries=0) device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', time.gmtime()), as_root=True) props = device.RunShellCommand('getprop') for prop in props: logging.info(' %s' % prop) if options.auto_reconnect: PushAndLaunchAdbReboot(device, options.target) except (errors.WaitForResponseTimedOutError, device_errors.CommandTimeoutError): logging.info('Timed out waiting for device %s. Adding to blacklist.', str(device)) # Device black list is reset by bb_device_status_check.py per build. device_blacklist.ExtendBlacklist([str(device)]) except device_errors.CommandFailedError: logging.exception( 'Failed to provision device %s. Adding to blacklist.', str(device)) device_blacklist.ExtendBlacklist([str(device)])
def SetProperties(device, options): try: device.EnableRoot() except device_errors.CommandFailedError as e: logging.warning(str(e)) if not device.IsUserBuild(): _ConfigureLocalProperties(device, options.enable_java_debug) else: logging.warning('Cannot configure properties in user builds.') device_settings.ConfigureContentSettings( device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) if options.disable_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_LOCATION_SETTINGS) if options.disable_mock_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_MOCK_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_MOCK_LOCATION_SETTINGS) device_settings.SetLockScreenSettings(device) if options.disable_network: device_settings.ConfigureContentSettings( device, device_settings.NETWORK_DISABLED_SETTINGS) if options.disable_system_chrome: # The system chrome version on the device interferes with some tests. device.RunShellCommand(['pm', 'disable', 'com.android.chrome'], check_return=True) if options.remove_system_webview: if device.HasRoot(): # This is required, e.g., to replace the system webview on a device. device.adb.Remount() device.RunShellCommand(['stop'], check_return=True) device.RunShellCommand(['rm', '-rf'] + _SYSTEM_WEBVIEW_PATHS, check_return=True) device.RunShellCommand(['start'], check_return=True) else: logging.warning( 'Cannot remove system webview from a non-rooted device') # Some device types can momentarily disappear after setting properties. device.adb.WaitForDevice()
def SetProperties(device, options): try: device.EnableRoot() except device_errors.CommandFailedError as e: logging.warning(str(e)) _ConfigureLocalProperties(device, options.enable_java_debug) device_settings.ConfigureContentSettings( device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) if options.disable_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_LOCATION_SETTINGS) if options.disable_mock_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_MOCK_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_MOCK_LOCATION_SETTINGS) device_settings.SetLockScreenSettings(device) if options.disable_network: device_settings.ConfigureContentSettings( device, device_settings.NETWORK_DISABLED_SETTINGS) if options.remove_system_webview: if device.HasRoot(): # This is required, e.g., to replace the system webview on a device. device.adb.Remount() device.RunShellCommand(['stop'], check_return=True) device.RunShellCommand(['rm', '-rf'] + _SYSTEM_WEBVIEW_PATHS, check_return=True) device.RunShellCommand(['start'], check_return=True) else: logging.warning( 'Cannot remove system webview from a non-rooted device')
def ProvisionDevice(device_serial, is_perf, disable_location): device = device_utils.DeviceUtils(device_serial) device.old_interface.EnableAdbRoot() _ConfigureLocalProperties(device, is_perf) device_settings_map = device_settings.DETERMINISTIC_DEVICE_SETTINGS if disable_location: device_settings_map.update(device_settings.DISABLE_LOCATION_SETTING) else: device_settings_map.update(device_settings.ENABLE_LOCATION_SETTING) device_settings.ConfigureContentSettingsDict(device, device_settings_map) device_settings.SetLockScreenSettings(device) if is_perf: # TODO(tonyg): We eventually want network on. However, currently radios # can cause perfbots to drain faster than they charge. device_settings.ConfigureContentSettingsDict( device, device_settings.NETWORK_DISABLED_SETTINGS) # Some perf bots run benchmarks with USB charging disabled which leads # to gradual draining of the battery. We must wait for a full charge # before starting a run in order to keep the devices online. try: battery_info = device.old_interface.GetBatteryInfo() except Exception as e: battery_info = {} logging.error('Unable to obtain battery info for %s, %s', device_serial, e) while int(battery_info.get('level', 100)) < 95: if not device.old_interface.IsDeviceCharging(): if device.old_interface.CanControlUsbCharging(): device.old_interface.EnableUsbCharging() else: logging.error('Device is not charging') break logging.info('Waiting for device to charge. Current level=%s', battery_info.get('level', 0)) time.sleep(60) battery_info = device.old_interface.GetBatteryInfo() device.RunShellCommand('date -u %f' % time.time(), as_root=True)
def SetProperties(device, options): try: device.EnableRoot() except device_errors.CommandFailedError as e: logging.warning(str(e)) if not device.IsUserBuild(): _ConfigureLocalProperties(device, options.enable_java_debug) else: logging.warning('Cannot configure properties in user builds.') device_settings.ConfigureContentSettings( device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) if options.disable_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_LOCATION_SETTINGS) if options.disable_mock_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_MOCK_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_MOCK_LOCATION_SETTINGS) device_settings.SetLockScreenSettings(device) if options.disable_network: device_settings.ConfigureContentSettings( device, device_settings.NETWORK_DISABLED_SETTINGS) if options.disable_system_chrome: # The system chrome version on the device interferes with some tests. device.RunShellCommand(['pm', 'disable', 'com.android.chrome'], check_return=True) if options.remove_system_webview: if any(device.PathExists(p) for p in _SYSTEM_WEBVIEW_PATHS): logging.info('System WebView exists and needs to be removed') if device.HasRoot(): # Disabled Marshmallow's Verity security feature if device.build_version_sdk >= version_codes.MARSHMALLOW: device.adb.DisableVerity() device.Reboot() device.WaitUntilFullyBooted() device.EnableRoot() # This is required, e.g., to replace the system webview on a device. device.adb.Remount() device.RunShellCommand(['stop'], check_return=True) device.RunShellCommand(['rm', '-rf'] + _SYSTEM_WEBVIEW_PATHS, check_return=True) device.RunShellCommand(['start'], check_return=True) else: logging.warning( 'Cannot remove system webview from a non-rooted device') else: logging.info('System WebView already removed') # Some device types can momentarily disappear after setting properties. device.adb.WaitForDevice()
def ProvisionDevice(device, options, is_perf): try: if not options.skip_wipe: WipeDeviceIfPossible(device) try: device.EnableRoot() except device_errors.CommandFailedError as e: logging.warning(str(e)) _ConfigureLocalProperties(device, is_perf) device_settings.ConfigureContentSettings( device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) if options.disable_location: device_settings.ConfigureContentSettings( device, device_settings.DISABLE_LOCATION_SETTINGS) else: device_settings.ConfigureContentSettings( device, device_settings.ENABLE_LOCATION_SETTINGS) device_settings.SetLockScreenSettings(device) if is_perf: # TODO(tonyg): We eventually want network on. However, currently radios # can cause perfbots to drain faster than they charge. device_settings.ConfigureContentSettings( device, device_settings.NETWORK_DISABLED_SETTINGS) # Some perf bots run benchmarks with USB charging disabled which leads # to gradual draining of the battery. We must wait for a full charge # before starting a run in order to keep the devices online. try: battery_info = device.old_interface.GetBatteryInfo() except Exception as e: battery_info = {} logging.error('Unable to obtain battery info for %s, %s', str(device), e) while int(battery_info.get('level', 100)) < options.min_battery_level: if not device.old_interface.IsDeviceCharging(): if device.old_interface.CanControlUsbCharging(): device.old_interface.EnableUsbCharging() else: logging.error('Device is not charging') break logging.info('Waiting for device to charge. Current level=%s', battery_info.get('level', 0)) time.sleep(60) battery_info = device.old_interface.GetBatteryInfo() if not options.skip_wipe: # TODO(jbudorick): Tune the timeout per OS version. device.Reboot(True, timeout=600, retries=0) device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', time.gmtime()), as_root=True) props = device.RunShellCommand('getprop') for prop in props: logging.info(' %s' % prop) if options.auto_reconnect: PushAndLaunchAdbReboot(device, options.target) except (errors.WaitForResponseTimedOutError, device_errors.CommandTimeoutError): logging.info('Timed out waiting for device %s. Adding to blacklist.', str(device)) # Device black list is reset by bb_device_status_check.py per build. device_blacklist.ExtendBlacklist([str(device)]) except device_errors.CommandFailedError: logging.exception( 'Failed to provision device %s. Adding to blacklist.', str(device)) device_blacklist.ExtendBlacklist([str(device)])
def ProvisionDevices(options): is_perf = 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower() # TODO(jbudorick): Parallelize provisioning of all attached devices after # switching from AndroidCommands. if options.device is not None: devices = [options.device] else: devices = android_commands.GetAttachedDevices() # Wipe devices (unless --skip-wipe was specified) if not options.skip_wipe: for device_serial in devices: device = device_utils.DeviceUtils(device_serial) device.old_interface.EnableAdbRoot() WipeDeviceData(device) try: device_utils.DeviceUtils.parallel(devices).Reboot(True) except errors.DeviceUnresponsiveError: pass for device_serial in devices: device.WaitUntilFullyBooted(timeout=90) # Provision devices for device_serial in devices: device = device_utils.DeviceUtils(device_serial) device.old_interface.EnableAdbRoot() _ConfigureLocalProperties(device, is_perf) device_settings_map = device_settings.DETERMINISTIC_DEVICE_SETTINGS if options.disable_location: device_settings_map.update( device_settings.DISABLE_LOCATION_SETTING) else: device_settings_map.update(device_settings.ENABLE_LOCATION_SETTING) device_settings.ConfigureContentSettingsDict(device, device_settings_map) device_settings.SetLockScreenSettings(device) if is_perf: # TODO(tonyg): We eventually want network on. However, currently radios # can cause perfbots to drain faster than they charge. device_settings.ConfigureContentSettingsDict( device, device_settings.NETWORK_DISABLED_SETTINGS) # Some perf bots run benchmarks with USB charging disabled which leads # to gradual draining of the battery. We must wait for a full charge # before starting a run in order to keep the devices online. try: battery_info = device.old_interface.GetBatteryInfo() except Exception as e: battery_info = {} logging.error('Unable to obtain battery info for %s, %s', device_serial, e) while int(battery_info.get('level', 100)) < 95: if not device.old_interface.IsDeviceCharging(): if device.old_interface.CanControlUsbCharging(): device.old_interface.EnableUsbCharging() else: logging.error('Device is not charging') break logging.info('Waiting for device to charge. Current level=%s', battery_info.get('level', 0)) time.sleep(60) battery_info = device.old_interface.GetBatteryInfo() device.RunShellCommand('date -u %f' % time.time(), as_root=True) try: device_utils.DeviceUtils.parallel(devices).Reboot(True) except errors.DeviceUnresponsiveError: pass for device_serial in devices: device = device_utils.DeviceUtils(device_serial) device.WaitUntilFullyBooted(timeout=90) (_, props ) = device.old_interface.GetShellCommandStatusAndOutput('getprop') for prop in props: print prop if options.auto_reconnect: PushAndLaunchAdbReboot(devices, options.target)