adb

package module
v0.0.0-...-1b432de Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: MIT Imports: 9 Imported by: 0

README

adb-go

easy to using adb with go

只是对 adb 的部分操作进行封装,并不是 adb 的 go 实现

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrorOutput

func IsErrorOutput(output []byte) bool

命令运行时可能会出现异常并在控制台输出,此函数就是为了识别这些可能的异常 另一方面,有些时候命令执行是成功的,但是执行的结果我将其视为 "失败" 例如执行 adb connect "" 时 ,输出是 "empty address...",我认为将其视为 error 是合适的 此函数并未涵盖所有的可能的异常输出,我只是添加了我遇到的

Types

type ADBRunner

type ADBRunner = func(args string) ([]byte, error)

用于执行 ADB 命令,例如: run("shell ls")

func NewADBRunner

func NewADBRunner(adb string) ADBRunner

adb 是运行 adb 时使用的命令,可以使用指定 adb 的路径,例如 "/usr/bin/adb"

type ADBRunnerWithReader

type ADBRunnerWithReader = func(args string) (io.Reader, error)

func NewADBRunnerWithReader

func NewADBRunnerWithReader(adb string) ADBRunnerWithReader

type Device

type Device struct {
	IsOnline    bool
	ID          string
	USB         string
	Product     string
	Model       string
	Device      string
	TransportID int
	// 此处的 Cmd 已经带有指定设备的参数,例如 "-s 192.168.1.3"
	// 当调用 Cmd("ls") 时,实际运行的命令是 "adb -s 192.168.1.3 shell ls"
	Cmd ADBRunner
	// adb 执行文件的路径
	ADBPath string
	Input   Input
}

func (*Device) Screencap

func (d *Device) Screencap() ([]byte, error)

直接截图传输图片,截图过程中如果触碰屏幕,可能会导致失败

func (*Device) ScreencapTo

func (d *Device) ScreencapTo(fileName string) (*os.File, error)

截图并保存文件到 fileName

type Input

type Input interface {
	Press(x, y, duration int) error
	Power() error
	Click(x, y int) error
	Swipe(x, y, x2, y2, duration int) error
	Text(text string) error
	VolumeDown() error
	VolumeUp() error
	Home() error
	Back() error
	Menu() error
	Del(count int) error
	Keyevent(event string) error
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func DefaultServer

func DefaultServer() Server

使用机器自带的 adb 命令,需要安装 adb

func NewServer

func NewServer(cmd ADBRunner, adbPath string) Server

cmd 见 NewADBRunner(),你也可以自己实现 ADBRunner adbPath 是 adb 的路径

func (*Server) ADBPath

func (s *Server) ADBPath() string

func (*Server) Cmd

func (s *Server) Cmd(args string) ([]byte, error)

func (*Server) Connect

func (s *Server) Connect(host string) error

连接一个网络设备,如果 err==nil 那么连接成功

func (*Server) Devices

func (s *Server) Devices() ([]Device, error)

获取所有已经连接的设备

func (*Server) Disconnect

func (s *Server) Disconnect(host string) error

断开网络设备的连接,如果 host=="" 则会断开所有网络设备连接

func (*Server) KillServer

func (s *Server) KillServer() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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