nearbysnippet

package
v0.0.0-...-683b059 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package nearbysnippet is for interacting with the Nearby Snippet which provides automated control of Android Nearby share.

Index

Constants

View Source
const (
	ZipName = "nearby_snippet.zip"
	ApkName = "nearby_snippet.apk"
)

Constants used in the adb commands for installing and launching the Nearby Snippet.

View Source
const SendDir = "test_files"

SendDir is the subdirectory of the Android downloads directory where we will stage files for sending.

Variables

View Source
var DataUsageStrings = map[DataUsage]string{
	DataUsageOffline:  "Offline",
	DataUsageOnline:   "Online",
	DataUsageWifiOnly: "Wifi Only",
}

DataUsageStrings is a map of DataUsage to human-readable setting values.

View Source
var VisibilityStrings = map[Visibility]string{
	VisibilityUnknown:          "Unknown",
	VisibilityNoOne:            "No One",
	VisibilityAllContacts:      "All Contacts",
	VisibilitySelectedContacts: "Selected Contacts",
	VisibilityEveryone:         "Everyone",
}

VisibilityStrings is a map of Visibility to human-readable setting values.

Functions

This section is empty.

Types

type AndroidAttributes

type AndroidAttributes struct {
	BasicAttributes    *crossdevice.AndroidAttributes
	DisplayName        string
	DataUsage          string
	Visibility         string
	NearbyShareVersion string
	NearbyShareChannel string
}

AndroidAttributes contains information about the Android device and its settings that are relevant to Nearby Share. "Android" is redundantly prepended to the field names to make them easy to distinguish from CrOS attributes in test logs.

type AndroidNearbyDevice

type AndroidNearbyDevice struct {
	// contains filtered or unexported fields
}

AndroidNearbyDevice represents a connected Android device equipped with Nearby Share controls. Nearby Share control is achieved by making RPCs to the Nearby Snippet running on the Android device.

func New

func New(ctx context.Context, d *adb.Device, apkZipPath string, overrideGMS bool) (a *AndroidNearbyDevice, err error)

New initializes the specified Android device for Nearby Sharing by setting up the Nearby snippet on the device and initializing a Mobly snippet client to communicate with it. Callers should defer Cleanup to ensure the resources used by the AndroidNearbyDevice are freed.

func (*AndroidNearbyDevice) AcceptTheSharing

func (a *AndroidNearbyDevice) AcceptTheSharing(ctx context.Context, token string) error

AcceptTheSharing accepts the share on the receiver side.

func (*AndroidNearbyDevice) AcceptUI

func (a *AndroidNearbyDevice) AcceptUI(ctx context.Context, timeout time.Duration) error

AcceptUI accepts the incoming contacts share through the UI and waits for the share to finish by waiting for the receiving UI to be gone.

func (*AndroidNearbyDevice) AwaitReceiverAccept

func (a *AndroidNearbyDevice) AwaitReceiverAccept(ctx context.Context, timeout time.Duration) (string, error)

AwaitReceiverAccept should be used to wait for the onAwaitingReceiverAccept SnippetEvent, which indicates that the Android sender has successfully connected to the receiver. The response includes the secure connection token.

func (*AndroidNearbyDevice) AwaitReceiverConfirmation

func (a *AndroidNearbyDevice) AwaitReceiverConfirmation(ctx context.Context, timeout time.Duration) error

AwaitReceiverConfirmation should be used after ReceiveFile to wait for the onLocalConfirmation SnippetEvent, which indicates that the Android device has detected the incoming share and is awaiting confirmation to begin the transfer.

func (*AndroidNearbyDevice) AwaitSharingStopped

func (a *AndroidNearbyDevice) AwaitSharingStopped(ctx context.Context, timeout time.Duration) error

AwaitSharingStopped waits for the onStop event, which indicates that sharing has stopped and Android Nearby Share teardown tasks have been completed. It does not necessarily indicate that the transfer succeeded.

