to top
public class

DeviceSetup

extends Object
implements ITargetPreparer ITargetCleaner @OptionClass(alias = "device-setup")
java.lang.Object
   ↳ com.android.tradefed.targetprep.DeviceSetup

Class Overview

A ITargetPreparer that configures a device for testing based on provided Options.

Requires a device where 'adb root' is possible, typically a userdebug build type.

Should be performed after a new build is flashed.

Summary

Nested Classes
enum DeviceSetup.BinaryState Enum used to record ON/OFF state with a IGNORE no-op state. 
Fields
protected DeviceSetup.BinaryState mAirplaneMode @Option(name = "airplane-mode", description = "Turn airplane mode on or off")
protected DeviceSetup.BinaryState mAutoRotate @Option(name = "auto-rotate", description = "Turn auto rotate on or off")
protected DeviceSetup.BinaryState mAutoUpdateTime @Option(name = "auto-update-time", description = "Turn auto update time on or off")
protected DeviceSetup.BinaryState mAutoUpdateTimezone @Option(name = "auto-update-timezone", description = "Turn auto update timezone on or off")
protected DeviceSetup.BinaryState mBatterySaver @Option(name = "battery-saver-mode", description = "Turn battery saver mode manually on or off. If OFF but battery is less battery-saver-trigger, the device will still go into battery saver mode")
protected Integer mBatterySaverTrigger @Option(name = "battery-saver-trigger", description = "Set the battery saver trigger level. Should be [1-99] to enable, or 0 to disable automatic battery saver mode")
protected DeviceSetup.BinaryState mBluetooth @Option(name = "bluetooth", description = "Turn bluetooth on or off")
protected Integer mDefaultSimData @Option(name = "default-sim-data", description = "Set the default sim card slot for data. Leave unset for single SIM devices")
protected Integer mDefaultSimSms @Option(name = "default-sim-sms", description = "Set the default sim card slot for SMS. Leave unset for single SIM devices")
protected Integer mDefaultSimVoice @Option(name = "default-sim-voice", description = "Set the default sim card slot for voice calls. Leave unset for single SIM devices")
private long mDeprecatedMinExternalStoreSpace @Option(name = "min-external-store-space", description = "deprecated, use option min-external-storage-kb. The minimum amount of free space in KB that must be present on device\'s external storage.")
private boolean mDeprecatedSetAudioSilent @Option(name = "audio-silent", description = "deprecated, use option disable-audio. set ro.audio.silent on boot.")
private Collection<String> mDeprecatedSetProps @Option(name = "setprop", description = "deprecated, use option set-property. set the specified property on boot. Format: --setprop key=value. May be repeated.")
protected boolean mDisable @Option(name = "disable", description = "Disable the device setup")
protected boolean mDisableAudio @Option(name = "disable-audio", description = "Disable the audio")
protected boolean mDisableDalvikVerifier @Option(name = "disable-dalvik-verifier", description = "Disable the dalvik verifier on device. Allows package-private framework tests to run.")
protected boolean mDisableDialing @Option(name = "disable-dialing", description = "Disable dialing")
protected boolean mDisableDoze @Option(name = "disable-doze", description = "Disable device from going into doze mode. This option is only applicable for M+")
private boolean mDisconnectWifiAfterTest @Option(name = "disconnect-wifi-after-test", description = "Disconnect from wifi network after test completes.")
protected DeviceSetup.BinaryState mEthernet @Option(name = "ethernet", description = "Turn ethernet on or off")
protected boolean mForceSkipRunCommands @Option(name = "force-skip-run-commands", description = "Force setup to not run any additional commands. All other commands will be ignored.")
protected boolean mForceSkipSettings @Option(name = "force-skip-settings", description = "Force setup to not modify any device settings. All other setting options will be ignored.")
protected boolean mForceSkipSystemProps @Option(name = "force-skip-system-props", description = "Force setup to not modify any device system properties. All other system property options will be ignored")
protected MultiMap<String, String> mGlobalSettings @Option(name = "set-global-setting", description = "Change a global setting. Option may be repeated and all key/value pairs will be set in order.")
protected File mLocalDataFile @Option(name = "local-data-path", description = "Optional local file path of test data to sync to device\'s external storage. Use --remote-data-path to set remote location.")
protected DeviceSetup.BinaryState mLocationGps @Option(name = "location-gps", description = "Turn the GPS location on or off")
protected DeviceSetup.BinaryState mLocationNetwork @Option(name = "location-network", description = "Turn the network location on or off")
protected long mMinExternalStorageKb @Option(name = "min-external-storage-kb", description = "The minimum amount of free space in KB that must be present on device\'s external storage.")
protected DeviceSetup.BinaryState mNotificationLed @Option(name = "notification-led", description = "Turn the notification led on or off")
protected String mRemoteDataPath @Option(name = "remote-data-path", description = "Optional file path on device\'s external storage to sync test data. Must be used with --local-data-path.")
protected List<String> mRunCommandAfterSettings @Option(name = "run-command", description = "Run an adb shell command. Option may be repeated")
protected List<String> mRunCommandBeforeSettings
protected DeviceSetup.BinaryState mScreenAdaptiveBrightness @Option(name = "screen-adaptive-brightness", description = "Turn screen adaptive brightness on or off")
protected DeviceSetup.BinaryState mScreenAlwaysOn @Option(name = "screen-always-on", description = "Turn \'screen always on\' on or off. If ON, then screen-timeout-secs must be unset. Will only work when the device is plugged in")
protected DeviceSetup.BinaryState mScreenAmbientMode @Option(name = "screen-ambient-mode", description = "Turn screen ambient mode on or off")
protected Integer mScreenBrightness @Option(name = "screen-brightness", description = "Set the screen brightness. This is uncalibrated from product to product")
protected DeviceSetup.BinaryState mScreenSaver @Option(name = "screen-saver", description = "Turn screen saver on or off")
protected Long mScreenTimeoutSecs @Option(name = "screen-timeout-secs", description = "Set the screen timeout in seconds. If set, then screen-always-on must be OFF or DEFAULT")
protected MultiMap<String, String> mSecureSettings @Option(name = "set-secure-setting", description = "Change a secure setting. Option may be repeated and all key/value pairs will be set in order.")
protected Map<String, String> mSetProps @Option(name = "set-property", description = "Set the specified property on boot. Option may be repeated but only the last value for a given key will be set.")
protected boolean mSetTestHarness @Option(name = "set-test-harness", description = "Set the read-only test harness flag on boot")
protected MultiMap<String, String> mSystemSettings @Option(name = "set-system-setting", description = "Change a system (non-secure) setting. Option may be repeated and all key/value pairs will be set in order.")
protected boolean mTriggerMediaMounted @Option(name = "trigger-media-mounted", description = "Trigger a MEDIA_MOUNTED broadcast")
protected DeviceSetup.BinaryState mWakeGesture @Option(name = "wake-gesture", description = "Turn wake gesture on or off")
protected DeviceSetup.BinaryState mWifi @Option(name = "wifi", description = "Turn wifi on or off")
protected String mWifiPsk @Option(name = "wifi-psk", description = "The passphrase used to connect to a secured network")
protected DeviceSetup.BinaryState mWifiScanAlwaysEnabled @Option(name = "wifi-scan-always-enabled", description = "Turn wifi scan always enabled on or off")
protected String mWifiSsid @Option(name = "wifi-network", description = "The SSID of the network to connect to. Will only attempt to connect to a network if set")
protected DeviceSetup.BinaryState mWifiWatchdog @Option(name = "wifi-watchdog", description = "Turn wifi watchdog on or off")
Public Constructors
DeviceSetup()
Public Methods
void changeSettings(ITestDevice device)
Change the settings on the device.
void processDeprecatedOptions()
Processes the deprecated options converting them into the currently used options.
void processOptions(ITestDevice device)
Process all the Options and turn them into system props, settings, or run commands.
static void setCommandForBinaryState(DeviceSetup.BinaryState state, List<String> commands, String onCommand, String offCommand)
Helper method to add an ON/OFF run command to be executed on the device.
static void setSettingForBinaryState(DeviceSetup.BinaryState state, MultiMap<String, String> settingsMap, String setting, String onValue, String offValue)
Helper method to add an ON/OFF setting to a setting map.
void setUp(ITestDevice device, IBuildInfo buildInfo)
Perform the target setup for testing.
void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
Perform the target cleanup/teardown after testing.
Protected Methods
void setAirplaneMode(DeviceSetup.BinaryState airplaneMode)
Exposed for unit testing
void setAutoRotate(DeviceSetup.BinaryState autoRotate)
Exposed for unit testing
void setAutoUpdateTime(DeviceSetup.BinaryState autoUpdateTime)
Exposed for unit testing
void setAutoUpdateTimezone(DeviceSetup.BinaryState autoUpdateTimezone)
Exposed for unit testing
void setBatterySaver(DeviceSetup.BinaryState batterySaver)
Exposed for unit testing
void setBatterySaverTrigger(Integer batterySaverTrigger)
Exposed for unit testing
void setBluetooth(DeviceSetup.BinaryState bluetooth)
Exposed for unit testing
void setDefaultSimData(Integer defaultSimData)
Exposed for unit testing
void setDefaultSimSms(Integer defaultSimSms)
Exposed for unit testing
void setDefaultSimVoice(Integer defaultSimVoice)
Exposed for unit testing
void setDeprecatedAudioSilent(boolean silent)
Exposed for unit testing
void setDeprecatedMinExternalStoreSpace(long storeSpace)
Exposed for unit testing
void setDeprecatedSetProp(String prop)
Exposed for unit testing
void setDisableAudio(boolean disable)
Exposed for unit testing
void setDisableDalvikVerifier(boolean disableDalvikVerifier)
Exposed for unit testing
void setDisableDialing(boolean disableDialing)
Exposed for unit testing
void setDisableDoze(boolean disableDoze)
Exposed for unit testing
void setEthernet(DeviceSetup.BinaryState ethernet)
Exposed for unit testing
void setLocalDataPath(File path)
Exposed for unit testing
void setLocationGps(DeviceSetup.BinaryState locationGps)
Exposed for unit testing
void setLocationNetwork(DeviceSetup.BinaryState locationNetwork)
Exposed for unit testing
void setMinExternalStorageKb(long storageKb)
Exposed for unit testing
void setNotificationLed(DeviceSetup.BinaryState notificationLed)
Exposed for unit testing
void setProperty(String key, String value)
Exposed for unit testing
void setScreenAdaptiveBrightness(DeviceSetup.BinaryState screenAdaptiveBrightness)
Exposed for unit testing
void setScreenAlwaysOn(DeviceSetup.BinaryState screenAlwaysOn)
Exposed for unit testing
void setScreenAmbientMode(DeviceSetup.BinaryState screenAmbientMode)
Exposed for unit testing
void setScreenBrightness(Integer screenBrightness)
Exposed for unit testing
void setScreenSaver(DeviceSetup.BinaryState screenSaver)
Exposed for unit testing
void setScreenTimeoutSecs(Long screenTimeoutSecs)
Exposed for unit testing
void setTestHarness(boolean setTestHarness)
Exposed for unit testing
void setTriggerMediaMounted(boolean triggerMediaMounted)
Exposed for unit testing
void setWakeGesture(DeviceSetup.BinaryState wakeGesture)
Exposed for unit testing
void setWifi(DeviceSetup.BinaryState wifi)
Exposed for unit testing
void setWifiNetwork(String wifiNetwork)
Exposed for unit testing
void setWifiScanAlwaysEnabled(DeviceSetup.BinaryState wifiScanAlwaysEnabled)
Exposed for unit testing
void setWifiWatchdog(DeviceSetup.BinaryState wifiWatchdog)
Exposed for unit testing
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.android.tradefed.targetprep.ITargetPreparer
From interface com.android.tradefed.targetprep.ITargetCleaner

