Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ADBPath string
ADBPath contains the absolute path to the adb executable, empty string if the adb executable was not found. In last case it should be set manually.
var ErrADBNotFound = errors.New("ADB command not found")
ErrADBNotFound is returned when the ADB executable is not found.
var ErrNoDevicesFound = errors.New("no devices found")
ErrNoDevicesFound is returned when the ADB executable returns an empty device list.
var ErrParseDeviceList = errors.New("could not parse device list")
ErrParseDeviceList is returned when the ADB executable returns an invalid device list.
var ErrParseDeviceState = errors.New("could not parse device state")
ErrParseDeviceState is returned when the ADB executable returns an invalid device state.
var RegexpSerial = regexp.MustCompile(`^[0-9a-f]{8}$`)
RegexpSerial contains regular expression to match serial numbers.
Functions ¶
func Exec ¶
Exec builds up an ADB command and executes it.
Example ¶
// simple error checking s, err := adb.Exec(5, "version") if err != nil { fmt.Printf("error occurred: %v\n", err) } else { fmt.Println("no error occurred") _ = s // fmt.Println(s) } // extended error checking s, err = adb.Exec(5, "foobar") if err != nil { // check for exit code != 0 if exiterr, ok := err.(*exec.ExitError); ok { // try to get exit code if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { fmt.Printf("exit code not 0: %d\n", status.ExitStatus()) } } else { fmt.Printf("error occurred: %v\n", err) } } else { fmt.Printf("exit code is 0\n") _ = s //fmt.Println(s) }
Output: no error occurred exit code not 0: 1
Types ¶
type Device ¶
type Device struct { Serial string State DeviceState }
Device contains details about an attached device.
func GetDevices ¶
GetDevices is a helper function that returns a list of attached devices.
Example ¶
package main import () func main() { // we can not simulate ADB device //d, err := adb.GetDevices() //fmt.Println(d[0].Serial) }
func ParseDevices ¶
ParseDevices parses the output from ADB devices command to Device struct.
Example ¶
o := `List of devices attached 36b8b42e offline` d, err := adb.ParseDevices(o) if err != nil { fmt.Println("error") } fmt.Println(d[0].Serial)
Output: 36b8b42e
type DeviceState ¶
type DeviceState int
DeviceState is the state of an device.
const ( //DeviceOffline referes to the state offline. DeviceOffline DeviceState = iota //DeviceOnline referes to the state online. DeviceOnline DeviceUnauthorized //DeviceUnknown refers to the state unknown. DeviceUnknown )
func GetDeviceState ¶
func GetDeviceState(serial string) (DeviceState, error)
GetDeviceState returns state of specific device.