From 5dde50c406e849e40cb0b86883d242764eca8173 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 17 Jul 2022 19:49:08 -0700 Subject: [PATCH] Adds placeholders for home, back, and other input events --- README.md | 4 ++-- adb.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++------- shell.go | 30 +++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e626d47..c16e8e9 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/adb.go b/adb.go index ecbfc98..884c86b 100644 --- a/adb.go +++ b/adb.go @@ -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 + SerialNo Serial + ConnType Connection + IP net.IPAddr + FileHandle string // TODO change this to a discrete type } 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 +} diff --git a/shell.go b/shell.go index 0a674e3..33b4adc 100644 --- a/shell.go +++ b/shell.go @@ -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 +}