Fields

protected DeviceSetup.BinaryState mAirplaneMode

protected DeviceSetup.BinaryState mAutoRotate

protected DeviceSetup.BinaryState mAutoUpdateTime

protected DeviceSetup.BinaryState mAutoUpdateTimezone

protected DeviceSetup.BinaryState mBatterySaver

protected Integer mBatterySaverTrigger

protected DeviceSetup.BinaryState mBluetooth

protected Integer mDefaultSimData

protected Integer mDefaultSimSms

protected Integer mDefaultSimVoice

private long mDeprecatedMinExternalStoreSpace

private boolean mDeprecatedSetAudioSilent

private Collection<String> mDeprecatedSetProps

protected boolean mDisable

protected boolean mDisableAudio

protected boolean mDisableDalvikVerifier

protected boolean mDisableDialing

protected boolean mDisableDoze

private boolean mDisconnectWifiAfterTest

protected DeviceSetup.BinaryState mEthernet

protected boolean mForceSkipRunCommands

protected boolean mForceSkipSettings

protected boolean mForceSkipSystemProps

protected MultiMap<String, String> mGlobalSettings

protected File mLocalDataFile

protected DeviceSetup.BinaryState mLocationGps

protected DeviceSetup.BinaryState mLocationNetwork

protected long mMinExternalStorageKb

