arc

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

Documentation

Overview

Package arc supports interacting with the ARC framework, which is used to run Android applications on Chrome OS.

Index

Constants

View Source
const (
	// BorderTop is the top border.
	BorderTop BorderType = 1 << 0
	// BorderBottom is the bottom border.
	BorderBottom = 1 << 1
	// BorderLeft is the left border.
	BorderLeft = 1 << 2
	// BorderRight is the right border.
	BorderRight = 1 << 3
	// BorderTopLeft is the top-left corner.
	BorderTopLeft = (BorderTop | BorderLeft)
	// BorderTopRight is the top-right corner.
	BorderTopRight = (BorderTop | BorderRight)
	// BorderBottomLeft is the bottom-left corner.
	BorderBottomLeft = (BorderBottom | BorderLeft)
	// BorderBottomRight is the bottom-right corner.
	BorderBottomRight = (BorderBottom | BorderRight)
)
View Source
const (
	// BootTimeout is the maximum amount of time that ARC is expected to take to boot.
	// Tests that call New should declare a timeout that's at least this long.
	BootTimeout = 120 * time.Second

	//ARCPath is the path where the container images are installed in the rootfs.
	ARCPath = "/opt/google/containers/android"
	//ARCVMPath is the pather where the VM images are installed in the rootfs.
	ARCVMPath = "/opt/google/vms/android"
)
View Source
const (
	// DefaultDisplayID represents the display ID for the internal display.
	DefaultDisplayID = 0
	// CaptionHeightR represents the caption height in ChromeDP which is defined in ArcSystemUIConstants.
	// TODO: Replace hard code caption height by getting from ash.
	CaptionHeightR = 32
	// DefaultDensityDPI is equal to DisplayMetrics#DENSITY_DEFAULT, and corresponds to a density of 1.0.
	// See: https://developer.android.com/reference/android/util/DisplayMetrics#DENSITY_DEFAULT
	DefaultDensityDPI = 160
)
View Source
const (
	// VethPrefix is a prefix for host veth interfaces name.
	VethPrefix = "veth_"
	// BridgePrefix is a prefix for host bridge interfaces name.
	BridgePrefix = "arc_"
	// VmtapPrefix is a prefix for host vmtap interfaces name.
	VmtapPrefix = "vmtap"

	// ARCBR0 refers to a host network bridge interface named arcbr0.
	ARCBR0 = "arcbr0"
	// ARC0 refers to an ARC network interface named arc0.
	ARC0 = "arc0"
	// ARC1 refers to an ARC network interface named arc1 which is created for ARCVM.
	// On dual-boards, ARC++ might have this interface as a result of switching ARCVM -> ARC++.
	// ARC++ should not care about this interface.
	ARC1 = "arc1"
	// Loopback refers to loopback interface named lo.
	Loopback = "lo"
)
View Source
const (
	// SDKN is the SDK version of Android N.
	SDKN = 25

	// SDKP is the SDK version of Android P.
	SDKP = 28

	// SDKQ is the SDK version of Android Q.
	SDKQ = 29

	// SDKR is the SDK version of Android R.
	SDKR = 30

	// SDKS is the SDK version of Android S v2, which is the S version of ARC.
	SDKS = 32
)
View Source
const (
	// RemovableMediaUUID is the (fake) UUID of the removable media volume for
	// testing. It is defined in
	// Chromium's components/arc/volume_mounter/arc_volume_mounter_bridge.cc.
	RemovableMediaUUID = "00000000000000000000000000000000DEADBEEF"

	// MyFilesUUID is the UUID of the ARC MyFiles volume. It is defined in
	// Chromium's components/arc/volume_mounter/arc_volume_mounter_bridge.cc.
	MyFilesUUID = "0000000000000000000000000000CAFEF00D2019"

	// VolumeProviderContentURIPrefix is the prefix of the URIs of files served by
	// ArcVolumeProvider.
	VolumeProviderContentURIPrefix = "content://org.chromium.arc.volumeprovider/"
)
View Source
const PostTestTimeout = resetTimeout + 20*time.Second

PostTestTimeout is the timeout duration to save logs after each test. It's intentionally set longer than resetTimeout because dumping 'dumpsys' takes around 20 seconds.

View Source
const TestBinaryDirPath = "/usr/local/libexec/arc-binary-tests"

TestBinaryDirPath is the directory to store test binaries which run inside ARC.

Variables

This section is empty.

Functions

func APKPath

func APKPath(value string) string

APKPath returns the absolute path to a helper APK.

func AndroidDataDir

func AndroidDataDir(ctx context.Context, user string) (string, error)

AndroidDataDir returns the ChromeOS path from which /data/ can be accessed (/home/root/${USER_HASH}/android-data).

func AppendToArcvmDevConf

func AppendToArcvmDevConf(ctx context.Context, text string) error

AppendToArcvmDevConf appends the string to the arcvm_dev.conf on ARCVM devices. Useful for modifying crosvm flags. Backs up the original content to arcvm_dev.conf.tast-backup which should later be restored with RestoreArcvmDevConf. Care should be taken to only write or append to the config once during a test run (either from the test itself or from the fixture) to avoid overwriting the backup config file.