func (*AndroidNearbyDevice) CancelReceivingFile

func (a *AndroidNearbyDevice) CancelReceivingFile(ctx context.Context) error

CancelReceivingFile ends Nearby Share on the receiving side. This is used to fail fast instead of waiting for ReceiveFile's timeout.

func (*AndroidNearbyDevice) CancelSendingFile

func (a *AndroidNearbyDevice) CancelSendingFile(ctx context.Context) error

CancelSendingFile ends Nearby Share on the sending side. This is used to fail fast instead of waiting for SendFile's timeout.

func (*AndroidNearbyDevice) Cleanup

func (a *AndroidNearbyDevice) Cleanup(ctx context.Context)

Cleanup stops the Nearby Snippet, removes port forwarding, and closes the TCP connection. This should be deferred after calling New to ensure the resources used by the AndroidNearbyDevice are released at the end of tests.

func (*AndroidNearbyDevice) ClearDownloads

func (a *AndroidNearbyDevice) ClearDownloads(ctx context.Context) error

ClearDownloads clears the device's Downloads folder, where outgoing shares are staged and incoming shares are received.

func (*AndroidNearbyDevice) ClearLogcat

func (a *AndroidNearbyDevice) ClearLogcat(ctx context.Context) error

ClearLogcat clears logcat so each test run can have only relevant logs.

func (*AndroidNearbyDevice) CloseUI

func (a *AndroidNearbyDevice) CloseUI(ctx context.Context) error

CloseUI closes the UI automator connection.

func (*AndroidNearbyDevice) DumpLogs

func (a *AndroidNearbyDevice) DumpLogs(ctx context.Context, outDir, filename string) error

DumpLogs saves the Android device's logcat output to a file.

func (*AndroidNearbyDevice) GetAndroidAttributes

func (a *AndroidNearbyDevice) GetAndroidAttributes(ctx context.Context) (*AndroidAttributes, error)

GetAndroidAttributes returns the AndroidAttributes for the device.

func (*AndroidNearbyDevice) GetDataUsage

func (a *AndroidNearbyDevice) GetDataUsage(ctx context.Context) (DataUsage, error)

GetDataUsage retrieve's the Android device's Nearby Share data usage setting.

func (*AndroidNearbyDevice) GetDeviceName

func (a *AndroidNearbyDevice) GetDeviceName(ctx context.Context) (string, error)

GetDeviceName retrieve's the Android device's display name for Nearby Share.

func (*AndroidNearbyDevice) GetNearbySharingVersion

func (a *AndroidNearbyDevice) GetNearbySharingVersion(ctx context.Context) (string, error)

GetNearbySharingVersion retrieves the Android device's Nearby Sharing version.

func (*AndroidNearbyDevice) GetVisibility

func (a *AndroidNearbyDevice) GetVisibility(ctx context.Context) (Visibility, error)

GetVisibility retrieve's the Android device's Nearby Share visibility setting.

func (*AndroidNearbyDevice) InitUI

func (a *AndroidNearbyDevice) InitUI(ctx context.Context) error

InitUI initializes a UI automator connection to the Android device. Callers should defer CloseUI to free the associated resources.

func (*AndroidNearbyDevice) ReceiveFile

func (a *AndroidNearbyDevice) ReceiveFile(ctx context.Context, senderName, receiverName string, isHighVisibility bool, turnaroundTime time.Duration) error

ReceiveFile starts receiving with a timeout. Sets the AndroidNearbyDevice's transferCallback, which is needed when awaiting follow-up SnippetEvents when calling eventWaitAndGet.

func (*AndroidNearbyDevice) ReconnectToSnippet

func (a *AndroidNearbyDevice) ReconnectToSnippet(ctx context.Context) error

ReconnectToSnippet restarts a connection to the Nearby Snippet on Android device.

func (*AndroidNearbyDevice) SHA256Sum

func (a *AndroidNearbyDevice) SHA256Sum(ctx context.Context, filename string) (string, error)

