TestAppInstallSetup

public class TestAppInstallSetup
extends BaseTargetPreparer implements ITargetCleaner, IAbiReceiver

java.lang.Object
   ↳ com.android.tradefed.targetprep.BaseTargetPreparer
     ↳ com.android.tradefed.targetprep.TestAppInstallSetup


A ITargetPreparer that installs one or more apps from a IDeviceBuildInfo#getTestsDir() folder onto device.

This preparer will look in alternate directories if the tests zip does not exist or does not contain the required apk. The search will go in order from the last alternative dir specified to the first.

Summary

Public constructors

TestAppInstallSetup()

Public methods

void addInstallArg(String arg)

Adds one apk installation arg to be used.

void addSplitApkFileNames(String fileNames)

Adds a set of file names divided by ',' in a string to be installed as split apks

void addTestFileName(String fileName)

Adds a file name to the list of apks to installed

IAbi getAbi()
getTestsFileName()

Returns a copy of the list of specified test apk names.

final boolean isInstantMode()

Returns whether or not instant mode installation has been enabled.

void setAbi(IAbi abi)
void setAltDir(File altDir)

Set an alternate directory.

void setAltDirBehavior(AltDirBehavior altDirBehavior)

Set an alternate directory behaviors.

void setCleanApk(boolean shouldClean)

Sets whether or not the installed apk should be cleaned on tearDown

final void setInstantMode(boolean mode)

Sets whether or not --instant should be used when installing the apk.

void setShouldGrantPermission(boolean shouldGrant)

If a userId is provided, grantPermission can be set for the apk installation.

void setUp(ITestDevice device, IBuildInfo buildInfo)

Perform the target setup for testing.

void setUserId(int userId)

If the apk should be installed for a particular user, sets the id of the user to install for.

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

Perform the target cleanup/teardown after testing.

Protected methods

File getLocalPathForFilename(IBuildInfo buildInfo, String apkFileName, ITestDevice device)

Resolve the actual apk path based on testing artifact information inside build info.

void installer(ITestDevice device, IBuildInfo buildInfo, apkNames)

Attempt to install an package or split package on the device.

String parsePackageName(File testAppFile, DeviceDescriptor deviceDescriptor)

Get the package name from the test app.

void uninstallPackage(ITestDevice device, String packageName)

Attempt to remove the package from the device.

Public constructors

TestAppInstallSetup

public TestAppInstallSetup ()

Public methods

addInstallArg

public void addInstallArg (String arg)

Adds one apk installation arg to be used.

Parameters
arg String

addSplitApkFileNames

public void addSplitApkFileNames (String fileNames)

Adds a set of file names divided by ',' in a string to be installed as split apks

Parameters
fileNames String: a string of file names divided by ','

addTestFileName

public void addTestFileName (String fileName)

Adds a file name to the list of apks to installed

getAbi

public IAbi getAbi ()

Returns
IAbi

getTestsFileName

public  getTestsFileName ()

Returns a copy of the list of specified test apk names.

Returns

isInstantMode

public final boolean isInstantMode ()

Returns whether or not instant mode installation has been enabled.

Returns
boolean

setAbi

public void setAbi (IAbi abi)

Parameters
abi IAbi

setAltDir

public void setAltDir (File altDir)

Set an alternate directory.

Parameters
altDir File

setAltDirBehavior

public void setAltDirBehavior (AltDirBehavior altDirBehavior)

Set an alternate directory behaviors.

Parameters
altDirBehavior AltDirBehavior

setCleanApk

public void setCleanApk (boolean shouldClean)

Sets whether or not the installed apk should be cleaned on tearDown

Parameters
shouldClean boolean

setInstantMode

public final void setInstantMode (boolean mode)

Sets whether or not --instant should be used when installing the apk. Will have no effect if force-install-mode is set.

Parameters
mode boolean

setShouldGrantPermission

public void setShouldGrantPermission (boolean shouldGrant)

If a userId is provided, grantPermission can be set for the apk installation.

Parameters
shouldGrant boolean

setUp

public void setUp (ITestDevice device, 
                IBuildInfo buildInfo)

Perform the target setup for testing.

Parameters
device ITestDevice: the ITestDevice to prepare.

buildInfo IBuildInfo: data about the build under test.

Throws
DeviceNotAvailableException
TargetSetupError

setUserId

public void setUserId (int userId)

If the apk should be installed for a particular user, sets the id of the user to install for.

Parameters
userId int

tearDown

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

Perform the target cleanup/teardown after testing.

Parameters
device ITestDevice: the ITestDevice to prepare.

buildInfo IBuildInfo: data about the build under test.

e Throwable: if the invocation ended with an exception, this will be the exception that was caught at the Invocation level. Otherwise, will be null.

Throws
DeviceNotAvailableException

Protected methods

getLocalPathForFilename

protected File getLocalPathForFilename (IBuildInfo buildInfo, 
                String apkFileName, 
                ITestDevice device)

Resolve the actual apk path based on testing artifact information inside build info.

Parameters
buildInfo IBuildInfo: build artifact information

apkFileName String: filename of the apk to install

device ITestDevice: the ITestDevice being prepared

Returns
File a ERROR(/File) representing the physical apk file on host or null if the file does not exist.

Throws
TargetSetupError

installer

protected void installer (ITestDevice device, 
                IBuildInfo buildInfo, 
                 apkNames)

Attempt to install an package or split package on the device.

Parameters
device ITestDevice: the ITestDevice to install package

buildInfo IBuildInfo: build artifact information

apkNames : List of String. The application file base names to be installed. If apkNames contains only one apk name, the apk will be installed as single package. If apkNames contains more than one name, the apks will be installed as split apks.

Throws
DeviceNotAvailableException
TargetSetupError

parsePackageName

protected String parsePackageName (File testAppFile, 
                DeviceDescriptor deviceDescriptor)

Get the package name from the test app.

Parameters
testAppFile File

deviceDescriptor DeviceDescriptor

Returns
String

Throws
TargetSetupError

uninstallPackage

protected void uninstallPackage (ITestDevice device, 
                String packageName)

Attempt to remove the package from the device.

Parameters
device ITestDevice

packageName String

Throws
DeviceNotAvailableException