func BlockOutbound

func BlockOutbound(ctx context.Context) error

BlockOutbound blocks all outbound traffic from ARC.

func Booted

func Booted() testing.Precondition

Booted returns a precondition that ARC Container has already booted when a test is run.

When adding a test, the testing.Test.Pre field may be set to the value returned by this function. Later, in the main test function, the value returned by testing.State.PreValue may be converted to a PreData containing already-initialized chrome.Chrome and ARC objects:

func DoSomething(ctx context.Context, s *testing.State) {
	d := s.PreValue().(arc.PreData)
	conn, err := d.Chrome.NewConn(ctx, "http://www.example.org/")
	...
	cmd := d.ARC.Command(ctx, "dumpsys", "window", "displays")
	...
}

When using this precondition, tests cannot call New or chrome.New. The Chrome and ARC instances are also shared and cannot be closed by tests.

func BootstrapCommand

func BootstrapCommand(ctx context.Context, name string, arg ...string) *testexec.Cmd

BootstrapCommand runs a command with android-sh.

It is very rare you want to call this function from your test; call Command instead. A valid use case would to run commands in the Android mini container, to set up adb, etc.

This function should be called only after WaitAndroidInit returns successfully. Please keep in mind that command execution environment of android-sh is not exactly the same as the actual Android container.

func CheckNoDex2Oat

func CheckNoDex2Oat(outDir string) error

CheckNoDex2Oat verifies whether ARC is pre-optimized and no dex2oat was previously running in the background.

func ClickAddAccountInSettings

func ClickAddAccountInSettings(ctx context.Context, arcDevice *androidui.Device, tconn *chrome.TestConn) error

ClickAddAccountInSettings clicks Add account > Google in ARC Settings. Settings window should be already open.

func DisableSyncFlags

func DisableSyncFlags() []string

DisableSyncFlags is the default flags for disabling ARC content sync and background activities when using GAIA accounts. --arc-disable-app-sync - prevents syncing installed apps from the previous sessions. --arc-disable-play-auto-install - disables PAI flow that downloads and installs apps in the background. --arc-play-store-auto-update=off - prevents Play Store and GMS Core from third party app update and prevents self-updates and downloadable content. --arc-disable-locale-sync - don’t propagate locale sync for the account that might cause reconfiguration updates. --arc-disable-media-store-maintenance - disables GMS scheduling of media store periodic indexing and corpora maintenance tasks.

func FirstDisplayIDByType

func FirstDisplayIDByType(ctx context.Context, a *ARC, displayType DisplayType) (int, error)

FirstDisplayIDByType returns first ARC display id for specific display type.

func InitExists

func InitExists() (bool, error)

InitExists returns true in case ARC init process exists.

func InitPID

func InitPID() (int32, error)

InitPID returns the PID (outside the guest) of the ARC init process. It returns an error in case process is not found.

func Lock

func Lock()

Lock sets a flag that makes New and Close fail unconditionally. Preconditions and fixtures should call this function on setup to prevent tests from invalidating an ARC object by a mistake.

func MyFilesVolumeID

func MyFilesVolumeID(ctx context.Context, a *ARC) (string, error)

MyFilesVolumeID returns the volume ID of the MyFiles volume. It waits for the volume to be mounted if it is not mounted yet.

func NetworkInterfaceNames

func NetworkInterfaceNames(ctx context.Context) ([]string, error)

NetworkInterfaceNames filters Android interfaces and returns ARC related network interfaces.

func NewArcBootedFixture

func NewArcBootedFixture(fOpts chrome.OptionsCallback) testing.FixtureImpl

NewArcBootedFixture returns a FixtureImpl with a OptionsCallback function provided. ARCEnabled() will always be added to the Chrome options returned by OptionsCallback.

func NewArcBootedWithConfigFixture

func NewArcBootedWithConfigFixture(fOpts chrome.OptionsCallback, arcvmConfig string) testing.FixtureImpl

NewArcBootedWithConfigFixture returns a FixtureImpl with a OptionsCallback function provided and the specified config appended to arcvm_dev.conf. ARCEnabled() will always be added to the Chrome options returned by OptionsCallback.

func NewArcBootedWithParentChromeFixture

func NewArcBootedWithParentChromeFixture() testing.FixtureImpl

NewArcBootedWithParentChromeFixture returns a FixtureImpl that gets Chrome from a parent fixture.

func NewArcBootedWithPlayStoreFixture

func NewArcBootedWithPlayStoreFixture(fOpts chrome.OptionsCallback) testing.FixtureImpl

NewArcBootedWithPlayStoreFixture returns a FixtureImpl with a OptionsCallback function provided. ARCSupported() will always be added to the Chrome options returned by OptionsCallback.

func NewArcBootedWithoutUIAutomatorFixture

func NewArcBootedWithoutUIAutomatorFixture(fOpts chrome.OptionsCallback) testing.FixtureImpl

NewArcBootedWithoutUIAutomatorFixture is same as NewArcBootedFixture but does not install UIAutomator by default.

