UserSwitcher
public
final
class
UserSwitcher
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.device.UserSwitcher |
Helper object used to switch to a user of a given type, and then switch back to
the previous user later.
Note: it's meant to be used just once, typically by ERROR(/com.android.tradefed.targetprep.ISwitchUserTargetPreparer) implementations (which would call
ERROR(switchUser(ITestDevice,UserType)/#switchUser(com.android.tradefed.device.ITestDevice,com.android.tradefed.device.UserInfo.UserType) switchUser(ITestDevice,UserType)) on setUp() and switchBack() on tearDown(). It could be used multiple times, in which case switchBack() would always
switch to the latest ERROR(user switched to/#switchUser(com.android.tradefed.device.ITestDevice,com.android.tradefed.device.UserInfo.UserType) user switched to).
Summary
Public constructors | |
|---|---|
UserSwitcher(ITestDevice device, UserInfo.UserType userType)
Default constructor. |
|
UserSwitcher(ITestDevice device, UserInfo.UserType userType, UserSwitcher.UserTypeMode userTypeMode)
Full constructor. |
|
Public methods | |
|---|---|
boolean
|
switchBack()
Switches back to the current user prior to the |
int
|
switchUser()
Switches to a user of the |
Public constructors
UserSwitcher
public UserSwitcher (ITestDevice device, UserInfo.UserType userType)
Default constructor.
It sets the user-type mode as UserTypeMode.LEGACY.
| Parameters | |
|---|---|
device |
ITestDevice |
userType |
UserInfo.UserType: type of user to switch to |
UserSwitcher
public UserSwitcher (ITestDevice device, UserInfo.UserType userType, UserSwitcher.UserTypeMode userTypeMode)
Full constructor.
| Parameters | |
|---|---|
device |
ITestDevice |
userType |
UserInfo.UserType: type of user to switch to |
userTypeMode |
UserSwitcher.UserTypeMode: defines the preparer's behavior based on some properties of the user type |
Public methods
switchBack
public boolean switchBack ()
Switches back to the current user prior to the ERROR(switchUser(ITestDevice,UserType)/#switchUser(com.android.tradefed.device.ITestDevice,com.android.tradefed.device.UserInfo.UserType) switchUser(ITestDevice,UserType))
call.
| Returns | |
|---|---|
boolean |
whether the switch succeeded |
| Throws | |
|---|---|
IllegalStateException |
if this method is called before ERROR(switchUser(ITestDevice,UserType)/#switchUser(com.android.tradefed.device.ITestDevice,com.android.tradefed.device.UserInfo.UserType) switchUser(ITestDevice,UserType)) |
DeviceNotAvailableException |
|
switchUser
public int switchUser ()
Switches to a user of the type set on constructor, if necessary.
| Returns | |
|---|---|
int |
id of the current user after the switch |
| Throws | |
|---|---|
TargetSetupError |
if it could not find a user of the given type or if the user switch operation failed or if this method was already called. |
DeviceNotAvailableException |
|