TestAppInstallSetup

public class TestAppInstallSetup
extends BaseTargetPreparer implements IAbiReceiver, IDiscoverDependencies

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

Fields

protected IncrementalInstallSession incrementalInstallSession

protected double mBlockFilterPercentage

protected int mIncrementalInstallTimeout

protected boolean mIncrementalInstallation

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 addTestFile(File file)

Adds a file or directory to the list of apks to installed.

void addTestFileName(String fileName)

Adds a file name to the list of apks to installed.

IAbi getAbi()
ITestDevice getDevice()

Returns the device that the preparer should apply to.

TestInformation getTestInfo()
getTestsFileName()

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

boolean isCleanUpEnabled()

Returns True if Apks will be cleaned up during tear down.

final boolean isInstantMode()

Returns whether or not instant mode installation has been enabled.

reportDependencies()
void setAaptVersion(AaptParser.AaptVersion aaptVersion)

Sets the version of AAPT for APK parsing.

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 setForceQueryable(boolean forceQueryable)

The default value of the force queryable is true.

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)

This method is deprecated. Temporary backward compatible callback.

void setUp(TestInformation testInfo)

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(TestInformation testInfo, Throwable e)

Protected methods

IncrementalInstallSession.Builder getIncrementalInstallSessionBuilder()

Initialize the session builder for installing a test app incrementally.

File getLocalPathForFilename(TestInformation testInfo, String apkFileName)

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

void installPackageIncrementally(IncrementalInstallSession.Builder builder)

Start the incremental installation session for a test app.

void installer(TestInformation testInfo, appFilesAndPackages)

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

String parsePackageName(File testAppFile)

Get the package name from the test app.

resolveApkFiles(TestInformation testInfo, apkFiles)

Helper to resolve some apk to their File and Package.

void setTestInformation(TestInformation testInfo)
void uninstallPackage(ITestDevice device, String packageName)

Attempt to remove the package from the device.

Fields

incrementalInstallSession

protected IncrementalInstallSession incrementalInstallSession

mBlockFilterPercentage

protected double mBlockFilterPercentage

mIncrementalInstallTimeout

protected int mIncrementalInstallTimeout

mIncrementalInstallation

protected boolean mIncrementalInstallation

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 ','

addTestFile

public void addTestFile (File file)

Adds a file or directory to the list of apks to installed.

Parameters
file File

addTestFileName

public void addTestFileName (String fileName)

Adds a file name to the list of apks to installed.

Parameters
fileName String

getAbi

public IAbi getAbi ()

Returns
IAbi

getDevice

public ITestDevice getDevice ()

Returns the device that the preparer should apply to.

Returns
ITestDevice

Throws
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

getTestInfo

public TestInformation getTestInfo ()

Returns
TestInformation

getTestsFileName

public  getTestsFileName ()

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

Returns

isCleanUpEnabled

public boolean isCleanUpEnabled ()

Returns True if Apks will be cleaned up during tear down.

Returns
boolean

isInstantMode

public final boolean isInstantMode ()

Returns whether or not instant mode installation has been enabled.

Returns
boolean

reportDependencies

public  reportDependencies ()

Returns

setAaptVersion

public void setAaptVersion (AaptParser.AaptVersion aaptVersion)

Sets the version of AAPT for APK parsing.

Parameters
aaptVersion AaptParser.AaptVersion

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

setForceQueryable

public void setForceQueryable (boolean forceQueryable)

The default value of the force queryable is true. Update it to false if the apk to be installed should not be queryable.

Parameters
forceQueryable 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)

This method is deprecated.
Temporary backward compatible callback.

Parameters
device ITestDevice

buildInfo IBuildInfo

Throws
BuildError
DeviceNotAvailableException
TargetSetupError

setUp

public void setUp (TestInformation testInfo)

Parameters
testInfo TestInformation

Throws
BuildError
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 (TestInformation testInfo, 
                Throwable e)

Parameters
testInfo TestInformation

e Throwable

Throws
DeviceNotAvailableException

Protected methods

getIncrementalInstallSessionBuilder

protected IncrementalInstallSession.Builder getIncrementalInstallSessionBuilder ()

Initialize the session builder for installing a test app incrementally.

Returns
IncrementalInstallSession.Builder

getLocalPathForFilename

protected File getLocalPathForFilename (TestInformation testInfo, 
                String apkFileName)

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

Parameters
testInfo TestInformation: The TestInformation for the invocation.

apkFileName String: filename of the apk to install

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

Throws
TargetSetupError

installPackageIncrementally

protected void installPackageIncrementally (IncrementalInstallSession.Builder builder)

Start the incremental installation session for a test app.

Parameters
builder IncrementalInstallSession.Builder: The Builder object for the incremental install session.

Throws
com.android.tradefed.targetprep.TargetSetupError
TargetSetupError

installer

protected void installer (TestInformation testInfo, 
                 appFilesAndPackages)

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

Parameters
testInfo TestInformation: the TestInformation for the invocation

appFilesAndPackages : The apks and their package to be installed.

Throws
DeviceNotAvailableException
TargetSetupError

parsePackageName

protected String parsePackageName (File testAppFile)

Get the package name from the test app.

Parameters
testAppFile File

Returns
String

Throws
TargetSetupError

resolveApkFiles

protected  resolveApkFiles (TestInformation testInfo, 
                 apkFiles)

Helper to resolve some apk to their File and Package.

Parameters
testInfo TestInformation

apkFiles

Returns

Throws
DeviceNotAvailableException
TargetSetupError

setTestInformation

protected void setTestInformation (TestInformation testInfo)

Parameters
testInfo TestInformation

uninstallPackage

protected void uninstallPackage (ITestDevice device, 
                String packageName)

Attempt to remove the package from the device.

Parameters
device ITestDevice

packageName String

Throws
DeviceNotAvailableException