Documentation
¶
Overview ¶
Package mobly is for interacting with Mobly snippets on Android devices for rich Android automation controls. See https://github.com/google/mobly-snippet-lib for more details.
Package mobly is for interacting with Mobly snippets on Android devices for rich Android automation controls. See https://github.com/google/mobly-snippet-lib for more details.
Index ¶
- Constants
- type EventWaitAndGetResult
- type JSONRPCResponse
- type SnippetClient
- func (sc *SnippetClient) Cleanup(ctx context.Context)
- func (sc *SnippetClient) EventWaitAndGet(ctx context.Context, callbackID, eventName string, timeout time.Duration) (*EventWaitAndGetResult, error)
- func (sc *SnippetClient) RPC(ctx context.Context, timeout time.Duration, method string, args ...interface{}) (*JSONRPCResponse, error)
- func (sc *SnippetClient) ReconnectToSnippet(ctx context.Context) error
Constants ¶
const DefaultRPCResponseTimeout = 10 * time.Second
DefaultRPCResponseTimeout is the default timeout for receiving an RPC response from the snippet. Most RPCs should return a response within a short amount of time. Some RPCs such as eventWaitAndGet may not respond until their specified timeouts are reached.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventWaitAndGetResult ¶
type EventWaitAndGetResult struct { CallbackID int `json:"callback_id"` Name string `json:"name"` CreationTime int `json:"creation_time"` Data map[string]interface{} `json:"data"` }
EventWaitAndGetResult maps the 'result' field of EventWaitAndGet's JSONRPCResponse to a format that's easier to work with.
type JSONRPCResponse ¶
type JSONRPCResponse struct { ID int `json:"id"` Result json.RawMessage `json:"result"` Callback string `json:"callback"` Error string `json:"error"` }
JSONRPCResponse is the corresponding response format for jsonRPCRequest. The Result field's format varies depending on which method is called by the request, so it should be unmarshalled based on the request's API.
type SnippetClient ¶
type SnippetClient struct {
// contains filtered or unexported fields
}
SnippetClient is a client for a single Mobly snippet running on an Android device. Mobly snippets run an on-device JSON RPC server, whose RPCs provide some custom controls on the Android device. This client can be used by Tast tests and support libraries to interact with these snippets.
func NewSnippetClient ¶
func NewSnippetClient(ctx context.Context, d *adb.Device, moblyPackage, apkZipPath, apkName string, apkPermissions ...string) (sc *SnippetClient, err error)
NewSnippetClient initializes the snippet client by doing the following:
- Install and run the specified snippet APK to start the server.
- Forward the snippet's listening port to the host (CrOS device) and establish a TCP connection to it.
We can then send RPCs over the TCP connection to interact with the snippet. The Android package containing the Snippet class must be provided in the moblyPackage argument. Callers should defer Cleanup to ensure the resources used by the SnippetClient are freed.
func (*SnippetClient) Cleanup ¶
func (sc *SnippetClient) Cleanup(ctx context.Context)
Cleanup stops the snippet, removes port forwarding, and closes the TCP connection. This should be deferred after calling NewSnippetClient to ensure the resources used by the SnippetClient are released at the end of tests.
func (*SnippetClient) EventWaitAndGet ¶
func (sc *SnippetClient) EventWaitAndGet(ctx context.Context, callbackID, eventName string, timeout time.Duration) (*EventWaitAndGetResult, error)
EventWaitAndGet waits for the specified event associated with the RPC that returned callbackID to appear in the snippet's event cache.
func (*SnippetClient) RPC ¶
func (sc *SnippetClient) RPC(ctx context.Context, timeout time.Duration, method string, args ...interface{}) (*JSONRPCResponse, error)
RPC formats the provided RPC method and arguments as a jsonRPCRequest, sends it to the server, and returns the server's response.
func (*SnippetClient) ReconnectToSnippet ¶
func (sc *SnippetClient) ReconnectToSnippet(ctx context.Context) error
ReconnectToSnippet restarts a connection to the snippet on Android device.