func NewMtbfArcBootedFixture

func NewMtbfArcBootedFixture(fOpts chrome.OptionsCallback) testing.FixtureImpl

NewMtbfArcBootedFixture returns a FixtureImpl with a OptionsCallback function provided for MTBF ARC++ tests.

func NewPrecondition

func NewPrecondition(name string, gaia *GaiaVars, gaiaPool *GaiaLoginPoolVars, oDirect bool, extraArgs ...string) testing.Precondition

NewPrecondition creates a new arc precondition for tests that need different args.

func OpenPlayStoreAccountSettings

func OpenPlayStoreAccountSettings(ctx context.Context, arcDevice *androidui.Device, tconn *chrome.TestConn) error

OpenPlayStoreAccountSettings opens account settings in PlayStore where user can switch between available accounts.

func PkgDataDir

func PkgDataDir(ctx context.Context, user, pkg string) (string, error)

PkgDataDir returns the ChromeOS path of the directory that contains user files of a given Android package (/home/root/${USER_HASH}/android-data/data/media/0/Android/data/${PKG}).

func PkgFileSize

func PkgFileSize(ctx context.Context, user, pkg, filename string) (int64, error)

PkgFileSize returns the size of a specified file that belongs to a specified Android package in bytes. Returns an error if the file does not exist.

func RegexpPred

func RegexpPred(exp *regexp.Regexp) func(string) bool

RegexpPred returns a function to be passed to WaitForLogcat that returns true if a given regexp is matched in that line.

func RestoreArcvmDevConf

func RestoreArcvmDevConf(ctx context.Context) error

RestoreArcvmDevConf restores the original arcvm_dev.conf from the backup copy set aside by WriteArcvmDevConf.

func SDCardVolumeID

func SDCardVolumeID(ctx context.Context, a *ARC) (string, error)

SDCardVolumeID returns the volume ID of the sdcard volume (/storage/emulated/0). Although the volume ID itself is a constant, the function waits for the volume to be mounted if it is not mounted yet, so that the ID is guaranteed to be valid and usable inside ARC.

func SDKVersion

func SDKVersion() (int, error)

SDKVersion returns the ARC's Android SDK version for the current ARC image installed into the DUT.

func Supported

func Supported() bool

Supported returns true if ARC is supported on the board.

This function must not be used to skip tests entirely; declare the "android_p" software dependency instead. A valid use case would be to change the test expectation by whether ARC is supported or not (e.g. existence of mount points).

func SwitchPlayStoreAccount

func SwitchPlayStoreAccount(ctx context.Context, arcDevice *androidui.Device, tconn *chrome.TestConn, accountEmail string) error

SwitchPlayStoreAccount switches between the ARC account in PlayStore.

func UnblockOutbound

func UnblockOutbound(ctx context.Context) error

UnblockOutbound unblocks all outbound traffic from ARC.

func Unlock

func Unlock()

Unlock resets the flag set by lock.

func VMEnabled

func VMEnabled() (bool, error)

VMEnabled returns true if Chrome OS is running ARCVM.

func WaitAndroidInit

func WaitAndroidInit(ctx context.Context, reader *syslog.Reader) error

WaitAndroidInit waits for Android init process to start.

It is very rare you want to call this function from your test; to wait for the Android system to start and become ready, call New instead. A valid use case is when you want to interact with Android mini container.

It is fine to call BootstrapCommand after this function successfully returns.

func WaitForARCMyFilesVolumeMount

func WaitForARCMyFilesVolumeMount(ctx context.Context, a *ARC) error

WaitForARCMyFilesVolumeMount waits for the MyFiles volume to be mounted inside ARC.

func WaitForARCMyFilesVolumeMountIfARCVMEnabled

func WaitForARCMyFilesVolumeMountIfARCVMEnabled(ctx context.Context, a *ARC) error

WaitForARCMyFilesVolumeMountIfARCVMEnabled waits for the MyFiles volume to be mounted inside ARC only if ARCVM is enabled. Otherwise it just returns nil. This can be used in tests that write to or read from ARC's Download folder, because Downloads integraion in ARCVM depends on MyFiles mount.

func WaitForARCMyFilesVolumeUnmount

func WaitForARCMyFilesVolumeUnmount(ctx context.Context, a *ARC) error

WaitForARCMyFilesVolumeUnmount waits for the MyFiles volume to be unmounted inside ARC.

func WaitForARCRemovableMediaVolumeMount

func WaitForARCRemovableMediaVolumeMount(ctx context.Context, a *ARC) error

WaitForARCRemovableMediaVolumeMount waits for the removable media volume for testing to be mounted inside ARC.

func WaitForARCRemovableMediaVolumeUnmount

func WaitForARCRemovableMediaVolumeUnmount(ctx context.Context, a *ARC) error

WaitForARCRemovableMediaVolumeUnmount waits for the removable media volume for testing to be unmounted inside ARC.

func WaitForARCSDCardVolumeMount

func WaitForARCSDCardVolumeMount(ctx context.Context, a *ARC) error

