device

package
v0.0.0-...-028fd47 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: MIT Imports: 5 Imported by: 0

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

View Source
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

func (dev Device) Adb(command string, args ...string) (string, error)

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

func (dev Device) GetAllProperties() (map[string]string, error)

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

func (dev Device) GetProperty(key string) (string, error)

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

func (dev Device) IsAvailable() (bool, error)

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

func (dev Device) Pull(src string, dst string) (string, error)

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

func (dev Device) Push(src string, dst string) (string, error)

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

func (dev Device) Reboot(restartTimeout int, bootTimeout int) error

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

func (dev Device) Root() error

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

func (dev Device) Shell(command string, args ...string) (string, error)

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

func (dev Device) WaitForAvailability(timeout int) error

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

func (dev Device) WaitForBootToComplete(bootTimeout int) error

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.

Jump to

Keyboard shortcuts

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