# Class: com.pnfsoftware.jeb.core.units.code.android.adb.AdbWrapper

A controller for the Android Debug Bridge \(ADB\) tool. Remember to call [#initialize()](#initialize()) if necessary \(e.g., first adb run\). Most methods in this class return null on error. 

 This class contains several helpful utility methods; if what you're looking for is not here, use [execute](#execute(long, Collection)) or [executeOn](#executeOn(long, String, Collection)) as a last resort. More complex and/or smarter wrapper functions can also be found in the [AndroidDeviceUtil](AndroidDeviceUtil) class. 

 This class is thread\-safe; the object itself may be used in synchronized blocks for transactions. 

 TODO: use [ProcessWrapper](ProcessWrapper)

## Static Field: STANDARD_TIMEOUT
Type: `long`

Constant value: `5000`
Description: Standard command execution timeout is 5 seconds.

## Method: chmod
- parameter: `user`, type: `java.lang.String`
- parameter: `path`, type: `java.lang.String`
- parameter: `perm`, type: `int`
- parameter: `recurse`, type: `boolean`
- return type: `boolean`

Description: Change the permissions of a file or folder.
parameter: user: 
parameter: path: 
parameter: perm: 
parameter: recurse: 
return: 

## Method: chown
- parameter: `user`, type: `java.lang.String`
- parameter: `path`, type: `java.lang.String`
- parameter: `userName`, type: `java.lang.String`
- parameter: `groupName`, type: `java.lang.String`
- parameter: `recurse`, type: `boolean`
- return type: `boolean`

Description: Change the ownership of a file or folder.
parameter: user: 
parameter: path: 
parameter: userName: mandatory
parameter: groupName: optional
parameter: recurse: 
return: 

## Method: copyFile
- parameter: `user`, type: `java.lang.String`
- parameter: `srcPath`, type: `java.lang.String`
- parameter: `dstPath`, type: `java.lang.String`
- parameter: `recurse`, type: `boolean`
- return type: `boolean`

Description: Copy a file or folder.
parameter: user: 
parameter: srcPath: 
parameter: dstPath: 
return: 

## Method: dateEpoch
- return type: `long`

Description: Retrieve the device date in seconds since 1970\-01\-01 00:00:00 UTC.
return: \-1 on error, else the Unix timestamp

## Method: dateString
- parameter: `appendTimezoneDelta`, type: `boolean`
- return type: `java.lang.String`

Description: Retrieve the device date in the following format: `YYYY-mm-dd_HH:MM:SS` or `YYYY-mm-dd_HH:MM:SS_TZD` where TZD is like "\+/\-HHMM" 

 Examples: "2016\-01\-16\_12:32:44", 2016\-01\-16\_12:32:44\_\-0500
parameter: appendTimezoneDelta: append time zone delta information
return: the date string

## Method: deleteFile
- parameter: `user`, type: `java.lang.String`
- parameter: `path`, type: `java.lang.String`
- parameter: `recurse`, type: `boolean`
- return type: `boolean`

Description: Delete a file or folder.
parameter: user: 
parameter: path: 
parameter: recurse: 
return: 

## Method: execute
- parameter: `timeout`, type: `java.lang.Long`
- parameter: `arguments`, type: `java.util.Collection<java.lang.String>`
- return type: `byte[]`

Description: Execute a command using ADB. This method may block indefinitely, for some time, or return immediately.
parameter: timeout: null to use the default timeout; else, refer to            [CommandExec#CommandExec(long)](CommandExec#CommandExec(long)) for timeout meaning
parameter: arguments: 
return: 

## Method: executeAsync
- parameter: `timeout`, type: `java.lang.Long`
- parameter: `arguments`, type: `java.util.Collection<java.lang.String>`
- return type: `com.pnfsoftware.jeb.util.concurrent.ProcessWrapper`

Description: Advanced method used to execute an ADB command with as much flexibility as needed. This method is non\-blocking.
parameter: timeout: timeout in ms \(use \-1  to specify no timeout; use null to use the default timeout\)
parameter: arguments: adb arguments
return: a process wrapper object; null on error
throws: on error

## Method: executeOn
- parameter: `timeout`, type: `java.lang.Long`
- parameter: `deviceSerial`, type: `java.lang.String`
- parameter: `arguments`, type: `java.util.Collection<java.lang.String>`
- return type: `byte[]`

Description: Execute a command using ADB. Do not provide "\-s ..." manually, use the appropriate argument instead.
parameter: timeout: null to use a default timeout
parameter: deviceSerial: optional, leave null to let ADB decide on which device the command should            be executed
parameter: arguments: 
return: 

## Method: forwardJdwpToTcp
- parameter: `srcJdwpPid`, type: `int`
- parameter: `dstTcpPort`, type: `int`
- return type: `boolean`


## Method: forwardLocalToTcp
- parameter: `srcDomainSocket`, type: `java.lang.String`
- parameter: `dstTcpPort`, type: `int`
- return type: `boolean`


## Method: forwardToTcp
- parameter: `srcType`, type: `com.pnfsoftware.jeb.core.units.code.android.adb.AdbForwardType`
- parameter: `srcDomainSocket`, type: `java.lang.String`
- parameter: `dstTcpPort`, type: `int`
- return type: `boolean`


## Method: getDefaultTimeout
- return type: `long`


## Method: getPath
- return type: `java.lang.String`

Description: Get the path to the ADB binary wrapped by this object.
return: 

## Method: getRunAs
- return type: `java.lang.String`


## Method: getTargetDevice
- return type: `java.lang.String`

Description: Get the default target device for operations. The result may be null, in which case, adb will work if and only if a single device is connected \(and that device will be used for operations\).
return: the serial number \(the case matters\); may be null if no target was explicitly         specified

## Method: getToolName
- parameter: `name`, type: `java.lang.String`
- return type: `java.lang.String`


## Method: getVersion
- return type: `java.lang.String`

Description: Get the adb tool version used by this wrapper.
return: 

## Method: hasFile
- parameter: `user`, type: `java.lang.String`
- parameter: `path`, type: `java.lang.String`
- return type: `boolean`

Description: Verify if a file is present.
parameter: user: 
parameter: path: full exact path, no wildcard
return: 

## Method: initialize
- return type: `boolean`


## Method: installApp
- parameter: `apkPath`, type: `java.lang.String`
- return type: `boolean`


## Method: installApp
- parameter: `apkPath`, type: `java.lang.String`
- parameter: `allowReplace`, type: `boolean`
- parameter: `onSdcard`, type: `boolean`
- parameter: `grantRuntimePermissions`, type: `boolean`
- return type: `boolean`

Description: Install an APK.
parameter: apkPath: 
parameter: allowReplace: 
parameter: onSdcard: 
parameter: grantRuntimePermissions: 
return: 

## Method: installAppForce
- parameter: `apkPath`, type: `java.lang.String`
- return type: `boolean`


## Method: killProcess
- parameter: `user`, type: `java.lang.String`
- parameter: `pid`, type: `int`

Description: Send the TERM signal to request normal termination of a process.

## Method: killProcess
- parameter: `user`, type: `java.lang.String`
- parameter: `pid`, type: `int`
- parameter: `signal`, type: `int`

Description: Send a signal to a process.

## Method: killProcess
- parameter: `user`, type: `java.lang.String`
- parameter: `pid`, type: `int`
- parameter: `signalNames`, type: `java.lang.String[]`
- return type: `boolean`

Description: Send a signal to a process.

## Method: listDevices
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.adb.AdbDevice>`


## Method: listJdwpPids
- return type: `java.util.List<java.lang.Integer>`

Description: List the PIDs of processes hosting a JDWP transport. Use a timeout of 1 second.
return: a list of process ids

## Method: listPackages
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.adb.AdbPackage>`


## Method: listPackages
- parameter: `options`, type: `com.pnfsoftware.jeb.core.units.code.android.adb.AdbPackageManagerOptions`
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.adb.AdbPackage>`


## Method: listProcesses
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.adb.AdbProcess>`

Description: List the processes running on this device.
return: 

## Method: logcat
- return type: `java.io.InputStream`

Description: Execute the `logcat` command.
return: the raw logcat stream data
throws: on error

## Method: logcat
- parameter: `pid`, type: `java.lang.Integer`
- parameter: `afterDate`, type: `java.lang.String`
- return type: `java.io.InputStream`

Description: Execute the `logcat` command with filter options.
parameter: pid: \(optional\) only the logs issued by the specified process
parameter: afterDate: \(optional\) cut\-off date: only logs generated after the provided date are            output; format must be like `YYYY-mm-dd HH:MM:SS.xxx`
return: the raw logcat stream data
throws: on error

## Method: logcatClear
- return type: `boolean`


## Method: pullFile
- parameter: `remotePath`, type: `java.lang.String`
- parameter: `localPath`, type: `java.lang.String`
- return type: `boolean`

Description: Download a file from a device.
parameter: remotePath: 
parameter: localPath: 
return: 

## Method: pushFile
- parameter: `localPath`, type: `java.lang.String`
- parameter: `remotePath`, type: `java.lang.String`
- return type: `boolean`

Description: Upload a file onto a device.
parameter: localPath: 
parameter: remotePath: 
return: 

## Method: readProperty
- parameter: `propertyName`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Read a device Android property.
parameter: propertyName: property fully\-qualified name
return: 

## Method: setDefaultTimeout
- parameter: `millis`, type: `long`


## Method: setRunAs
- parameter: `path`, type: `java.lang.String`


## Method: setTargetDevice
- parameter: `deviceSerial`, type: `java.lang.String`

Description: Set the default target device for operations.
parameter: deviceSerial: the serial number \(the case matters\)

## Method: setToolName
- parameter: `standardName`, type: `java.lang.String`
- parameter: `alternateName`, type: `java.lang.String`


## Method: shell
- parameter: `user`, type: `java.lang.String`
- parameter: `arguments`, type: `java.util.List<java.lang.String>`
- return type: `com.pnfsoftware.jeb.core.units.code.android.adb.AdbResult`


## Method: shell
- parameter: `timeout`, type: `java.lang.Long`
- parameter: `deviceSerial`, type: `java.lang.String`
- parameter: `user`, type: `java.lang.String`
- parameter: `arguments`, type: `java.util.List<java.lang.String>`
- return type: `com.pnfsoftware.jeb.core.units.code.android.adb.AdbResult`


## Method: shell
- parameter: `arguments`, type: `java.util.List<java.lang.String>`
- return type: `com.pnfsoftware.jeb.core.units.code.android.adb.AdbResult`


## Method: shell
- parameter: `timeout`, type: `java.lang.Long`
- parameter: `deviceSerial`, type: `java.lang.String`
- parameter: `user`, type: `java.lang.String`
- parameter: `arguments`, type: `java.util.List<java.lang.String>`
- parameter: `logOnResult`, type: `boolean`
- return type: `com.pnfsoftware.jeb.core.units.code.android.adb.AdbResult`


## Method: shellAsync
- parameter: `timeout`, type: `java.lang.Long`
- parameter: `deviceSerial`, type: `java.lang.String`
- parameter: `user`, type: `java.lang.String`
- parameter: `arguments`, type: `java.util.List<java.lang.String>`
- return type: `com.pnfsoftware.jeb.util.concurrent.ProcessWrapper`

Description: Advanced method used to execute a shell ADB command. This method is non\-blocking.
parameter: timeout: timeout in ms \(use \-1  to specify no timeout; use null to use the default timeout\)
parameter: deviceSerial: optional target device
parameter: user: optional user
parameter: arguments: adb arguments
return: a process wrapper object; null on error
throws: on error

## Method: shellLog
- parameter: `user`, type: `java.lang.String`
- parameter: `arguments`, type: `java.util.List<java.lang.String>`
- return type: `com.pnfsoftware.jeb.core.units.code.android.adb.AdbResult`


## Method: startActivity
- parameter: `pname`, type: `java.lang.String`
- parameter: `aname`, type: `java.lang.String`
- parameter: `bEnableDebugging`, type: `boolean`
- parameter: `bWaitForLaunch`, type: `boolean`
- parameter: `bForceStopBeforeStart`, type: `boolean`
- return type: `boolean`

Description: Start an activity. Uses the Activity Manager \(am\) internally. Example: `adb shell am start -n com.xyz.appcheck/.AppCheck`
parameter: pname: 
parameter: aname: 
parameter: bEnableDebugging: will wait for debugger to connect. If true, bForceStopBeforeStart is            disregarded; also not recommended to set bWaitForLaunch to true, as am would not            return until a debugger connects
parameter: bWaitForLaunch: wait for activity to have launched before 'am' returns
parameter: bForceStopBeforeStart: the already running activity, if there is one, will be killed            \(instead of simply be brought up to the front\)
return: 

## Method: startActivity
- parameter: `pname`, type: `java.lang.String`
- parameter: `aname`, type: `java.lang.String`
- return type: `boolean`


## Method: startServer
- return type: `boolean`

Description: Start the ADB server \(on the local machine\).
return: 

## Method: stopAllForwards
- parameter: `dstTcpPort`, type: `int`
- return type: `boolean`


## Method: stopApp
- parameter: `pname`, type: `java.lang.String`
- return type: `boolean`


## Method: stopForwardToTcp
- parameter: `dstTcpPort`, type: `int`
- return type: `boolean`

Description: Issue a `adb forward --remove tcp:port` command.
parameter: dstTcpPort: 
return: 

## Method: stopProcess
- parameter: `user`, type: `java.lang.String`
- parameter: `pid`, type: `int`
- return type: `boolean`

Description: Send the STOP signal to a process.

## Method: stopServer

Description: Stop the ADB server.

## Method: toString
- return type: `java.lang.String`


## Method: touchFile
- parameter: `user`, type: `java.lang.String`
- parameter: `path`, type: `java.lang.String`
- return type: `boolean`

Description: Create an empty file.
parameter: user: 
parameter: path: 
return: false indicates sure failure; true indicates potential success \(not guaranteed; use         [#hasFile(String, String, String)](#hasFile(String, String, String)) to confirm\)

## Method: uninstallApp
- parameter: `packageName`, type: `java.lang.String`
- return type: `boolean`


## Method: uninstallApp
- parameter: `packageName`, type: `java.lang.String`
- parameter: `keepData`, type: `boolean`
- return type: `boolean`

Description: Uninstall an APK.
parameter: packageName: 
parameter: keepData: 
return: 

## Method: waitForBootCompletionHeur1
- return type: `boolean`

Description: Uses `dev.bootcomplete` property. Uses a 30 second time\-out. 

 Does not seem reliable.
return: 

## Method: waitForBootCompletionHeur2
- return type: `boolean`

Description: Uses `init.svc.bootanim` property. Uses a 30 second time\-out. 

 Does not seem reliable.
return: 

## Method: waitForBootCompletionHeur3
- return type: `boolean`

Description: Uses the Package Manager to find out whether the system is ready for app installation. Uses a 30 second time\-out. 

 Flaky heuristic \(Jenkins only\), b/c reading 'init.svc.bootanim' does not seem to do the trick on my slow emulator.
return: 

## Method: waitForDevice
- return type: `boolean`

Description: `adb wait-for-device` command. Uses a 30 second time\-out.
return: 

## Method: which
- parameter: `user`, type: `java.lang.String`
- parameter: `path`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Find the location of a binary file.
parameter: user: 
parameter: path: 
return: 

