Documentation ¶
Overview ¶
Package adb provides an interface to the Android Debug Bridge.
Index ¶
- Constants
- Variables
- func ForwardAndConnect(ctx context.Context, d Device, las string) (io.ReadCloser, error)
- func Monitor(ctx context.Context, r *bind.Registry, interval time.Duration) error
- func RegisterDeviceInfoProvider(f DeviceInfoProvider)
- type Device
- type DeviceInfoProvider
- type DeviceList
- type Jdwp
- type NamedAbstractSocket
- type NamedFileSystemSocket
- type Port
- type TCPPort
Constants ¶
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 rooted") ErrRootFailed = fault.Const("Device failed to switch to root") )
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") )
const ( EV_ABS = 3 EV_SYN = 0 )
Event types
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
const ( ErrScreenOnState = fault.Const("Couldn't get screen-on state") ErrLockScreenState = fault.Const("Couldn't get lockscreen state") )
const (
ErrServiceTimeout = fault.Const("Timeout connecting to service")
)
Variables ¶
var ADB file.Path
ADB is the path to the adb executable, or an empty string if the adb executable was not found.
Functions ¶
func ForwardAndConnect ¶
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 ¶
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.
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 // 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 }
Device extends the android.Device interface with adb specific features.
type DeviceInfoProvider ¶
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 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 ¶ added in v1.2.0
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 ¶
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.