crossdevice

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: 29 Imported by: 0

Documentation

Overview

Package crossdevice is for controlling Cross Device features involving a paired Android phone and Chromebook.

Index

Constants

View Source
const (
	MultideviceSnippetZipName      = "multidevice_snippet.zip"
	MultideviceSnippetApkName      = "multidevice_snippet.apk"
	MultideviceSnippetMoblyPackage = "com.google.android.gmscore.integ.modules.auth.proximity.mobly.snippet"
)

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

View Source
const AccountUtilApk = "GoogleAccountUtil.apk"

AccountUtilApk is the filename for the GoogleAccountUtil APK.

View Source
const AccountUtilZip = "google_account_util.zip"

AccountUtilZip is the filename for the .zip containing the GoogleAccountUtil APK.

View Source
const AndroidPhotosPath = "/sdcard/DCIM/Camera"

AndroidPhotosPath is the directory where photos taken on the device can be located.

View Source
const KeepStateVar = "keepState"

KeepStateVar is the runtime variable name used to specify the chrome.KeepState parameter to preserve the DUT's user accounts.

Variables

View Source
var PhoneIP = testing.RegisterVarString(
	"crossdevice.PhoneIP",
	"",
	"IP address of an Android Phone that has enabled adb-over-tcp",
)

PhoneIP is the address of the adb-over-wifi device to use in Cross device tests.

Functions

func AdbSetup

func AdbSetup(ctx context.Context) (*adb.Device, bool, error)

AdbSetup configures adb and connects to the Android device with adb root if available.

func AddAccount

func AddAccount(ctx context.Context, d *adb.Device, username, password string) error

AddAccount adds the specified Google account to the Android device. Assumes the GoogleAccountUtil APK has already been installed.

func ConfigureDevice

func ConfigureDevice(ctx context.Context, d *adb.Device, rooted bool) error

ConfigureDevice performs basic device preparation. This includes clearing logcat and waking the screen, and if the device is rooted, enabling bluetooth and extending the screen-off timeout.

func EnableVerboseLogging

func EnableVerboseLogging(ctx context.Context, d *adb.Device, rooted bool, tags ...string) error

EnableVerboseLogging enables verbose logging on the Android device for the specified tags, and bluetooth+wifi if the device is rooted.

func GAIALogin

func GAIALogin(ctx context.Context, d *adb.Device, accountUtilZipPath, username, password string) error

GAIALogin removes existing user accounts from the device and adds the specified one using the tradefed GoogleAccountUtil APK. Note that only rooted Android devices can add/remove accounts in this way.

func GetCrosAttributes

func GetCrosAttributes(ctx context.Context, tconn *chrome.TestConn, username string) (*crossdevicecommon.CrosAttributes, error)

GetCrosAttributes gets the Chrome version and combines it into a CrosAttributes strct with the provided values for easy logging with json.MarshalIndent.

func GetLoginCredentials

func GetLoginCredentials(ctx context.Context, s *testing.FixtState, feature Feature) (string, string, error)

GetLoginCredentials returns the correct credentials to use based on the Cross Device feature being tested.

func NewCrossDeviceAndroid

func NewCrossDeviceAndroid(feature Feature) testing.FixtureImpl

NewCrossDeviceAndroid creates a fixture that sets up an Android device for crossdevice feature testing.

func NewCrossDeviceOnboarded

func NewCrossDeviceOnboarded(allFeatures, saveScreenRecording, lockFixture bool) testing.FixtureImpl

NewCrossDeviceOnboarded creates a fixture that logs in to CrOS, pairs it with an Android device, and ensures the features in the "Connected devices" section of OS Settings are ready to use (Smart Lock, Phone Hub, etc.). Note that crossdevice fixtures inherit from crossdeviceAndroidSetup.

func OverrideFeatureFlags

func OverrideFeatureFlags(ctx context.Context, adbDevice *adb.Device, feature Feature) error

OverrideFeatureFlags overrides the required Phenotype flags for the given cross device feature.

func RemoveAccounts

func RemoveAccounts(ctx context.Context, d *adb.Device) error

RemoveAccounts removes accounts from the Android device. Assumes the GoogleAccountUtil APK has already been installed.

Types

type AndroidAttributes

type AndroidAttributes struct {
	User                string
	GMSCoreVersion      int
	AndroidVersion      int
	SDKVersion          int
	ProductName         string
	ModelName           string
	DeviceName          string
	BluetoothMACAddress string
}

AndroidAttributes contains information about the Android device and its settings that are relevant to Cross Device features.

