Adds placeholders for home, back, and other input events

This commit is contained in:
2022-07-17 19:49:08 -07:00
parent 22435135d8
commit 5dde50c406
3 changed files with 81 additions and 9 deletions

View File

@@ -23,8 +23,8 @@ If you would like to add support for Windows, MacOS, *BSD..., please [Submit a P
- [ ] `adb install`
- [ ] `adb push`
- [ ] `adb reboot`
- [ ] `adb tap X Y`
- [ ] `adb swipe X1 Y1 X2 Y2 duration`
- [ ] `adb shell input tap X Y`
- [ ] `adb shell input swipe X1 Y1 X2 Y2 duration`
Please note that as this is a purpose-driven project library, not all functionality of ADB is currently supported, but if you need functionality that's not currently supported,
Feel free to [Open an Issue](https://github.com/taigrr/adb/issues) or [Submit a Pull Request](https://github.com/taigrr/adb/pulls)

48
adb.go
View File

@@ -3,7 +3,6 @@ package adb
import (
"context"
"net"
"sync"
)
type Serial string
@@ -16,12 +15,10 @@ const (
)
type Device struct {
IsConnected bool
SerialNo Serial
ConnType Connection
IP net.IPAddr
FileHandle string // TODO change this to a discrete type
Lock sync.Mutex
}
type ConnOptions struct {
@@ -60,3 +57,48 @@ func Devices(ctx context.Context) ([]Device, error) {
func (d Device) Disconnect(ctx context.Context) error {
return nil
}
// Kill the ADB Server
//
// Warning, this function call may cause inconsostency if nto 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.
func KillServer(ctx context.Context) error {
return nil
}
// Push a file to a Device.
//
// Returns an error if src does not exist or there is an error copying the file.
func (d Device) Push(ctx context.Context, src, dest string) error {
return nil
}
// Pulls a file from a Device
//
// Returns an error if src does not exist, or if dest already exists or cannot be created
func (d Device) Pull(ctx context.Context, src, dest string) error {
return nil
}
// Attempts to reboot the device
//
// Once the device reboots, you must manually reconnect.
// Returns an error if the device cannot be contacted
func (d Device) Reboot(ctx context.Context) error {
return nil
}
// 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 (d Device) Root(ctx context.Context) (success bool, err error) {
return true, nil
}

View File

@@ -2,6 +2,7 @@ package adb
import (
"context"
"time"
)
// Shell allows you to run an arbitrary shell command against a device.
@@ -13,3 +14,32 @@ import (
func (d Device) Shell(ctx context.Context, command string) (stdout string, stderr string, ErrCode int, err error) {
return "", "", 1, nil
}
func (d Device) Tap(ctx context.Context, X, Y int) error {
return nil
}
func (d Device) Swipe(ctx context.Context, X1, Y1, X2, Y2 int, duration time.Duration) error {
return nil
}
// Equivalent to pressing the home button
//
// Calls `input keyevent KEYCODE_HOME` under the hood
func (d Device) GoHome(ctx context.Context) error {
return nil
}
//Equivalent to pressing the back button
//
// Calls `input keyevent KEYCODE_BACK` under the hood
func (d Device) GoBack(ctx context.Context) error {
return nil
}
// Equivalent to pushing the app switcher. You probably want to call this twice.
//
// Calls `input keyevent KEYCODE_APP_SWITCH` under the hood
func (d Device) SwitchApp(ctx context.Context) error {
return nil
}