Documentation ¶
Overview ¶
Package device provides some useful methods to operate on an associated android device.
Following are the features of this package:
- It provides generic methods to run adb or adb shell command on the associated device
- Gives ability to check if associated device is available or not
- Gives ability to gain adb root access to the associated device
- Gives ability to reboot associated device
- Gives ablity to wait for different device states
- Gives ablity to push or pull files/directories to/from device
- Gives ablity to fetch properties from the device
Index ¶
- Constants
- type Device
- func (dev Device) Adb(command string, args ...string) (string, error)
- func (dev Device) GetAllProperties() (map[string]string, error)
- func (dev Device) GetProperty(key string) (string, error)
- func (dev Device) IsAvailable() (bool, error)
- func (dev Device) Pull(src string, dst string) (string, error)
- func (dev Device) Push(src string, dst string) (string, error)
- func (dev Device) Reboot(restartTimeout int, bootTimeout int) error
- func (dev Device) Root() error
- func (dev Device) Shell(command string, args ...string) (string, error)
- func (dev Device) WaitForAvailability(timeout int) error
- func (dev Device) WaitForBootToComplete(bootTimeout int) error
Constants ¶
const (
PROP_BOOT_STATUS = "sys.boot_completed" // Property that represents devices boot status
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct { Serial string // Device serial number Timeout int // Timeout in seconds for all adb and shell operations AdbEndpoint adbutility.AdbEndpoint // Adb endpoint for this device }
Device struct represents adb capable android device, its serial number and associated adb endpoint. Device timeout represents all device specific adb operation timeouts.
func NewDevice ¶
func NewDevice(serial string, timeout int, endPoint adbutility.AdbEndpoint) Device
NewDevice method creates a new Device based on given serial number, adb operation timeout and connecting adb enpoint for this device.
func (Device) Adb ¶
Adb method allows to execute adb command on this device instance. It takes a adb command and optional list of arguments. It returns outout of the adb command and error in case of something went wrong. Please note that adb will timeout within default adb operation timeout.
func (Device) GetAllProperties ¶
GetAllProperties method returns a map of [key: value] pairs of all device properties. It also returns error in case of adb operation failure.
func (Device) GetProperty ¶
GetProperty method is used to extract a device property value based on the specified key. It returns string representation of the property value and error in case of adb operation failure or specified key is not located.
func (Device) IsAvailable ¶
IsAvailable method checkes availability of the device in the adb endpoint. It returns boolean value indicating availibility status of the device and error in case of something went wrong while doing adb operations.
func (Device) Pull ¶
Pull method pulls a file or directory from specified source path to specified destination path. Specified path must exist on device and specified destination path must exist on local machine. It returns command output and error in case of adb operation failed.
func (Device) Push ¶
Push method pushes a file or directory from local machine from specified source path to device in specified destination path. Specified source path mast exist on local machine and destinaltion path mast exist on device. It returns command output and error in case of adb operation failed.
func (Device) Reboot ¶
Reboot method reboots associated device. It waits for the device to become available again within specified restart timeout and the device to complete its boot sequence within specified boot timeout. It returns error in case of adb operation failure or timeout has been reached.
func (Device) Root ¶
Root method gains root access to the device, for this the device must be rooted. It returns error in case of root failed or adb operation failed.
func (Device) Shell ¶
Shell method allows to execute adb shell commands on associated device instance. It takes a shell comand and a list of opetional command arguments. It returns adb shell command output and stderr output combiled as string and error in case of adb operation failure or timeout.
func (Device) WaitForAvailability ¶
WaitForAvailability method waits for associatred device to be available or attached to the adb endpoint within specified timeout period. It returns error in case of adb operation failure or timeout.
func (Device) WaitForBootToComplete ¶
WaitForBootToComplete method waits for the device to complete its boot sequence within specified ammount of timeout. It returns error in case of adb operation failure or timeout has been reached.