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 addTestFileName(String fileName)

Adds a file to the list of apks to install

IAbi getAbi()
List<String> getTestsFileName()

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

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

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.

String parsePackageName(File testAppFile, DeviceDescriptor deviceDescriptor)

Get the package name from the test app.

Public constructors

TestAppInstallSetup

public TestAppInstallSetup ()

Public methods

addInstallArg

public void addInstallArg (String arg)

Adds one apk installation arg to be used.

Parameters
arg String

addTestFileName

public void addTestFileName (String fileName)

Adds a file to the list of apks to install

getAbi

public IAbi getAbi ()

Returns
IAbi

getTestsFileName

public List<String> getTestsFileName ()

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

Returns
List<String>

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

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
TargetSetupError
DeviceNotAvailableException

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 File representing the physical apk file on host or null if the file does not exist.

Throws
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