GoogleAccountUtil

public class GoogleAccountUtil
extends Object

java.lang.Object
   ↳ com.google.android.tradefed.util.GoogleAccountUtil


A Utility that supports configuring google accounts on a device

Summary

Constants

String ACCOUNT_PKG_NAME

String UTIL_APK_NAME

Fields

public static final String CHECK_INSTRUMENTATION_CMD

Public constructors

GoogleAccountUtil()

Public methods

static boolean addAccountAttempt(ITestDevice device, int userId, String accountName, String password, boolean sync, boolean waitForCheckin)

Attempt to configures device under test with given Google account.

static boolean hasAccount(ITestDevice device, int userId)

Check if there is an account on the device.

static boolean installUtil(ITestDevice device)
static boolean installUtil(ITestDevice device, File altApk)

Install the account utility apk contained in jar if necessary

static boolean isAccountUtilInstalled(ITestDevice device)

Check if the account utility is currently installed

static boolean removeAccountAttempt(ITestDevice device, int userId, String accountName)

Remove the single account specified

static boolean removeAllAccountAttempt(ITestDevice device, int userId)

Remove all accounts of the device

static boolean syncAndOff(ITestDevice device, int userId, String accountName, long syncThenOff)

Turns off syncing with the given Google account.

static boolean syncOn(ITestDevice device, int userId, String accountName)

Turns on syncing with the given Google account.

static boolean uninstallUtil(ITestDevice device)

Uninstall the account utility apk contained in jar

static boolean waitForAccountSync(ITestDevice device, int userId, long interval, long timeout, boolean forceSync)

Wait for the device to finish syncing.

Constants

ACCOUNT_PKG_NAME

public static final String ACCOUNT_PKG_NAME

Constant Value: "com.google.android.tradefed.account"

UTIL_APK_NAME

public static final String UTIL_APK_NAME

Constant Value: "GoogleAccountUtil"

Fields

CHECK_INSTRUMENTATION_CMD

public static final String CHECK_INSTRUMENTATION_CMD

Public constructors

GoogleAccountUtil

public GoogleAccountUtil ()

Public methods

addAccountAttempt

public static boolean addAccountAttempt (ITestDevice device, 
                int userId, 
                String accountName, 
                String password, 
                boolean sync, 
                boolean waitForCheckin)

Attempt to configures device under test with given Google account.

Account must already exist on server.

Exposed for unit testing.

Parameters
device ITestDevice: the ITestDevice

userId int: the ID of user to which the account will be added

accountName String: full name of Google account to add

password String: password of account

sync boolean: true if automatic sync should be enabled for this account

waitForCheckin boolean: true to wait for checkin after adding account

Returns
boolean true if account was created successfully, false otherwise

Throws
DeviceNotAvailableException

hasAccount

public static boolean hasAccount (ITestDevice device, 
                int userId)

Check if there is an account on the device.

Parameters
device ITestDevice: the ITestDevice checked for an account

userId int: the user ID id to check

Returns
boolean

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

installUtil

public static boolean installUtil (ITestDevice device)

Parameters
device ITestDevice

Returns
boolean

Throws
DeviceNotAvailableException

installUtil

public static boolean installUtil (ITestDevice device, 
                File altApk)

Install the account utility apk contained in jar if necessary

Parameters
device ITestDevice: on which to install the utility.

altApk File

Returns
boolean

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

isAccountUtilInstalled

public static boolean isAccountUtilInstalled (ITestDevice device)

Check if the account utility is currently installed

Parameters
device ITestDevice: on which to check if the account utility is installed

Returns
boolean

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

removeAccountAttempt

public static boolean removeAccountAttempt (ITestDevice device, 
                int userId, 
                String accountName)

Remove the single account specified

Parameters
accountName String

Returns
boolean true if removal is a success, false otherwise.

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

removeAllAccountAttempt

public static boolean removeAllAccountAttempt (ITestDevice device, 
                int userId)

Remove all accounts of the device

Returns
boolean true if removal is a success, false otherwise.

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

syncAndOff

public static boolean syncAndOff (ITestDevice device, 
                int userId, 
                String accountName, 
                long syncThenOff)

Turns off syncing with the given Google account. Assume syncing is On.

Parameters
device ITestDevice: the ITestDevice

userId int: the ID of the user to run this operation on

accountName String: full name of Google account to turn sync off

syncThenOff long: seconds to allow sync to run before turning it off

Returns
boolean true if the sync was turned off successfully

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

syncOn

public static boolean syncOn (ITestDevice device, 
                int userId, 
                String accountName)

Turns on syncing with the given Google account. Assume syncing is false;

Parameters
device ITestDevice: the ITestDevice

userId int: the ID of the user to run this operation on

accountName String: full name of Google account to turn sync on

Returns
boolean true if the sync was turned off successfully

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

uninstallUtil

public static boolean uninstallUtil (ITestDevice device)

Uninstall the account utility apk contained in jar

Parameters
device ITestDevice: to uninstall the account utility from.

Returns
boolean

Throws
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

waitForAccountSync

public static boolean waitForAccountSync (ITestDevice device, 
                int userId, 
                long interval, 
                long timeout, 
                boolean forceSync)

Wait for the device to finish syncing.

Parameters
device ITestDevice

userId int

interval long

timeout long

forceSync boolean

Returns
boolean

Throws
DeviceNotAvailableException