WaitForARCSDCardVolumeMount waits for the sdcard volume to be mounted inside ARC.

func WaitForARCSDCardVolumeUnmount

func WaitForARCSDCardVolumeUnmount(ctx context.Context, a *ARC) error

WaitForARCSDCardVolumeUnmount waits for the sdcard volume to be unmounted inside ARC.

func WriteArcvmDevConf

func WriteArcvmDevConf(ctx context.Context, text string) error

WriteArcvmDevConf writes string to arcvm_dev.conf on ARCVM devices. Useful for modifying flags for crosvm start up. Backs up original content to arcvm_dev.conf.tast-backup which should later be restored with RestoreArcvmDevConf. Care should be taken to only write or append to the config once during a test run (either from the test itself or from the fixture) to avoid overwriting the backup config file.

Types

type ARC

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

ARC holds resources related to an active ARC session. Call Close to release those resources.

func New

func New(ctx context.Context, outDir string) (*ARC, error)

New waits for Android to finish booting.

ARC must be enabled in advance by passing chrome.ARCEnabled or chrome.ARCSupported with real user gaia login to chrome.New.

After this function returns successfully, you can assume BOOT_COMPLETED intent has been broadcast from Android system, and ADB connection is ready. Note that this does not necessarily mean all ARC mojo services are up; call WaitIntentHelper() to wait for ArcIntentHelper to be ready, for example.

The returned ARC instance must be closed when the test is finished.

func NewWithSyslogReader

func NewWithSyslogReader(ctx context.Context, outDir string, reader *syslog.Reader) (*ARC, error)

NewWithSyslogReader waits for Android to finish booting.

Give a syslog.Reader instantiated before chrome.New to allow diagnosing init failure.

func NewWithTimeout

func NewWithTimeout(ctx context.Context, outDir string, timeout time.Duration) (*ARC, error)

NewWithTimeout waits for Android to finish booting until timeout expires.

ARC must be enabled in advance by passing chrome.ARCEnabled or chrome.ARCSupported with real user gaia login to chrome.New.

After this function returns successfully, you can assume BOOT_COMPLETED intent has been broadcast from Android system, and ADB connection is ready. Note that this does not necessarily mean all ARC mojo services are up; call WaitIntentHelper() to wait for ArcIntentHelper to be ready, for example.

The returned ARC instance must be closed when the test is finished.

func (*ARC) BroadcastIntent

func (a *ARC) BroadcastIntent(ctx context.Context, action string, params ...string) (*adb.BroadcastResult, error)

BroadcastIntent broadcasts an intent with "am broadcast" and returns the result.

func (*ARC) BroadcastIntentGetData

func (a *ARC) BroadcastIntentGetData(ctx context.Context, action string, params ...string) (string, error)

BroadcastIntentGetData broadcasts an intent with "am broadcast" and returns the result data.

func (*ARC) BugReport

func (a *ARC) BugReport(ctx context.Context, path string) error

BugReport returns bugreport of the device.

func (*ARC) Close

func (a *ARC) Close(ctx context.Context) error

Close releases testing-related resources associated with ARC. ARC itself is not stopped.

func (*ARC) Command

func (a *ARC) Command(ctx context.Context, name string, args ...string) *testexec.Cmd

Command returns a command in Android via adb.

func (*ARC) DumpUIHierarchyOnError

func (a *ARC) DumpUIHierarchyOnError(ctx context.Context, outDir string, hasError func() bool) error

DumpUIHierarchyOnError dumps arc UI hierarchy to 'arc_uidump.xml', when the test fails. Call this function after closing arc UI devices. Otherwise the uiautomator might exist with errors like status 137.

func (*ARC) FileSize

func (a *ARC) 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. Note: In contrast to PkgFileSize, FileSize accesses files via adb commands.

func (*ARC) GetProp

func (a *ARC) GetProp(ctx context.Context, key string) (string, error)

GetProp returns the Android system property indicated by the specified key.

func (*ARC) Install

func (a *ARC) Install(ctx context.Context, path string, installOptions ...adb.InstallOption) error

Install installs an APK file to the Android system. By default, it uses InstallOptionReplaceApp and InstallOptionAllowVersionDowngrade.

func (*ARC) InstallMultiple

func (a *ARC) InstallMultiple(ctx context.Context, apks []string, installOptions ...adb.InstallOption) error

InstallMultiple installs a split APK to the Android system. By default, it uses InstallOptionReplaceApp and InstallOptionAllowVersionDowngrade.

func (*ARC) InstalledPackages

func (a *ARC) InstalledPackages(ctx context.Context) (map[string]struct{}, error)

InstalledPackages returns a set of currently-installed packages, e.g. "android". This operation is slow (700+ ms), so unnecessary calls should be avoided.

func (*ARC) IsConnected

func (a *ARC) IsConnected(ctx context.Context) error

IsConnected checks if ARC is connected through ADB.

func (*ARC) NewUIDevice

func (a *ARC) NewUIDevice(ctx context.Context) (*ui.Device, error)

NewUIDevice creates a Device object by starting and connecting to UI Automator server. Close must be called to clean up resources when a test is over.