func GetAndroidAttributes

func GetAndroidAttributes(ctx context.Context, adbDevice *adb.Device) (*AndroidAttributes, error)

GetAndroidAttributes returns the AndroidAttributes for the device.

type AndroidDevice

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

AndroidDevice represents an Android device that's been paired with the Chromebook (i.e. from the "Connected devices" section of OS settings). Android control is achieved by making RPCs to the Multidevice Snippet running on the Android device, or by using ADB commands directly.

func NewAndroidDevice

func NewAndroidDevice(ctx context.Context, d *adb.Device, apkZipPath string) (*AndroidDevice, error)

NewAndroidDevice returns an AndroidDevice that can be used to control the Android phone in Cross Device tests. Callers should defer Cleanup to ensure the resources used by the AndroidDevice are freed.

func (*AndroidDevice) BatteryLevel

func (c *AndroidDevice) BatteryLevel(ctx context.Context) (int, error)

BatteryLevel returns the current battery level.

func (*AndroidDevice) Cleanup

func (c *AndroidDevice) Cleanup(ctx context.Context)

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

func (*AndroidDevice) ClearLogcat

func (c *AndroidDevice) ClearLogcat(ctx context.Context) error

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

func (*AndroidDevice) ClearPIN

func (c *AndroidDevice) ClearPIN(ctx context.Context) error

ClearPIN clears a screen lock PIN on Android.

func (*AndroidDevice) DoNotDisturbEnabled

func (c *AndroidDevice) DoNotDisturbEnabled(ctx context.Context) (bool, error)

DoNotDisturbEnabled returns true if Do Not Disturb is enabled, and false if it is disabled.

func (*AndroidDevice) DumpLogs

func (c *AndroidDevice) DumpLogs(ctx context.Context, outDir, filename string) error

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

func (*AndroidDevice) EnableChromeSync

func (c *AndroidDevice) EnableChromeSync(ctx context.Context) error

EnableChromeSync turns on Chrome Sync using the UI.

func (*AndroidDevice) EnablePhoneHubNotifications

func (c *AndroidDevice) EnablePhoneHubNotifications(ctx context.Context) error

EnablePhoneHubNotifications sets the flag on Android to allow Phone Hub to receive notification updates.

func (*AndroidDevice) FileSize

func (c *AndroidDevice) FileSize(ctx context.Context, filename string) (int64, error)

FileSize returns the size of the specified file in bytes. Returns an error if the file does not exist.

func (*AndroidDevice) FindMyPhoneActive

func (c *AndroidDevice) FindMyPhoneActive(ctx context.Context) (bool, error)

FindMyPhoneActive returns true if the "Find my phone" alarm is ringing.

func (*AndroidDevice) GenerateMessageNotification

func (c *AndroidDevice) GenerateMessageNotification(ctx context.Context, id int, title, text string) (func(context.Context) (string, error), error)

GenerateMessageNotification creates a message notification on the phone. The notification has inline reply enabled, so it can be used to test Phone Hub's notification features. The notification title and message text can be specified by the inputs. You can create multiple distinct notifications by calling this with different notification IDs. The returned function will retrieve the reply to the notification.

func (*AndroidDevice) GetAndroidAttributes

func (c *AndroidDevice) GetAndroidAttributes(ctx context.Context) (*AndroidAttributes, error)

GetAndroidAttributes returns the AndroidAttributes for the device.

func (*AndroidDevice) GetMostRecentPhoto

func (c *AndroidDevice) GetMostRecentPhoto(ctx context.Context) (string, error)

GetMostRecentPhoto returns the file name of the most recent photo taken on the device. Returns an empty string if there's no photo on the device.

func (*AndroidDevice) LaunchChrome

func (c *AndroidDevice) LaunchChrome(ctx context.Context) error

LaunchChrome launches Chrome on the Android device.

func (*AndroidDevice) LaunchChromeAtURL

func (c *AndroidDevice) LaunchChromeAtURL(ctx context.Context, url string) error

LaunchChromeAtURL opens the specified URL in Chrome.

func (*AndroidDevice) Pair

func (c *AndroidDevice) Pair(ctx context.Context) error

Pair pairs the Android device to nearby Chromebooks signed in with the same GAIA account. This will cause the phone to be listed under the "Connected devices" section of OS settings, allowing use of Cross Device features (Smart Lock, Phone Hub, etc.) on the Chromebook. Calling this function effectively bypasses the crossdevice onboarding flow that is triggered from OOBE or OS settings. One notable difference is unlike the normal onboarding flow, not all features in the "Connected devices" page will be enabled by default. Some (Phone Hub, WiFi Sync) may need to be toggled on after calling Pair.

