public class DUtilities
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static AndroidTools |
androidsdk
static android sdk tool to the one appropriate for the OS (Windows or Unix).
|
protected static AntTool |
anttool
static ant sdk tool to the one appropriate for the OS (Windows or Unix).
|
static com.android.ddmlib.AndroidDebugBridge |
bridge
ADB: The central point to communicate with any devices, emulators, or the applications running on them.
|
static java.lang.String |
DEFAULT_DEVICE_SERIAL
Empty until set.
|
static java.lang.String |
DEFAULT_EMULATOR_AVD
null until set.
|
protected static int |
DEFAULT_INSTALL_APK_TIMEOUT
120 seconds to wait the installation process to finish.
|
static java.lang.String |
DEVICE_STRING |
static boolean |
installAUT
Default TRUE flag to (re)install the AUT Target Package APK upon launch.
|
static boolean |
installMessenger
Default FALSE flag to (re)install the SAFS TCP Messenger Package APK upon launch.
|
(package private) static java.lang.String[] |
installParams
The parameters used by 'adb' to install an application on device/emulator
You should modify the third value in this array Attention: use the clone of this field as it is static and shared by threads |
static boolean |
installRunner
Default TRUE flag to (re)install the Test Runner APK upon launch.
|
static boolean |
IS_TEST_TARGET_PACKAGE_SET
If
TEST_TARGET_PACKAGE is set, this field will be true. |
(package private) static java.lang.String[] |
launchTestCaseParams
The parameters used by 'adb' to launch a test runner on device/emulator
You should modify the fourth value in this array Attention: use the clone of this field as it is static and shared by threads |
static java.lang.String |
MANIFEST_XML_FILENAEM |
protected static GenericProcessMonitor |
mon |
static java.lang.String |
OFFLINE_STRING |
static boolean |
rebuildRunner
Default FALSE flag to rebuild the Test Runner APK before installing it at launch time.
|
static java.lang.String[] |
rebuildRunnerAntArgs
Default NULL value of arguments to pass to the Ant launcher used to rebuild the
Test Runner APK before installing it at launch time.
|
static boolean |
rebuildRunnerForce
Default FALSE flag.
|
static int |
REMOTE_DROID_LAUNCH_TIMEOUT
180 (seconds) by default.
|
static int |
REMOTE_LAUNCH_TIMEOUT
20.
|
static java.lang.String |
RESIGN_JAR_ENV |
static java.lang.String |
RESIGN_JAR_FULL_NAME
This field contains the resign jar file's absolute name, for example, "C:\safs\lib\re-sign.jar".
|
static java.lang.String |
ROOT_ANT_SDK_DIR
Default: D:\ant182
Set to the root directory where the ant Development SDK is located. |
static java.lang.String |
ROOT_DROID_PROJECT_DIR
Default: "C:\\SAFS\samples\Droid"
Set to the root directory where the Droid project files are located.
|
static java.lang.String |
ROOT_DROID_SDK_DIR
Default: C:\Program Files\Android\android-sdk\
Set to the root directory where the Droid Development SDK is located. |
static java.lang.String |
ROOT_DROID_SDK_TOOLS
Default: C:\Program Files\Android\android-sdk\tools
Set to the directory where the Droid Development SDK Tools are located. |
static java.lang.String |
SAFS_SERVICE_APP
Default: SAFSMessenger\bin\SAFSTCPMessenger-debug.apk
Set to the path to the SAFS Communication Service app. |
static java.lang.String |
SAFS_SERVICE_PACKAGE
Default: org.safs.android.messenger
Set to the expected package name of the SAFS Service. |
static java.lang.String |
TEST_RUNNER_APP
Default: ? RobotiumTestRunner\bin\RobotiumTestRunner-debug.apk ?
Set to the path to the Test Runner app. |
static java.lang.String |
TEST_RUNNER_APP_SOURCE
Default: RobotiumTestRunner
Set to the path to the Test Runner app's source folder. |
static java.lang.String |
TEST_RUNNER_INSTRUMENT
Default: com.jayway.android.robotium.remotecontrol.client/com.jayway.android.robotium.remotecontrol.client.RobotiumTestRunner
Set to the expected package and class name of the Test Runner Instrument. |
static java.lang.String |
TEST_RUNNER_PACKAGE
Default: com.jayway.android.robotium.remotecontrol.client
Set to the expected package name of the Test Runner. |
static java.lang.String |
TEST_TARGET_APP
Default: pathTo\bin\ApiDemos-debug.apk
Set to the path to the target Application. |
static java.lang.String |
TEST_TARGET_PACKAGE
Default: org.safs.android.engine
Set to the expected package name of the target Application. |
static int |
timeoutWaitInstallAPK
The timeout in seconds to wait the installation of APK, it is set to default timeout 120 seconds.
|
(package private) static java.lang.String[] |
uninstallParams
The parameters used by 'adb' to uninstall an application on device/emulator
This version also clears application data and cache. You should modify the second value in this array Attention: use the clone of this field as it is static and shared by threads |
(package private) static java.lang.String[] |
uninstallParamsNoClear
The parameters used by 'adb' to uninstall an application on device/emulator
This version does NOT clear application data or cache. You should modify the third value in this array Attention: use the clone of this field as it is static and shared by threads |
(package private) static java.lang.String[] |
uninstallParamsNoClearByShell
The parameters used by 'adb shell command: pm - package manager' to uninstall an application on device/emulator
Sometimes 'adb uninstall -k application.package' will fail to un-install, so try "adb shell pm uninstall -k application.package" to un-install This version does NOT clear application data or cache. You should modify the fifth value in this array Attention: use the clone of this field as it is static and shared by threads |
static java.lang.String |
USE_DEVICE_SERIAL
Empty until set.
|
protected static DUtilities |
utils |
static int |
XML_MODIFIED_FAIL |
static int |
XML_MODIFIED_NO_CHANGE |
static int |
XML_MODIFIED_SUCCESS |
Constructor and Description |
---|
DUtilities() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
addDeviceSerialParam(java.lang.String[] params)
Add the petential parameter "-s serivalNumber" to the parameters passed to command 'adb'.
This petential parameter is stored in USE_DEVICE_SERIAL |
static java.lang.String |
argsToString(java.lang.String[] args) |
static boolean |
buildAPK(java.lang.String appDirString,
boolean debug)
We use ant to build the apk.
The method will depend on the build.xml, android-sdk-home, ant-home |
static void |
copyFile(java.io.File source,
java.io.File target)
Copy the bytes of one file overwriting or creating a new file.
|
protected static void |
debug(java.lang.String message)
Writes to System.out.
|
protected void |
debugI(java.lang.String message) |
protected static void |
error(java.lang.String message)
Writes to System.err.
|
static com.android.ddmlib.AndroidDebugBridge |
getAndroidDebugBridge()
Get the AndroidDebugBridge instance.
|
static AndroidTools |
getAndroidTools(java.lang.String androidToolHome)
Set our static android sdk tool to the one appropriate for the OS (Windows or Unix).
The routine does nothing if the appropriate sdk instance is already set. For the sdk's tool home, it firstly try to set it to parameter 'androidToolHome' If androidToolHome is not a valid home path: it will try to get it from the 'VM properties' AndroidTools.ANDROID_HOME_SYS_PROP or from 'systeme environment' AndroidTools.ANDROID_HOME_ENV_VAR or from 'systeme environment' AndroidTools.ANDROID_SDK_ENV_VAR |
static AntTool |
getAntTool(java.lang.String antToolHome)
Set our static ant sdk tool to the one appropriate for the OS (Windows or Unix).
The routine does nothing if the appropriate sdk instance is already set. For the sdk's tool home, it firstly try to set it to parameter 'antToolHome' If antToolHome is not a valid home path: it will try to get it from the 'VM properties' AntTool.ANT_HOME_PROP or from 'systeme environment' AntTool.ANT_HOME_ENV |
static java.util.List<java.lang.String> |
getAttachedDevices()
Extract the list of Android Debug Bridge attached devices from Android Tools
|
static java.awt.image.BufferedImage |
getDeviceScreenImage(com.android.ddmlib.IDevice device,
int rotation,
boolean rotatable)
Grab an image from an ADB-connected device.
|
static com.android.ddmlib.IDevice |
getIDevice()
Return the device that we want to test with.
|
protected static GenericProcessMonitor |
getProcessMonitor()
Returns a blank instance of GenericProcessMonitor on which to call the necessary
static methods.
|
static java.lang.String |
getResignJarFileName() |
static java.lang.String |
getTargetPackageValue(java.lang.String apkFile)
Get the value of attribute 'package' from the tag
|
protected static void |
initAndroidTools()
Before calling this method:
Remember to set ROOT_DROID_SDK_DIR or set 'vm properties' AndroidTools.ANDROID_HOME_SYS_PROP or set 'systeme environment' AndroidTools.ANDROID_HOME_ENV_VAR or set 'systeme environment' AndroidTools.ANDROID_SDK_ENV_VAR |
protected static void |
initAntTool()
Before calling this method:
Remember to set ROOT_ANT_SDK_DIR or set 'vm properties' AntTool.ANT_HOME_PROP or set 'systeme environment' AntTool.ANT_HOME_ENV |
static boolean |
installEnabledAPKs()
Note: Risk!!! If some threads modify
TEST_TARGET_APP , TEST_RUNNER_APP
or SAFS_SERVICE_APP during this method is called, wrong. |
static void |
installReplaceAPK(java.lang.String apkPath)
Install the single APK provided in apkPath with the -r (replace) option.
|
static boolean |
isDeviceOffline()
Calls getAttachedDevices and returns true if any are offline.
|
static void |
killADBServer()
Attempt an adb "kill-server" command.
|
static boolean |
launchEmulatorAVD(java.lang.String avd)
Attempt to launch a prestored Emulator -avd and a -no-snapstorage argument.
|
static boolean |
launchTestInstrumentation()
Note: Risk!!! If some threads modify
TEST_RUNNER_INSTRUMENT
during this method is called, wrong. |
static boolean |
launchTestInstrumentation(java.lang.String instrumentArg)
Launches the test instrumentation which should also automatically launch our remote TCP Messenger.
|
static int |
modifyAndroidManifestXml(java.io.File xmlFile,
java.lang.String[][] tagAttributeValueArray)
Modify an attribute's value of a certain tag.
|
static boolean |
rebuildRunner()
Note: Risk!!! If some threads modify
TEST_TARGET_APP , TEST_RUNNER_APP
or TEST_RUNNER_APP_SOURCE during this method is called, wrong. |
static java.lang.String |
rebuildTestRunnerApk(java.lang.String testRunnerSourceDir,
java.lang.String autApk,
java.lang.String testRunnerApk,
java.lang.String instrumentArg,
boolean debug)
User may want to rebuild the TestRunner apk according to the "package" of "aut apk"
|
static void |
resetADBServer()
Execute adb kill-server then adb start-server back-to-back with a 4 second delay between.
|
static boolean |
resignAUTApk()
This method is used to resign AUT
TEST_TARGET_APP automatically.Before calling this method, the field RESIGN_JAR_FULL_NAME needs to be set.This method should be called before method installEnabledAPKs() |
static boolean |
resignAUTApk(java.lang.String resignJar,
java.lang.String apkFullName)
This method is used to resign an android apk.
|
static void |
setAndroidToolsHome(java.lang.String androidToolHome)
You can always change the
androidsdk 's home path by calling this method.But be careful, if you call this method, you will modify the tool-home of Singleton AndroidTools ,and the other thread may be affected when the use AndroidTools. |
static void |
setAntToolsHome(java.lang.String antToolHome)
|
static boolean |
shutdownEmulatorProcess(java.lang.String emulator)
Attempt to shutdown a specific emulator Process.
|
static boolean |
shutdownLaunchedEmulators(boolean shutdownAnyEmulator)
Attempts to shutdown (process destroy!) any emulators we have launched.
|
static void |
startADBServer()
Attempt an adb "start-server" command.
|
static void |
uninstallAPK(java.lang.String apkFullPath,
boolean clearData)
Uninstall (remove) the single APK provided in apkFullPath.
|
static void |
uninstallAPKPackage(java.lang.String apkPackage,
boolean clearData)
Uninstall (remove) the single APK (package) provided in apkPackage.
|
static boolean |
unlockDeviceScreen()
Send an appropriate adb command to unlock the screen.
|
static boolean |
waitDevice()
The routine will attempt to make sure adb devices are valid and not offline
|
protected static DUtilities utils
public static java.lang.String ROOT_DROID_SDK_DIR
public static java.lang.String ROOT_DROID_SDK_TOOLS
public static java.lang.String ROOT_ANT_SDK_DIR
public static java.lang.String ROOT_DROID_PROJECT_DIR
public static java.lang.String SAFS_SERVICE_APP
public static java.lang.String SAFS_SERVICE_PACKAGE
public static java.lang.String TEST_RUNNER_APP
public static java.lang.String TEST_RUNNER_APP_SOURCE
public static java.lang.String TEST_RUNNER_PACKAGE
public static java.lang.String TEST_RUNNER_INSTRUMENT
public static java.lang.String TEST_TARGET_APP
public static java.lang.String TEST_TARGET_PACKAGE
public static boolean IS_TEST_TARGET_PACKAGE_SET
TEST_TARGET_PACKAGE
is set, this field will be true.protected static final int DEFAULT_INSTALL_APK_TIMEOUT
public static int timeoutWaitInstallAPK
static java.lang.String[] installParams
Usage: String[] params = installParams.clone(); params[2] = "yourApp.apk";
SAFS_SERVICE_APP
,
#SAFS_ENGINE_APP
,
TEST_TARGET_APP
static java.lang.String[] uninstallParams
Usage: String[] params = uninstallParams.clone(); params[1] = "your.app.package";
static java.lang.String[] uninstallParamsNoClear
Usage: String[] params = uninstallParamsNoClear.clone(); params[2] = "your.app.package";
static java.lang.String[] uninstallParamsNoClearByShell
Usage: String[] params = uninstallParamsNoClear.clone(); params[4] = "your.app.package";
static java.lang.String[] launchTestCaseParams
Usage: String[] params = launchTestCaseParams.clone(); params[3] = "yourRunnerInstrument";
#SAFS_ENGINE_INSTRUMENT
,
#ROBOTIUM_ENGINE_INSTRUMENT
public static final java.lang.String MANIFEST_XML_FILENAEM
public static java.lang.String DEFAULT_DEVICE_SERIAL
public static java.lang.String USE_DEVICE_SERIAL
public static java.lang.String DEFAULT_EMULATOR_AVD
public static final java.lang.String DEVICE_STRING
public static final java.lang.String OFFLINE_STRING
public static int REMOTE_DROID_LAUNCH_TIMEOUT
public static int REMOTE_LAUNCH_TIMEOUT
protected static AndroidTools androidsdk
protected static AntTool anttool
public static boolean installAUT
public static boolean installMessenger
public static boolean installRunner
public static boolean rebuildRunner
public static java.lang.String[] rebuildRunnerAntArgs
On Windows, a very common Ant launcher arg to pass is "-noclasspath" to force the Ant build to ignore the Windows CLASSPATH Environment variable.
This value should be considered separate from the typical "debug" or "release" args sent to Ant. Instead, these are for the platform-specific Ant launchers: ant.bat, etc..
public static boolean rebuildRunnerForce
Note: rebuildRunner must also be true. This force override only applies if a rebuild has been requested, but the detection of unchanged AndroidManifest XML would otherwise forego the actual rebuild.
public static java.lang.String RESIGN_JAR_FULL_NAME
TEST_TARGET_APP
automatically. If this field is
null, the AUT TEST_TARGET_APP
will not be resigned.
This field only take effect when field installAUT
is true.
protected static GenericProcessMonitor mon
public static com.android.ddmlib.AndroidDebugBridge bridge
public static final int XML_MODIFIED_FAIL
public static final int XML_MODIFIED_SUCCESS
public static final int XML_MODIFIED_NO_CHANGE
public static final java.lang.String RESIGN_JAR_ENV
protected void debugI(java.lang.String message)
protected static void debug(java.lang.String message)
message
- public static boolean installEnabledAPKs()
TEST_TARGET_APP
, TEST_RUNNER_APP
or SAFS_SERVICE_APP
during this method is called, wrong. use synchronized block?
for each APK whose install boolean is still true, install the apk.public static boolean rebuildRunner()
TEST_TARGET_APP
, TEST_RUNNER_APP
or TEST_RUNNER_APP_SOURCE
during this method is called, wrong. use synchronized block?
Try to rebuild the test-runner apk.#testRunnerApk
installEnabledAPKs()
installEnabledAPKs()
public static boolean launchTestInstrumentation()
TEST_RUNNER_INSTRUMENT
during this method is called, wrong. use synchronized block?public static AndroidTools getAndroidTools(java.lang.String androidToolHome)
AndroidTools.ANDROID_HOME_SYS_PROP
AndroidTools.ANDROID_HOME_ENV_VAR
AndroidTools.ANDROID_SDK_ENV_VAR
androidToolHome
- String, the android tool's sdk home pathAndroidTools
protected static void error(java.lang.String message)
message
- protected static GenericProcessMonitor getProcessMonitor()
public static void setAndroidToolsHome(java.lang.String androidToolHome)
androidsdk
's home path by calling this method.AndroidTools
,androidToolHome
- String, the android tool's sdk home pathprotected static void initAndroidTools()
ROOT_DROID_SDK_DIR
AndroidTools.ANDROID_HOME_SYS_PROP
AndroidTools.ANDROID_HOME_ENV_VAR
AndroidTools.ANDROID_SDK_ENV_VAR
public static AntTool getAntTool(java.lang.String antToolHome)
AntTool.ANT_HOME_PROP
AntTool.ANT_HOME_ENV
antToolHome
- String, the ant tool's sdk home pathAntTool
public static void setAntToolsHome(java.lang.String antToolHome)
anttool
's home path by calling this method.AntTool
,antToolHome
- String, the ant tool's sdk home pathprotected static void initAntTool()
ROOT_ANT_SDK_DIR
AntTool.ANT_HOME_PROP
AntTool.ANT_HOME_ENV
public static java.util.List<java.lang.String> getAttachedDevices() throws java.lang.RuntimeException
adb devices
java.lang.RuntimeException
- if there is a problem executing the Android Debug Bridge (adb)public static com.android.ddmlib.AndroidDebugBridge getAndroidDebugBridge()
public static com.android.ddmlib.IDevice getIDevice()
public static java.awt.image.BufferedImage getDeviceScreenImage(com.android.ddmlib.IDevice device, int rotation, boolean rotatable)
device,
- IDevice: the android device or emulator, it can be got by getIDevice()
rotation,
- int: the device rotation in degree rotatable,
- boolean: if the application is rotatablegetIDevice()
public static boolean launchEmulatorAVD(java.lang.String avd) throws AndroidRuntimeException
emulator -avd (avd)
AndroidRuntimeException
- if an error occurs while trying to launch the emulator or
trying to extract the number of adb devices.public static boolean shutdownEmulatorProcess(java.lang.String emulator) throws java.io.IOException
emulator
- -- known valid values: "emulator", "emulator-arm", "emulator-mips", "emulator-x86"java.io.IOException
public static boolean shutdownLaunchedEmulators(boolean shutdownAnyEmulator)
Note the built-in process to signal an emulator shutdown does not seem to work on Windows. Windows runs emulator.exe which launches emulator-arm.exe. The shutdown request does not seem to impact emulator-arm.exe.
shutdownAnyEmulator
- to attempt to kill any emulator, whether we started it or not.public static boolean isDeviceOffline()
getAttachedDevices()
public static void resetADBServer()
public static void startADBServer()
public static void killADBServer()
public static void installReplaceAPK(java.lang.String apkPath) throws java.lang.RuntimeException
apkPath
- to APK ready for installation.java.lang.RuntimeException
- if the process was interrupted, had an IOException, or
did not exit in the timeout period or did not exit with success.public static void uninstallAPK(java.lang.String apkFullPath, boolean clearData) throws java.lang.RuntimeException
apkFullPath
- the full path name of the APK to uninstallclearData
- set true to force a clear of the app data and cache along with the uninstall.java.lang.RuntimeException
- if the process was interrupted, had an IOException, or
did not exit with success.uninstallAPKPackage(String, boolean)
public static void uninstallAPKPackage(java.lang.String apkPackage, boolean clearData) throws java.lang.RuntimeException
apkPackage
- the name of the APK package to uninstallclearData
- set true to force a clear of the app data and cache along with the uninstall.java.lang.RuntimeException
- if the process was interrupted, had an IOException, or
did not exit with success.uninstallAPK(String, boolean)
public static boolean launchTestInstrumentation(java.lang.String instrumentArg) throws java.lang.RuntimeException
java.lang.RuntimeException
public static boolean unlockDeviceScreen()
addDeviceSerialParam(String[])
to the default command.public static java.lang.String[] addDeviceSerialParam(java.lang.String[] params)
USE_DEVICE_SERIAL
params
- String[], string array used by command 'adb'USE_DEVICE_SERIAL
public static boolean waitDevice()
public static java.lang.String getTargetPackageValue(java.lang.String apkFile)
apkFile
- String, the apk file from which we want to get the "package's value"public static int modifyAndroidManifestXml(java.io.File xmlFile, java.lang.String[][] tagAttributeValueArray)
xmlFile
- File, the xml filetagAttributeValueArray,
- 2-dimension array, the second dimension is 3, containing following
tag String, the tag to be modified
attribute String, the attribute to be modified
value String, the value will be set to attributepublic static boolean buildAPK(java.lang.String appDirString, boolean debug)
appDirString
- String, the path where apk source locates, an ant build.xml should exists there.debug
- boolean, true --> build in debug; false --> build in release.public static java.lang.String argsToString(java.lang.String[] args)
public static java.lang.String rebuildTestRunnerApk(java.lang.String testRunnerSourceDir, java.lang.String autApk, java.lang.String testRunnerApk, java.lang.String instrumentArg, boolean debug)
testRunnerSourceDir
- String, the full path where the 'test runner' source is stored.autApk
- String, the full path of the aut's apk file.testRunnerApk
- String, the full path of the testrunner's apk file.instrumentArg
- String, the instrumentation string.debug
- boolean, true to make a debug build; false to make a release build.public static void copyFile(java.io.File source, java.io.File target)
source
- File should already be known to existtarget
- File should already be known to be writable.public static java.lang.String getResignJarFileName()
public static boolean resignAUTApk()
TEST_TARGET_APP
automatically.RESIGN_JAR_FULL_NAME
needs to be set.installEnabledAPKs()
TEST_TARGET_APP
,
RESIGN_JAR_FULL_NAME
,
installAUT
,
installEnabledAPKs()
public static boolean resignAUTApk(java.lang.String resignJar, java.lang.String apkFullName)
resignJar
- The full name of re-sign.jarapkFullName
- The full name of android apk to be resigned.Copyright © SAS Institute. All Rights Reserved.