adbtools

package module
v0.0.0-...-5d78c2a Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: GPL-3.0 Imports: 10 Imported by: 5

README

adbtools

This package concentrates many of the most needed and helpful adb commands, easing its usage with Go.

It requires adb installed and a connected android device with debug permission.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartAVD

func StartAVD(verified bool, deviceName string) (func(), error)

StartAVD starts the emulator with the given name

This method requires the Android Studio to be installed and allows the calling to be verified or not

The returned function closes the emulator

ALERT: Requires the emulator to be closed, elsewise the emulator remains active

func StartAnbox

func StartAnbox() error

StartAnbox starts an Anbox Emulator

Before starting it only checks if Anbox is installed

Alert: Does not check if its dependencies are installed

To install dependencies check the link: https://docs.anbox.io/userguide/install_kernel_modules.html

To install Anbox check the link: https://docs.anbox.io/userguide/install.html

Alert: no method was found to stop the anbox emulator

func XMLtoCoords

func XMLtoCoords(xmlcoords string) ([2]int, error)

XMLtoCoords converts XML block coords to center tap coords. Accepts [x1,y1][x2,y2] format as string and returns [2]int coords

Types

type Device

type Device struct {
	ID  string
	Log bool

	DefaultSleep int
	Screen       struct {
		Width  int
		Height int
	}
	// contains filtered or unexported fields
}

Device main structure

func Devices

func Devices(Log bool) ([]Device, error)

Devices returns all the connected devices´ ID

func NewDevice

func NewDevice(deviceID string, log bool) Device

NewDevice creates a new device management struct

func (*Device) Activities

func (device *Device) Activities(packagename string) []string

Activities returns all package's activities

func (*Device) AutoRotate

func (device *Device) AutoRotate(rotate bool)

AutoRotate enables or disables the device auto rotation behaviour

func (*Device) ClearApp

func (device *Device) ClearApp(app string) error

ClearApp clears all the app data

func (*Device) CloseApp

func (device *Device) CloseApp(app string)

CloseApp closes the app

func (*Device) DefaultBrowser

func (device *Device) DefaultBrowser(url string) error

DefaultBrowser loads the page in a default browser's new tab

func (*Device) DeviceReady

func (device *Device) DeviceReady() bool

DeviceReady returns the readiness state of the device

func (*Device) Exp2Tap

func (device *Device) Exp2Tap(expression string) error

Exp2Tap taps the screen in the coordinates fetched using a regular expression and the screen's xml dump

func (*Device) Foreground

func (device *Device) Foreground() string

Foreground verifies if the given package is on foreground

func (*Device) GetImei

func (device *Device) GetImei() string

GetImei returns the device IMEI

func (*Device) HasInScreen

func (device *Device) HasInScreen(newDump bool, want ...string) bool

HasInScreen verifies if the wanted text appear on screen

func (*Device) InputText

func (device *Device) InputText(text string, splitted bool) error

InputText inserts a given text in a selected input

func (*Device) InstalledApp

func (device *Device) InstalledApp(pkg string) bool

InstalledApp checks if the given app package is installed

func (*Device) IsScreenON

func (device *Device) IsScreenON() bool

IsScreenON verifies if the is on

func (*Device) NodeList

func (device *Device) NodeList(newDump bool) []string

NodeList returns the unnested list of xml nodes

func (*Device) Orientation

func (device *Device) Orientation() (int, error)

Orientation returns the devices orientation

0: portrait

1: landscape

func (*Device) PageDown

func (device *Device) PageDown()

PageDown scrolls down a fixed amount of pixels

func (*Device) PageUp

func (device *Device) PageUp()

PageUp scrolls up a fixed amount of pixels

func (*Device) PowerButton

func (device *Device) PowerButton()

PowerButton emulates the pressing of the power button

func (*Device) Root

func (device *Device) Root() error

Root enables all adb commands to be run as root. Only works in rooted devices or emulators

func (*Device) ScreenCap

func (device *Device) ScreenCap(filename string)

ScreenCap captures the screen as png

func (*Device) ScreenRecord

func (device *Device) ScreenRecord(filename string, duration int)

ScreenRecord records the screen as video with limited duration. Uses mp4 format

func (*Device) ScreenSize

func (device *Device) ScreenSize() error

ScreenSize fetches the physical screen size and return its height and width

func (*Device) ScreenTimeout

func (device *Device) ScreenTimeout(waitTime string) (func(), error)

ScreenTimeout sets the screen off timeout to key1 seconds

Returns a function to be deferred setting timeout to key2 seconds

Accepts only the following time intervals:

15s

30s

1m

2m

5m

10m

30m

func (*Device) Shell

func (device *Device) Shell(arg string) string

Shell executes the given command in the Linux bash terminal and return the command output as string

func (*Device) Shutdown

func (device *Device) Shutdown()

Shutdown turns the device off

func (*Device) StartApp

func (device *Device) StartApp(pkg, activity, options string) error

StartApp requires the package name with format com.packagename and activity such as com.packagename.MainActivity

func (*Device) Swipe

func (device *Device) Swipe(coords [4]int)

Swipe swipes the screen with [x1,y1,x2,y2] coords format

func (*Device) TapCleanInput

func (device *Device) TapCleanInput(x, y, charcount int)

TapCleanInput tap and cleans the input

func (*Device) TapScreen

func (device *Device) TapScreen(x, y, delay int)

TapScreen taps the given coords and waits the given delay in Milliseconds

func (*Device) WaitApp

func (device *Device) WaitApp(pkg string, delay, maxRetry int) bool

WaitApp waits until the given app appears on the foreground.

Waits for given miliseconds after each try.

Note: Has limited retry count

func (*Device) WaitDeviceReady

func (device *Device) WaitDeviceReady(attemptCount int) error

WaitDeviceReady waits until the device. It's specially useful after a fresh boot.

func (*Device) WaitInScreen

func (device *Device) WaitInScreen(attemptCount int, want ...string) error

WaitInScreen waits until the wanted text appear on screen. It requires a max retry count to avoid endless loop.

func (*Device) WakeUp

func (device *Device) WakeUp()

WakeUp wakes the device up

func (*Device) XMLScreen

func (device *Device) XMLScreen(newdump bool) (string, error)

XMLScreen fetches the screen xml data

Jump to

Keyboard shortcuts

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