adb

package
v0.0.0-...-15b4445 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 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")
)
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 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 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 on the preview graphics driver.
	GraphicsDriver(ctx context.Context) (Driver, 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 Jdwp

type Jdwp int

Jdwp represents a Jdwp process on an Android device. The value is the same as the PID of the process. Jdwp implements the Port interface.

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