func (*ARC) PackageInstalled

func (a *ARC) PackageInstalled(ctx context.Context, pkg string) (bool, error)

PackageInstalled returns true if the given package has been installed.

func (*ARC) PullFile

func (a *ARC) PullFile(ctx context.Context, src, dst string) error

PullFile copies a file in Android to Chrome OS with adb pull.

func (*ARC) PushFile

func (a *ARC) PushFile(ctx context.Context, src, dst string) error

PushFile copies a file in Chrome OS to Android with adb push.

func (*ARC) PushFileToTmpDir

func (a *ARC) PushFileToTmpDir(ctx context.Context, src string) (string, error)

PushFileToTmpDir copies a file in Chrome OS to Android temp directory. The destination path within the ARC container is returned.

func (*ARC) ReadFile

func (a *ARC) ReadFile(ctx context.Context, filename string) ([]byte, error)

ReadFile reads a file in Android file system with adb pull.

func (*ARC) RemoveAll

func (a *ARC) RemoveAll(ctx context.Context, path string) error

RemoveAll removes all files and directories under the path in Android. The path must be abspath.

func (*ARC) RemoveReverseTCP

func (a *ARC) RemoveReverseTCP(ctx context.Context, androidPort int) error

RemoveReverseTCP removes the forwarding from a host port to the specified ADB device local port.

func (*ARC) ResetOutDir

func (a *ARC) ResetOutDir(ctx context.Context, outDir string) error

ResetOutDir updates the outDir field of ARC object.

func (*ARC) ReverseTCP

func (a *ARC) ReverseTCP(ctx context.Context, hostPort int) (int, error)

ReverseTCP forwards the host port to an ADB device local port and returns that ADB device port.

func (*ARC) SaveLogFiles

func (a *ARC) SaveLogFiles(ctx context.Context) error

SaveLogFiles writes log files to the a.outDir directory and clears the a.outDir.

func (*ARC) SendIntentCommand

func (a *ARC) SendIntentCommand(ctx context.Context, action, data string) *testexec.Cmd

SendIntentCommand returns a Cmd to send an intent with "am start" command.

func (*ARC) TaskInfosFromDumpsys

func (a *ARC) TaskInfosFromDumpsys(ctx context.Context) ([]TaskInfo, error)

TaskInfosFromDumpsys returns a list of all available TaskInfo from the "dumpsys activity activities" and "dumpsys Wayland" if needed.

func (*ARC) TempDir

func (a *ARC) TempDir(ctx context.Context) (string, error)

TempDir creates a temporary directory under AndroidTmpDirPath in Android, then returns its absolute path. It is caller's responsibility to remove all the contents in the directory after its use. One of the typical use cases will be as follows:

tmpdir, err := a.MktempDir(ctx)
if err != nil {
  ... // error handling
}
defer a.RemoveAll(tmpdir)
... // Main code using tmpdir.

func (*ARC) Uninstall

func (a *ARC) Uninstall(ctx context.Context, pkg string) error

Uninstall uninstalls a package from the Android system.

func (*ARC) WaitForLogcat

func (a *ARC) WaitForLogcat(ctx context.Context, pred func(string) bool, quitFunc ...func() bool) error

WaitForLogcat keeps scanning logcat. The function pred is called on the logcat contents line by line. This function returns successfully if pred returns true. If pred never returns true, this function returns an error as soon as the context is done. An optional quitFunc will be polled at regular interval, which can be used to break early if for example the activity which is supposed to print the exp has crashed

func (*ARC) WaitForPackages

func (a *ARC) WaitForPackages(ctx context.Context, packages []string) error

WaitForPackages waits for Android packages being installed.

func (*ARC) WaitIntentHelper

func (a *ARC) WaitIntentHelper(ctx context.Context) error

WaitIntentHelper waits for ArcIntentHelper to get ready.

func (*ARC) WriteFile

func (a *ARC) WriteFile(ctx context.Context, filename string, data []byte) error

WriteFile writes to a file in Android file system with adb push.

type Activity

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

Activity holds resources associated with an ARC activity.

func NewActivity

func NewActivity(a *ARC, pkgName, activityName string) (*Activity, error)

NewActivity returns a new Activity instance. The caller is responsible for closing a. Returned Activity instance must be closed when the test is finished.

func NewActivityOnDisplay

func NewActivityOnDisplay(a *ARC, pkgName, activityName string, displayID int) (*Activity, error)

NewActivityOnDisplay returns a new Activity instance on specific display. The caller is responsible for closing a. Returned Activity instance must be closed when the test is finished.

func (*Activity) ActivityName

func (ac *Activity) ActivityName() string

ActivityName returns the activity name.

func (*Activity) CaptionHeight

func (ac *Activity) CaptionHeight(ctx context.Context) (int, error)

CaptionHeight returns the caption height of the activity.

func (*Activity) Close

func (ac *Activity) Close()

Close closes the resources associated with the Activity instance. Calling Close() does not stop the activity.

func (*Activity) DisplayDensity