SHA256Sum computes the sha256sum of the specified file on the Android device.

func (*AndroidNearbyDevice) SendFile

func (a *AndroidNearbyDevice) SendFile(ctx context.Context, senderName, receiverName, shareFileName string, mimetype nearbycommon.MimeType, turnaroundTime time.Duration) error

SendFile starts sending with a timeout. Sets the AndroidNearbyDevice's transferCallback, which is needed when awaiting follow-up SnippetEvents when calling eventWaitAndGet.

func (*AndroidNearbyDevice) SetEnabled

func (a *AndroidNearbyDevice) SetEnabled(ctx context.Context, enabled bool) error

SetEnabled sets Nearby Share enabled.

func (*AndroidNearbyDevice) SetupDevice

func (a *AndroidNearbyDevice) SetupDevice(ctx context.Context, dataUsage DataUsage, visibility Visibility, name string) error

SetupDevice configures the Android device's Nearby Share settings.

func (*AndroidNearbyDevice) StageFile

func (a *AndroidNearbyDevice) StageFile(ctx context.Context, file string) error

StageFile pushes the specified file to the Android device to be used in sending.

func (*AndroidNearbyDevice) Sync

Sync synchronizes contact information and certificates on the Android device. This should be used before attempting to receive a contacts share.

func (*AndroidNearbyDevice) WaitForInContactSenderUI

func (a *AndroidNearbyDevice) WaitForInContactSenderUI(ctx context.Context, sender string, timeout time.Duration) error

WaitForInContactSenderUI waits for the sharing UI that appears when there is an incoming share from a contact.

type DataUsage

type DataUsage int

DataUsage are data usage values for the Nearby Snippet's setupDevice and getDataUsage methods.

const (
	DataUsageOffline DataUsage = iota + 1
	DataUsageOnline
	DataUsageWifiOnly
)

These are the 3 values defined by the Nearby Snippet API.

type MimeType

type MimeType string

MimeType are the mime type values that are accepted by the snippet's sendFile method.

const (
	MimeTypeTextVCard MimeType = "text/x-vcard"
	MimeTypePDF       MimeType = "application/pdf"
	MimeTypeJpeg      MimeType = "image/jpeg"
	MimeTypeMP4       MimeType = "video/mp4"
	MimeTypeTextPlain MimeType = "text/plain"
	MimeTypePng       MimeType = "image/png"
)

MimeTypes supported by the snippet library.

type SnippetEvent

type SnippetEvent string

SnippetEvent are the event names posted by the Nearby Snippet to its event cache after initiating receiving. The host CrOS device can monitor the sharing state by awaiting these events using the Nearby Snippet's eventWaitAndGet RPC.

const (
	// Snippet events when Android is the receiver.
	SnippetEventOnLocalConfirmation SnippetEvent = "onLocalConfirmation"
	SnippetEventOnReceiveStatus     SnippetEvent = "onReceiveStatus"
	// Snippet events when Android is the sender.
	SnippetEventOnReceiverFound          SnippetEvent = "onReceiverFound"
	SnippetEventOnAwaitingReceiverAccept SnippetEvent = "onAwaitingReceiverAccept"
	SnippetEventOnTransferStatus         SnippetEvent = "onTransferStatus"
	// Shared Snippet event when Android is sender and receiver.
	// The onStop event indicates that the transfer is complete and all teardown tasks for Android Nearby are complete.
	SnippetEventOnStop SnippetEvent = "onStop"
)

Event names defined by the Nearby Snippet.

type Visibility

type Visibility int

Visibility are values for the Nearby Snippet's setupDevice and getVisibility methods, corresponding to different contact visibility settings.

const (
	VisibilityUnknown Visibility = iota - 1
	VisibilityNoOne
	VisibilityAllContacts
	VisibilitySelectedContacts
	VisibilityEveryone
)

These are the 5 values defined by the Nearby Snippet API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL