Documentation ¶
Index ¶
- Variables
- func KillServer(ctx context.Context) error
- type ConnOptions
- type Connection
- type Device
- func (d Device) CaptureSequence(ctx context.Context) (t TapSequence, err error)
- func (d Device) ConnString() string
- func (d Device) Disconnect(ctx context.Context) error
- func (d Device) GetScreenResolution(ctx context.Context) (res Resolution, err error)
- func (d Device) GoBack(ctx context.Context) error
- func (d Device) GoHome(ctx context.Context) error
- func (d Device) LongPress(ctx context.Context, X, Y int) error
- func (d Device) Pull(ctx context.Context, src, dest string) error
- func (d Device) Push(ctx context.Context, src, dest string) error
- func (d Device) Reboot(ctx context.Context) error
- func (d Device) Reconnect(ctx context.Context) (Device, error)
- func (d Device) ReplayTapSequence(ctx context.Context, t TapSequence) error
- func (d Device) Root(ctx context.Context) (success bool, err error)
- func (d Device) Shell(ctx context.Context, command string) (stdout string, stderr string, ErrCode int, err error)
- func (d Device) Swipe(ctx context.Context, X1, Y1, X2, Y2 int, duration time.Duration) error
- func (d Device) SwitchApp(ctx context.Context) error
- func (d Device) Tap(ctx context.Context, X, Y int) error
- type Input
- type Resolution
- type SeqType
- type SequenceImporter
- type SequenceSleep
- type SequenceSwipe
- type SequenceTap
- type Serial
- type TapSequence
- type TapSequenceImporter
Constants ¶
This section is empty.
Variables ¶
var ( // When an execution should have data but has none, but the exact error is // indeterminite, this error is returned ErrStdoutEmpty = errors.New("stdout expected to contain data but was empty") ErrNotInstalled = errors.New("adb is not installed or not in PATH") ErrCoordinatesNotFound = errors.New("coordinates for an input event are missing") ErrConnUSB = errors.New("cannot call connect/disconnect to device using USB") ErrResolutionParseFail = errors.New("failed to parse screen size from input text") ErrUnspecified = errors.New("an unknown error has occurred, please open an issue on GitHub") )
Functions ¶
func KillServer ¶
Kill the ADB Server
Warning, this function call may cause inconsostency if not used properly. Killing the ADB server shouldn't ever technically be necessary, but if you do decide to use this function. note that it may invalidate all existing device structs. Older versions of Android don't play nicely with kill-server, and some may refuse following connection attempts if you don't disconnect from them before calling this function.
Types ¶
type ConnOptions ¶
Provides a connection string for Connect()
type Device ¶
type Device struct { IsAuthorized bool SerialNo Serial ConnType Connection IP net.IPAddr Port uint FileHandle string // TODO change this to a discrete type }
Create a Device with Connect() or a slice with Devices()
Device contains the information necessary to connect to and communicate with a device
func Connect ¶
func Connect(ctx context.Context, opts ConnOptions) (Device, error)
Connect to a device by IP:port.
This will return a Device struct, which can be used to call other methods. If the connection fails or cannot complete on time, Connect will return an error. TODO
func Devices ¶
Equivalent to running `adb devices`.
This function returns a list of discovered devices, but note that they may not be connected. It is recommended to call IsConnected() against the device you're interested in using and connect if not already connected before proceeding.
func (Device) CaptureSequence ¶
func (d Device) CaptureSequence(ctx context.Context) (t TapSequence, err error)
CaptureSequence allows you to capture and replay screen taps and swipes.
ctx, cancelFunc := context.WithCancel(context.TODO())
go dev.CaptureSequence(ctx) time.Sleep(time.Second * 30) cancelFunc()
func (Device) ConnString ¶
func (Device) Disconnect ¶
Disconnect from a device.
If a device is already disconnected or otherwise not found, returns an error.
func (Device) GetScreenResolution ¶
func (d Device) GetScreenResolution(ctx context.Context) (res Resolution, err error)
adb shell wm size Physical size: 1440x3120
func (Device) GoBack ¶
Equivalent to pressing the back button
Calls `input keyevent KEYCODE_BACK` under the hood
func (Device) GoHome ¶
Equivalent to pressing the home button
Calls `input keyevent KEYCODE_HOME` under the hood
func (Device) LongPress ¶
Simulates a long press
Under the hood, this calls swipe with the same start and end coordinates with a duration of 250ms
func (Device) Pull ¶
Pulls a file from a Device
Returns an error if src does not exist, or if dest already exists or cannot be created
func (Device) Push ¶
Push a file to a Device.
Returns an error if src does not exist or there is an error copying the file.
func (Device) Reboot ¶
Attempts to reboot the device
Once the device reboots, you must manually reconnect. Returns an error if the device cannot be contacted
func (Device) Reconnect ¶
Connect to a previously discovered device.
This function is helpful when connecting to a device found from the Devices call or when reconnecting to a previously connected device.
func (Device) ReplayTapSequence ¶
func (d Device) ReplayTapSequence(ctx context.Context, t TapSequence) error
func (Device) Root ¶
Attempt to relaunch adb as root on the Device.
Note, this may not be possible on most devices. Returns an error if it can't be done. The device connection will stay established. Once adb is relaunched as root, it will stay root until rebooted. returns true if the device successfully relaunched as root
func (Device) Shell ¶
func (d Device) Shell(ctx context.Context, command string) (stdout string, stderr string, ErrCode int, err error)
Shell allows you to run an arbitrary shell command against a device.
This function is useful if you need to run an obscure shell command or if you require functionality not provided by the exposed functions here. Instead of using Shell, please consider submitting a PR with the functionality you require.
type Resolution ¶
type SequenceImporter ¶
type SequenceImporter struct { Duration time.Duration Type SeqType X int Y int X1 int Y1 int X2 int Y2 int Start time.Time End time.Time }
func (SequenceImporter) ToInput ¶
func (si SequenceImporter) ToInput() Input
type SequenceSleep ¶
func (SequenceSleep) EndTime ¶
func (s SequenceSleep) EndTime() time.Time
func (SequenceSleep) Length ¶
func (s SequenceSleep) Length() time.Duration
func (SequenceSleep) StartTime ¶
func (s SequenceSleep) StartTime() time.Time
type SequenceSwipe ¶
type SequenceSwipe struct { X1 int Y1 int X2 int Y2 int Start time.Time End time.Time Type SeqType }
func (SequenceSwipe) EndTime ¶
func (s SequenceSwipe) EndTime() time.Time
func (SequenceSwipe) Length ¶
func (s SequenceSwipe) Length() time.Duration
func (SequenceSwipe) StartTime ¶
func (s SequenceSwipe) StartTime() time.Time
type SequenceTap ¶
func (SequenceTap) EndTime ¶
func (s SequenceTap) EndTime() time.Time
func (SequenceTap) Length ¶
func (s SequenceTap) Length() time.Duration
func (SequenceTap) StartTime ¶
func (s SequenceTap) StartTime() time.Time
type TapSequence ¶
type TapSequence struct { Events []Input Resolution Resolution }
func TapSequenceFromJSON ¶
func TapSequenceFromJSON(j []byte) (TapSequence, error)
func (TapSequence) GetLength ¶
func (t TapSequence) GetLength() time.Duration
GetLength returns the length of all Input events inside of a given TapSequence
This function is useful for devermining how long a context timeout should last when calling ReplayTapSequence
func (TapSequence) ShortenSleep ¶
func (t TapSequence) ShortenSleep(scalar int) TapSequence
func (TapSequence) ToJSON ¶
func (t TapSequence) ToJSON() []byte
type TapSequenceImporter ¶
type TapSequenceImporter struct { Events []SequenceImporter Resolution Resolution }