func (ac *Activity) DisplayDensity(ctx context.Context) (float64, error)

DisplayDensity returns the density of activity's physical display.

func (*Activity) DisplaySize

func (ac *Activity) DisplaySize(ctx context.Context) (s coords.Size, err error)

DisplaySize returns the size of display associated with the activity.

func (*Activity) Focus

func (ac *Activity) Focus(ctx context.Context, tconn *chrome.TestConn) error

Focus focuses the activity.

func (*Activity) Focused

func (ac *Activity) Focused(ctx context.Context) (bool, error)

Focused returns whether the app's window has focus or not. Only works on ARC++ R and later.

func (*Activity) GetWindowState

func (ac *Activity) GetWindowState(ctx context.Context) (WindowState, error)

GetWindowState returns the window state.

func (*Activity) IsRunning

func (ac *Activity) IsRunning(ctx context.Context) (bool, error)

IsRunning returns true if the activity is running, false otherwise.

func (*Activity) MoveWindow

func (ac *Activity) MoveWindow(ctx context.Context, tconn *chrome.TestConn, t time.Duration, toBounds, fromBounds coords.Rect) error

MoveWindow moves the activity's window to a new location. t represents the duration of the movement. toBounds represent the destination bounds (in px). fromBounds represent the source bounds (in px).

func (*Activity) PackageName

func (ac *Activity) PackageName() string

PackageName returns the activity package name.

func (*Activity) PackageResizable

func (ac *Activity) PackageResizable(ctx context.Context) (bool, error)

PackageResizable returns the window resizability of an app package name.

func (*Activity) Resizable

func (ac *Activity) Resizable(ctx context.Context) (bool, error)

Resizable returns the window resizability.

func (*Activity) ResizeWindow

func (ac *Activity) ResizeWindow(ctx context.Context, tconn *chrome.TestConn, border BorderType, to coords.Point, t time.Duration) error

ResizeWindow resizes the activity's window. border represents from where the resize should start. to represents the coordinates for for the new border's position, in pixels. t represents the duration of the resize. ResizeWindow only works with WindowStateNormal and WindowStatePIP windows. Will fail otherwise. For PiP windows, they must have the PiP Menu Activity displayed. Will fail otherwise.

func (*Activity) SetWindowState

func (ac *Activity) SetWindowState(ctx context.Context, tconn *chrome.TestConn, state WindowState) error

SetWindowState sets the window state. Note this method is async, so ensure to call ash.WaitForArcAppWindowState after this. Supported states: WindowStateNormal, WindowStateMaximized, WindowStateFullscreen, WindowStateMinimized

func (*Activity) Start

func (ac *Activity) Start(ctx context.Context, tconn *chrome.TestConn, opts ...ActivityStartOption) error

Start starts the activity by invoking "am start". Activity start options can be passed in to affect with arguments that are run with the command.

func (*Activity) StartWithDefaultOptions

func (ac *Activity) StartWithDefaultOptions(ctx context.Context, tconn *chrome.TestConn) error

StartWithDefaultOptions starts the activity by invoking "am start" with default options passed.

func (*Activity) Stop

func (ac *Activity) Stop(ctx context.Context, tconn *chrome.TestConn) error

Stop stops the activity by invoking "am force-stop" with the package name. If there are multiple activities that belong to the same package name, all of them will be stopped.

func (*Activity) SurfaceBounds

func (ac *Activity) SurfaceBounds(ctx context.Context) (coords.Rect, error)

SurfaceBounds returns the surface bounds in pixels. A surface represents the buffer used to store the window content. This is the buffer used by SurfaceFlinger and Wayland. The surface bounds might be smaller than the window bounds since the surface does not include the caption. And does not include the shelf size if the activity is fullscreen/maximized and the shelf is in "always show" mode. See: WindowBounds

func (*Activity) WaitForFinished

func (ac *Activity) WaitForFinished(ctx context.Context, timeout time.Duration) error

WaitForFinished waits till all the activities beloninging to this task are inactive. Active means anywhere between activity launched and activity shut down in the activity lifecycle. This function cannot tell if the activity was launched at all.

Activity lifecycle: https://developer.android.com/guide/components/activities/activity-lifecycle#alc

func (*Activity) WindowBounds

func (ac *Activity) WindowBounds(ctx context.Context) (coords.Rect, error)

WindowBounds returns the window bounding box of the activity in pixels. The caption bounds, in case it is present, is included as part of the window bounds. This is the same size as the one reported by Chrome/Aura. See: SurfaceBounds

type ActivityInfo

type ActivityInfo struct {
	// PackageName is the package name.
	PackageName string
	// ActivityName is the name of the activity.
	ActivityName string
}

ActivityInfo contains the information found in ActivityRecord

type ActivityStartOption

type ActivityStartOption func(*activityStartCmdBuilder)

ActivityStartOption is a function that sets a start command flag on a start command builder passed to it.

func WithActivityType

func WithActivityType(activityType ActivityType) ActivityStartOption

WithActivityType sets the activity type of the activity.

func WithDataURI

func WithDataURI(dataURI string) ActivityStartOption