protected DeviceSetup.BinaryState mNotificationLed

protected String mRemoteDataPath

protected List<String> mRunCommandAfterSettings

protected List<String> mRunCommandBeforeSettings

protected DeviceSetup.BinaryState mScreenAdaptiveBrightness

protected DeviceSetup.BinaryState mScreenAlwaysOn

protected DeviceSetup.BinaryState mScreenAmbientMode

protected Integer mScreenBrightness

protected DeviceSetup.BinaryState mScreenSaver

protected Long mScreenTimeoutSecs

protected MultiMap<String, String> mSecureSettings

protected Map<String, String> mSetProps

protected boolean mSetTestHarness

protected MultiMap<String, String> mSystemSettings

protected boolean mTriggerMediaMounted

protected DeviceSetup.BinaryState mWakeGesture

protected DeviceSetup.BinaryState mWifi

protected String mWifiPsk

protected DeviceSetup.BinaryState mWifiScanAlwaysEnabled

protected String mWifiSsid

protected DeviceSetup.BinaryState mWifiWatchdog

Public Constructors

public DeviceSetup ()

Public Methods

public void changeSettings (ITestDevice device)

Change the settings on the device.

Exposed so children classes may override.

Parameters
device The ITestDevice
Throws
DeviceNotAvailableException if the device is not available
TargetSetupError if there was a failure setting the settings

