mirror of
https://github.com/taigrr/adb.git
synced 2026-04-02 02:58:42 -07:00
Adds placeholders for home, back, and other input events
This commit is contained in:
@@ -23,8 +23,8 @@ If you would like to add support for Windows, MacOS, *BSD..., please [Submit a P
|
|||||||
- [ ] `adb install`
|
- [ ] `adb install`
|
||||||
- [ ] `adb push`
|
- [ ] `adb push`
|
||||||
- [ ] `adb reboot`
|
- [ ] `adb reboot`
|
||||||
- [ ] `adb tap X Y`
|
- [ ] `adb shell input tap X Y`
|
||||||
- [ ] `adb swipe X1 Y1 X2 Y2 duration`
|
- [ ] `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,
|
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)
|
Feel free to [Open an Issue](https://github.com/taigrr/adb/issues) or [Submit a Pull Request](https://github.com/taigrr/adb/pulls)
|
||||||
|
|||||||
56
adb.go
56
adb.go
@@ -3,7 +3,6 @@ package adb
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Serial string
|
type Serial string
|
||||||
@@ -16,12 +15,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
IsConnected bool
|
SerialNo Serial
|
||||||
SerialNo Serial
|
ConnType Connection
|
||||||
ConnType Connection
|
IP net.IPAddr
|
||||||
IP net.IPAddr
|
FileHandle string // TODO change this to a discrete type
|
||||||
FileHandle string // TODO change this to a discrete type
|
|
||||||
Lock sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnOptions struct {
|
type ConnOptions struct {
|
||||||
@@ -60,3 +57,48 @@ func Devices(ctx context.Context) ([]Device, error) {
|
|||||||
func (d Device) Disconnect(ctx context.Context) error {
|
func (d Device) Disconnect(ctx context.Context) error {
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
30
shell.go
30
shell.go
@@ -2,6 +2,7 @@ package adb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Shell allows you to run an arbitrary shell command against a device.
|
// 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) {
|
func (d Device) Shell(ctx context.Context, command string) (stdout string, stderr string, ErrCode int, err error) {
|
||||||
return "", "", 1, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user