WithDataURI sets a data URI where data can be written to about the activity.

func WithDisplayID

func WithDisplayID(dispID int) ActivityStartOption

WithDisplayID sets the display ID for the activity.

func WithEnableDebugging

func WithEnableDebugging() ActivityStartOption

WithEnableDebugging enables debugging for an activity.

func WithEnableNativeDebugging

func WithEnableNativeDebugging() ActivityStartOption

WithEnableNativeDebugging enables native debugging for an activity.

func WithExtraBool

func WithExtraBool(key string, val bool) ActivityStartOption

WithExtraBool adds an extra bool to the activity which can provide extra information.

func WithExtraInt

func WithExtraInt(key string, val int) ActivityStartOption

WithExtraInt adds an extra int to the activity which can provide extra information.

func WithExtraIntUint64

func WithExtraIntUint64(key string, val uint64) ActivityStartOption

WithExtraIntUint64 adds an extra unint64 value converted to an int (since the activity manager can only hand signed 64-bit ints anyway) to the activity.

func WithExtraString

func WithExtraString(key, val string) ActivityStartOption

WithExtraString adds an extra string to the activity which can provide extra information.

func WithExtraStringArray

func WithExtraStringArray(key string, vals []string) ActivityStartOption

WithExtraStringArray adds an extra string array to the activity which can provide extra information.

func WithForceStop

func WithForceStop() ActivityStartOption

WithForceStop forces an activity to stop before a new one of the same name is started.

func WithIntentAction

func WithIntentAction(intentAction string) ActivityStartOption

WithIntentAction sets an intent action for this activity.

func WithUser

func WithUser(user string) ActivityStartOption

WithUser sets the user of the activity.

func WithWaitForLaunch

func WithWaitForLaunch() ActivityStartOption

WithWaitForLaunch waits for the launch of the activity before ending am process.

func WithWindowingMode

func WithWindowingMode(windowingMode WindowingMode) ActivityStartOption

WithWindowingMode sets the windowing mode of the activity.

type ActivityType

type ActivityType int

ActivityType is an enum that changes how the activity is presented upon starting.

const (
	ActivityTypeUndefined ActivityType = 0
	ActivityTypeStandard  ActivityType = 1
	ActivityTypeHome      ActivityType = 2
	ActivityTypeRecents   ActivityType = 3
	ActivityTypeAssistant ActivityType = 4
	ActivityTypeDream     ActivityType = 5
)

Constants taken from WindowConfiguration.java. See: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/app/WindowConfiguration.java;l=133;drc=6d5082d3a593d34b413067a3cc30069aa2b78818

type BorderType

type BorderType uint

BorderType represents the 8 different border types that a window can have.

type Display

type Display struct {
	DisplayID int
	// contains filtered or unexported fields
}

Display holds resources related to an ARC display. For the moment only the default display (internal display) is supported.

func NewDisplay

func NewDisplay(a *ARC, displayID int) (*Display, error)

NewDisplay returns a new Display instance. The caller is responsible for closing a. Returned Display instance must be closed when the test is finished.

func (*Display) CaptionHeight

func (d *Display) CaptionHeight(ctx context.Context) (h int, err error)

CaptionHeight returns the caption height in pixels.

func (*Display) Close

func (d *Display) Close()

Close closes resources related to the Display instance.

func (*Display) OverrideDensityDPI

func (d *Display) OverrideDensityDPI(ctx context.Context) (dpi int, err error)

OverrideDensityDPI returns the density DPI used by the Android framework for the display. Only works on Android R and later.

func (*Display) PhysicalDensity

func (d *Display) PhysicalDensity(ctx context.Context) (density float64, err error)

PhysicalDensity returns the density value in PhysicalDisplayInfo.

func (*Display) Size

func (d *Display) Size(ctx context.Context) (s coords.Size, err error)

Size returns the display size. Takes into account possible orientation changes. For example, if the display is rotated, instead of returning {W, H}, it will return {H, W}.

type DisplayType

type DisplayType string

DisplayType represents corresponding ARC display type string from dumpsys display.

const (
	// Internal display.
	InternalDisplay DisplayType = "INTERNAL"
	// Virtual display.
	VirtualDisplay DisplayType = "VIRTUAL"
	// External display.
	ExternalDisplay DisplayType = "EXTERNAL"
)

DisplayType available on R and above versions.

type GaiaLoginPoolVars

type GaiaLoginPoolVars struct {
	PoolVar string // the secret variable for the GAIA pool
}

GaiaLoginPoolVars holds the secret variable for a GAIA POOL.

type GaiaVars

type GaiaVars struct {
	UserVar string // the secret variable for the GAIA username
	PassVar string // the secret variable for the GAIA password
}

GaiaVars holds the secret variables for username and password for a GAIA login.

type InstallType

type InstallType int

InstallType is the type of ARC (Container or VM) available on the device.

const (
	// Container is for the ARC container install.
	Container InstallType = iota
	// VM is for the ARCVM install.
	VM
)

func Type

func Type() (t InstallType, ok bool)