public void processDeprecatedOptions ()

Processes the deprecated options converting them into the currently used options.

This method should be run before any other processing methods. Will throw a TargetSetupError if the deprecated option overrides a specified non-deprecated option.

Throws
TargetSetupError if there is a conflict

public void processOptions (ITestDevice device)

Process all the Options and turn them into system props, settings, or run commands. Does not run any commands on the device at this time.

Exposed so that children classes may override this.

Parameters
device The ITestDevice
Throws
DeviceNotAvailableException if the device is not available
TargetSetupError if the Options conflict

public static void setCommandForBinaryState (DeviceSetup.BinaryState state, List<String> commands, String onCommand, String offCommand)

Helper method to add an ON/OFF run command to be executed on the device.

Parameters
state The DeviceSetup.BinaryState
commands The list of commands to add the on or off command to.
onCommand The command to run if ON. Ignored if the command is null
offCommand The command to run if OFF. Ignored if the command is null

public static void setSettingForBinaryState (DeviceSetup.BinaryState state, MultiMap<String, String> settingsMap, String setting, String onValue, String offValue)

Helper method to add an ON/OFF setting to a setting map.

Parameters
state The DeviceSetup.BinaryState
settingsMap The MultiMap used to store the settings.
setting The setting key
onValue The value if ON
offValue The value if OFF

public void setUp (ITestDevice device, IBuildInfo buildInfo)

Perform the target setup for testing.