func (*AndroidDevice) ReconnectToSnippet

func (c *AndroidDevice) ReconnectToSnippet(ctx context.Context) error

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

func (*AndroidDevice) RemoveMediaFile

func (c *AndroidDevice) RemoveMediaFile(ctx context.Context, filePath string) error

RemoveMediaFile removes the media file specified by filePath from the Android device's storage and media gallery.

func (*AndroidDevice) SHA256Sum

func (c *AndroidDevice) SHA256Sum(ctx context.Context, filename string) (string, error)

SHA256Sum returns the sha256sum of the specified file as a string.

func (*AndroidDevice) SetPIN

func (c *AndroidDevice) SetPIN(ctx context.Context) error

SetPIN sets a screen lock PIN on Android.

func (*AndroidDevice) StartScreenRecording

func (c *AndroidDevice) StartScreenRecording(ctx context.Context, filename, outDir string) (func(context.Context, func() bool) error, error)

StartScreenRecording starts screen recording on the Android device. Defer the returned function to save the recording and clean up on the Android side.

func (*AndroidDevice) TakePhoto

func (c *AndroidDevice) TakePhoto(ctx context.Context) (string, error)

TakePhoto takes a photo with Camera app and returns the name of the new photo taken.

func (*AndroidDevice) ToggleDoNotDisturb

func (c *AndroidDevice) ToggleDoNotDisturb(ctx context.Context, enable bool) error

ToggleDoNotDisturb toggles the Do Not Disturb setting on the Android device.

func (*AndroidDevice) ToggleScreen

func (c *AndroidDevice) ToggleScreen(ctx context.Context) error

ToggleScreen turns the screen off and back on again. This can also be used to easily disable the loud "Find my phone" ringer in case we fail to do so from the UI.

func (*AndroidDevice) TurnOnRecentPhotosFeature

func (c *AndroidDevice) TurnOnRecentPhotosFeature(ctx context.Context) error

TurnOnRecentPhotosFeature enables the recent photos feature through the phone side set up dialog.

func (*AndroidDevice) WaitForDoNotDisturb

func (c *AndroidDevice) WaitForDoNotDisturb(ctx context.Context, enabled bool, timeout time.Duration) error

WaitForDoNotDisturb waits for Do Not Disturb to be enabled/disabled.

func (*AndroidDevice) WaitForFindMyPhone

func (c *AndroidDevice) WaitForFindMyPhone(ctx context.Context, active bool, timeout time.Duration) error

WaitForFindMyPhone waits for "Find my phone" to be on/off.

type Feature

type Feature struct {
	Name       FeatureName
	SubFeature SubFeature
}

Feature defines the Cross Device feature we are testing.

type FeatureName

type FeatureName int

FeatureName is the name of the Cross Device feature to test.

const (
	// SmartLock defines Smart Lock
	SmartLock FeatureName = iota
	// PhoneHub defines Phone Hub
	PhoneHub
	// NearbyShare defines Nearby Share
	NearbyShare
	// Exo defines Exo
	Exo
)

type FixtData

type FixtData struct {
	// Chrome is the running chrome instance.
	Chrome *chrome.Chrome

	// TestConn is a connection to the test extension.
	TestConn *chrome.TestConn

	// Connection to the lock screen test extension.
	LoginConn *chrome.TestConn

	// AndroidDevice is an object for interacting with the connected Android device's Multidevice Snippet.
	AndroidDevice *AndroidDevice

	// The credentials to be used on both chromebook and phone.
	Username string
	Password string

	// The options used to start Chrome sessions.
	ChromeOptions []chrome.Option
}

FixtData holds information made available to tests that specify this Fixture.

type SubFeature

type SubFeature int

SubFeature is the specific part of a feature we are testing.

const (
	// SmartLockUnlock defines unlocking with Smart Lock
	SmartLockUnlock SubFeature = iota
	// SmartLockLogin defines logging in with Smart Lock
	SmartLockLogin
)

Directories

Path Synopsis
Package phonehub is for controlling Chrome OS Phone Hub functionality.
Package phonehub is for controlling Chrome OS Phone Hub functionality.
Package smartlock is for controlling ChromeOS Smart Lock functionality.
Package smartlock is for controlling ChromeOS Smart Lock functionality.

Jump to

Keyboard shortcuts

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