Type detects the type (container or VM) of the ARC installation. As for Supported(), it should not be used to skip tests entirely, both fall under the "android_p" software dependency. But it could be used to change the behaviour of a test (e.g. check that ARCVM is running or not).

type PreData

type PreData struct {
	// Chrome is a connection to an already-started Chrome instance.
	// It cannot be closed by tests.
	Chrome *chrome.Chrome
	// ARC enables interaction with an already-started ARC environment.
	// It cannot be closed by tests.
	ARC *ARC
	// UIDevice is a UI Automator device object.
	// It cannot be closed by tests.
	UIDevice *ui.Device
	// LacrosFixt is lacros fixture data when tests use lacros related fixtures.
	LacrosFixt lacrosfixt.FixtValue
}

PreData holds information made available to tests that specify preconditions.

type Snapshot

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

Snapshot represents a Snapshot of ARC state. Fixtures and preconditions can use a Snapshot to revert ARC state to the original one after running a test.

func NewSnapshot

func NewSnapshot(ctx context.Context, a *ARC) (*Snapshot, error)

NewSnapshot captures an ARC state snapshot.

func (*Snapshot) Restore

func (s *Snapshot) Restore(ctx context.Context, a *ARC) error

Restore restores the ARC state to the snapshot state.

type State

type State struct {
	// Provisioned indicates whether the ARC is provisioned.
	Provisioned bool `json:"provisioned"`
	// TOSNeeded indicates whether ARC Terms of Service needs to be shown.
	TOSNeeded bool `json:"tosNeeded"`
	// PreStartTime is ARC pre-start time (mini-ARC) or 0 if not pre-started.
	PreStartTime float64 `json:"preStartTime"`
	// StartTime is the ARC start time or 0 if not started.
	StartTime float64 `json:"startTime"`
}

State holds the ARC state returned from autotestPrivate.getArcState() call.

Refer to https://chromium.googlesource.com/chromium/src/+/main/chrome/common/extensions/api/autotest_private.idl for the mapping of the fields to JavaScript.

func GetState

func GetState(ctx context.Context, tconn *chrome.TestConn) (State, error)

GetState gets the arc state. It is a wrapper for chrome.autotestPrivate.getArcState.

type TaskInfo

type TaskInfo struct {
	// ID represents the TaskRecord ID.
	ID int
	// StackID represents the stack ID.
	StackID int
	// StackSize represents how many activities are in the stack.
	StackSize int
	// Bounds represents the task bounds in pixels. Caption is not taken into account.
	Bounds coords.Rect
	// ActivityInfos is the activities in the task
	ActivityInfos []ActivityInfo
	// contains filtered or unexported fields
}

TaskInfo contains the information found in TaskRecord. See: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/pie-release/services/core/java/com/android/server/am/TaskRecord.java

type WindowState

type WindowState int

WindowState represents the different states a window can have.

const (
	// WindowStateNormal represents the "not maximized" state, but users can maximize it if they want.
	WindowStateNormal WindowState = 0
	// WindowStateMaximized is the maximized window state.
	WindowStateMaximized WindowState = 1
	// WindowStateFullscreen is the fullscreen window state.
	WindowStateFullscreen WindowState = 2
	// WindowStateMinimized is the minimized window state.
	WindowStateMinimized WindowState = 3
	// WindowStatePrimarySnapped is the primary snapped state.
	WindowStatePrimarySnapped WindowState = 4
	// WindowStateSecondarySnapped is the secondary snapped state.
	WindowStateSecondarySnapped WindowState = 5
	// WindowStatePIP is the Picture-in-Picture state.
	WindowStatePIP WindowState = 6
)

Constants taken from WindowPositioner.java. See: http://cs/pi-arc-dev/frameworks/base/services/core/arc/java/com/android/server/am/WindowPositioner.java

func (WindowState) String

func (s WindowState) String() string

String returns a human-readable string representation for type WindowState.

func (WindowState) ToAshWindowState

func (s WindowState) ToAshWindowState() (ash.WindowStateType, error)

ToAshWindowState returns equivalent ash WindowStateType for the arc WindowState.

type WindowingMode

type WindowingMode int

WindowingMode is an enum that changes how the window of the activity is presented.

const (
	WindowingModeUndefined            WindowingMode = 0
	WindowingModeFullscreen           WindowingMode = 1
	WindowingModePinned               WindowingMode = 2
	WindowingModeSplitScreenPrimary   WindowingMode = 3
	WindowingModeSplitScreenSecondary WindowingMode = 4
	WindowingModeFreeform             WindowingMode = 5
	WindowingModeMultiWindow          WindowingMode = 6
)

Constants taken from WindowConfiguration.java. See: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/app/WindowConfiguration.java;l=93;drc=6d5082d3a593d34b413067a3cc30069aa2b78818

Directories

Path Synopsis
Package optin provides set of util functions used to control ARC provisioning.
Package optin provides set of util functions used to control ARC provisioning.
Package playstore provides set of util functions used to install applications through the playstore.
Package playstore provides set of util functions used to install applications through the playstore.

Jump to

Keyboard shortcuts

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