adb

package
v3.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package adb provides an interface to the Android Debug Bridge.

Index

Constants

View Source
const (
	// ErrDeviceNotRooted is returned by Device.Root when the device is running a
	// production build as is not 'rooted'.
	ErrDeviceNotRooted = fault.Const("Device is not a userdebug build")
	ErrRootFailed      = fault.Const("Device failed to switch to root")
	ErrUnrootFailed    = fault.Const("Device failed to switch out of root")
)
View Source
const (
	// ErrNoDeviceList May be returned if the adb fails to return a device list when asked.
	ErrNoDeviceList = fault.Const("Device list not returned")
	// ErrInvalidDeviceList May be returned if the device list could not be parsed.
	ErrInvalidDeviceList = fault.Const("Could not parse device list")
	// ErrInvalidStatus May be returned if the status string is not a known status.
	ErrInvalidStatus = fault.Const("Invalid status string")
)
View Source
const (
	EV_ABS = 3
	EV_SYN = 0
)

Event types

View Source
const (
	ABS_MT_TRACKING_ID = 57
	ABS_MT_POSITION_X  = 53
	ABS_MT_POSITION_Y  = 54
	ABS_MT_PRESSURE    = 58
	ABS_MT_TOUCH_MAJOR = 48
	SYN_REPORT         = 0
)

Event codes

View Source
const (
	ErrScreenState = fault.Const("Couldn't get screen state")
)
View Source
const (
	ErrServiceTimeout = fault.Const("Timeout connecting to service")
)

Variables

ADB is the path to the adb executable, or an empty string if the adb executable was not found.

View Source
var (
	AnsiRegex = regexp.MustCompile("\u001b\\[\\d+m")
)

Functions

func ForwardAndConnect

func ForwardAndConnect(ctx context.Context, d Device, las string) (io.ReadCloser, error)

ForwardAndConnect forwards the local-abstract-socket las and connects to it. When the returned ReadCloser is closed the forwarded port is removed. The function takes care of the quirky behavior of ADB forwarded sockets.

func LimitToSerial

func LimitToSerial(serial string)

LimitToSerial restricts the device lookup to only scan and operate on the device with the given serial id.

func Monitor

func Monitor(ctx context.Context, r *bind.Registry, interval time.Duration) error

Monitor updates the registry with devices that are added and removed at the specified interval. Monitor returns once the context is cancelled.

func RegisterDeviceInfoProvider

func RegisterDeviceInfoProvider(f DeviceInfoProvider)

RegisterDeviceInfoProvider registers f to be called to add additional information to a newly discovered Android device.

func SetupAngle

func SetupAngle(ctx context.Context, d Device, p *android.InstalledPackage) (app.Cleanup, error)

func SetupPrereleaseDriver

func SetupPrereleaseDriver(ctx context.Context, d Device, p *android.InstalledPackage) (app.Cleanup, error)

Types

type Device

type Device interface {
	android.Device
	// Command is a helper that builds a shell.Cmd with the device as its target.
	Command(name string, args ...string) shell.Cmd
	// Root restarts adb as root. If the device is running a production build then
	// Root will return ErrDeviceNotRooted.
	Root(ctx context.Context) error
	// IsDebuggableBuild returns true if the device runs a debuggable Android build.
	IsDebuggableBuild(ctx context.Context) (bool, error)
	// Forward will forward the specified device Port to the specified local Port.
	Forward(ctx context.Context, local, device Port) error
	// RemoveForward removes a port forward made by Forward.
	RemoveForward(ctx context.Context, local Port) error
	// GraphicsDriver queries and returns info about the prerelease graphics driver.
	GraphicsDriver(ctx context.Context) (Driver, error)
	// PrepareGpuProfiling queries GPU profiling support, and when profiling is supported it sets up
	// the device for profiling of installedPackage app. It returns:
	// - a bool which is true when GPU profiling is supported and the setup is done without errors
	// - a string that contains the name of the package where to find profiling layers, this string
	//   is empty if there is no profiling layer required
	// - a cleanup function to revert the device settings after profiling is done
	// - an error to indicate if anything went wrong
	// The returned bool disambiguates between "an error happened" and "profiling is not supported".
	PrepareGpuProfiling(ctx context.Context, installedPackage *android.InstalledPackage) (bool, string, app.Cleanup, error)
}

Device extends the android.Device interface with adb specific features.

type DeviceInfoProvider

type DeviceInfoProvider func(ctx context.Context, d Device) error

DeviceInfoProvider is a function that adds additional information to a Device.

type DeviceList

type DeviceList []Device

DeviceList is a list of devices.

func Devices

func Devices(ctx context.Context) (DeviceList, error)

Devices returns the list of attached Android devices.

func (DeviceList) FindBySerial

func (l DeviceList) FindBySerial(serial string) Device

FindBySerial returns the device with the matching serial, or nil if the device cannot be found.

type Driver

type Driver struct {
	Package string
	Path    string
}

Driver contains the information about a graphics driver.

type NamedAbstractSocket

type NamedAbstractSocket string

NamedAbstractSocket represents an abstract UNIX domain socket name on either the local machine or Android device. NamedAbstractSocket implements the Port interface.

type NamedFileSystemSocket

type NamedFileSystemSocket string

NamedFileSystemSocket represents an file system UNIX domain socket name on either the local machine or Android device. NamedFileSystemSocket implements the Port interface.

type Port

type Port interface {
	// contains filtered or unexported methods
}

Port is the interface for sockets ports that can be forwarded from an Android Device to the local machine.

type TCPPort

type TCPPort int

TCPPort represents a TCP/IP port on either the local machine or Android device. TCPPort implements the Port interface.

func LocalFreeTCPPort

func LocalFreeTCPPort() (TCPPort, error)

LocalFreeTCPPort returns a currently free TCP port on the localhost. There are two potential issues with using this for ADB port forwarding:

  • There is the potential for the port to be taken between the function returning and the port being used by ADB.
  • The system _may_ hold on to the socket after it has been told to close.

Because of these issues, there is a potential for flakiness.

Jump to

Keyboard shortcuts

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