Parameters
device the ITestDevice to prepare.
buildInfo data about the build under test.

public void tearDown (ITestDevice device, IBuildInfo buildInfo, Throwable e)

Perform the target cleanup/teardown after testing.

Parameters
device the ITestDevice to prepare.
buildInfo data about the build under test.
e if the invocation ended with an exception, this will be the exception that was caught at the Invocation level. Otherwise, will be null.

Protected Methods

protected void setAirplaneMode (DeviceSetup.BinaryState airplaneMode)

Exposed for unit testing

protected void setAutoRotate (DeviceSetup.BinaryState autoRotate)

Exposed for unit testing

protected void setAutoUpdateTime (DeviceSetup.BinaryState autoUpdateTime)

Exposed for unit testing

protected void setAutoUpdateTimezone (DeviceSetup.BinaryState autoUpdateTimezone)

Exposed for unit testing

protected void setBatterySaver (DeviceSetup.BinaryState batterySaver)

Exposed for unit testing

protected void setBatterySaverTrigger (Integer batterySaverTrigger)

Exposed for unit testing

protected void setBluetooth (DeviceSetup.BinaryState bluetooth)

Exposed for unit testing

protected void setDefaultSimData (Integer defaultSimData)

Exposed for unit testing

protected void setDefaultSimSms (Integer defaultSimSms)

Exposed for unit testing

protected void setDefaultSimVoice (Integer defaultSimVoice)

Exposed for unit testing

protected void setDeprecatedAudioSilent (boolean silent)

Exposed for unit testing

protected void setDeprecatedMinExternalStoreSpace (long storeSpace)

Exposed for unit testing

protected void setDeprecatedSetProp (String prop)

Exposed for unit testing

protected void setDisableAudio (boolean disable)

Exposed for unit testing

protected void setDisableDalvikVerifier (boolean disableDalvikVerifier)

Exposed for unit testing

protected void setDisableDialing (boolean disableDialing)

Exposed for unit testing

protected void setDisableDoze (boolean disableDoze)

Exposed for unit testing

protected void setEthernet (DeviceSetup.BinaryState ethernet)

Exposed for unit testing

protected void setLocalDataPath (File path)

Exposed for unit testing

protected void setLocationGps (DeviceSetup.BinaryState locationGps)

Exposed for unit testing

protected void setLocationNetwork (DeviceSetup.BinaryState locationNetwork)

Exposed for unit testing

protected void setMinExternalStorageKb (long storageKb)

Exposed for unit testing

protected void setNotificationLed (DeviceSetup.BinaryState notificationLed)

Exposed for unit testing

protected void setProperty (String key, String value)

Exposed for unit testing

protected void setScreenAdaptiveBrightness (DeviceSetup.BinaryState screenAdaptiveBrightness)

Exposed for unit testing

protected void setScreenAlwaysOn (DeviceSetup.BinaryState screenAlwaysOn)

Exposed for unit testing

protected void setScreenAmbientMode (DeviceSetup.BinaryState screenAmbientMode)

Exposed for unit testing

protected void setScreenBrightness (Integer screenBrightness)

Exposed for unit testing

protected void setScreenSaver (DeviceSetup.BinaryState screenSaver)

Exposed for unit testing

protected void setScreenTimeoutSecs (Long screenTimeoutSecs)

Exposed for unit testing

protected void setTestHarness (boolean setTestHarness)

Exposed for unit testing

protected void setTriggerMediaMounted (boolean triggerMediaMounted)

Exposed for unit testing

protected void setWakeGesture (DeviceSetup.BinaryState wakeGesture)

Exposed for unit testing

protected void setWifi (DeviceSetup.BinaryState wifi)

Exposed for unit testing

protected void setWifiNetwork (String wifiNetwork)

Exposed for unit testing

protected void setWifiScanAlwaysEnabled (DeviceSetup.BinaryState wifiScanAlwaysEnabled)

Exposed for unit testing

protected void setWifiWatchdog (DeviceSetup.BinaryState wifiWatchdog)

Exposed for unit testing