Sl4aClient

public class Sl4aClient
extends Object implements AutoCloseable

java.lang.Object
   ↳ com.android.tradefed.util.sl4a.Sl4aClient


Sl4A client to interact via RPC with SL4A scripting layer.

Summary

Constants

String IS_SL4A_RUNNING_CMD

String IS_SL4A_RUNNING_CMD_OLD

String SL4A_LAUNCH_CMD

String STOP_SL4A_CMD

Public constructors

Sl4aClient(ITestDevice device, int hostPort, int devicePort)

Creates the Sl4A client.

Sl4aClient(ITestDevice device, File sl4aApkFile)

Creates the Sl4A client.

Public methods

void close()

Close the sl4a connection to device side and Kills any running instance of sl4a.

Sl4aEventDispatcher getEventDispatcher()

Return the event dispatcher to wait for events.

boolean isSl4ARunning()

Return true if the sl4a device side client is running.

void open()

Helper to actually starts the connection host to device for sl4a.

Object rpcCall(String methodName, Object... args)

Execute an RPC call on the sl4a layer.

static Sl4aClient startSL4A(ITestDevice device, File sl4aApkFile)

Convenience method to create and start a client ready to use.

void startSl4A()

Starts the sl4a client on the device side.

Protected methods

IRunUtil getRunUtil()

Return the default runutil instance.

void startEventDispatcher()

Starts the event dispatcher.

Constants

IS_SL4A_RUNNING_CMD

String IS_SL4A_RUNNING_CMD

Constant Value: "ps -e | grep "S com.googlecode.android_scripting""

IS_SL4A_RUNNING_CMD_OLD

String IS_SL4A_RUNNING_CMD_OLD

Constant Value: "ps | grep "S com.googlecode.android_scripting""

SL4A_LAUNCH_CMD

String SL4A_LAUNCH_CMD

Constant Value: "am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER --ei com.googlecode.android_scripting.extra.USE_SERVICE_PORT %s com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher"

STOP_SL4A_CMD

String STOP_SL4A_CMD

Constant Value: "am force-stop com.googlecode.android_scripting"

Public constructors

Sl4aClient

Sl4aClient (ITestDevice device, 
                int hostPort, 
                int devicePort)

Creates the Sl4A client.

Parameters
device ITestDevice: the {ITestDevice} that the client will be for.

hostPort int: the port on the host machine to connect to the sl4a client.

devicePort int: the device port used to communicate to.

Sl4aClient

Sl4aClient (ITestDevice device, 
                File sl4aApkFile)

Creates the Sl4A client.

Parameters
device ITestDevice: the {ITestDevice} that the client will be for.

sl4aApkFile File: file path to hte sl4a apk to install, or null if already installed.

Throws
DeviceNotAvailableException

Public methods

close

void close ()

Close the sl4a connection to device side and Kills any running instance of sl4a. If no instance is running then nothing is done.

getEventDispatcher

Sl4aEventDispatcher getEventDispatcher ()

Return the event dispatcher to wait for events.

Returns
Sl4aEventDispatcher

isSl4ARunning

boolean isSl4ARunning ()

Return true if the sl4a device side client is running.

Returns
boolean

Throws
DeviceNotAvailableException

open

void open ()

Helper to actually starts the connection host to device for sl4a.

rpcCall

Object rpcCall (String methodName, 
                Object... args)

Execute an RPC call on the sl4a layer.

Parameters
methodName String: the name of the method to be called on device side.

args Object: the arg list to be used on the method.

Returns
Object the result of the request.

Throws
IOException if the requested method does not exists.

startSL4A

Sl4aClient startSL4A (ITestDevice device, 
                File sl4aApkFile)

Convenience method to create and start a client ready to use.

Parameters
device ITestDevice: the {ITestDevice} that the client will be for.

sl4aApkFile File: file path to hte sl4a apk to install, or null if already installed.

Returns
Sl4aClient an Sl4aClient instance that has been started.

Throws
DeviceNotAvailableException

startSl4A

void startSl4A ()

Starts the sl4a client on the device side. Assume the sl4a apk is installed.

Throws
DeviceNotAvailableException

Protected methods

getRunUtil

IRunUtil getRunUtil ()

Return the default runutil instance. Exposed for testing.

Returns
IRunUtil

startEventDispatcher

void startEventDispatcher ()

Starts the event dispatcher. Exposed for testing.

Throws
DeviceNotAvailableException