From 810a431a8e93fc22afacd25a02152c973cab24f4 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Fri, 13 Jan 2023 16:18:38 -0800 Subject: [PATCH] add USB conn support explicitly --- adb.go | 10 ++++++++-- errors.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/adb.go b/adb.go index b97c616..3d38f4e 100644 --- a/adb.go +++ b/adb.go @@ -97,6 +97,7 @@ func Devices(ctx context.Context) ([]Device, error) { return parseDevices(stdout) } +// TODO add support for connected network devices func parseDevices(stdout string) ([]Device, error) { devs := []Device{} lines := strings.Split(stdout, "\n") @@ -119,7 +120,11 @@ func parseDevices(stdout string) ([]Device, error) { // // If a device is already disconnected or otherwise not found, returns an error. func (d Device) Disconnect(ctx context.Context) error { - return nil + if d.ConnType != Network { + return ErrConnUSB + } + _, _, _, err := execute(ctx, []string{"-s", d.ConnString(), "disconnect"}) + return err } // Kill the ADB Server @@ -131,7 +136,8 @@ func (d Device) Disconnect(ctx context.Context) error { // refuse following connection attempts if you don't disconnect from them before // calling this function. func KillServer(ctx context.Context) error { - return nil + _, _, _, err := execute(ctx, []string{"kill-server"}) + return err } // Push a file to a Device. diff --git a/errors.go b/errors.go index b508228..896b313 100644 --- a/errors.go +++ b/errors.go @@ -10,7 +10,7 @@ var ( ErrStdoutEmpty = errors.New("stdout expected to contain data but was empty") ErrNotInstalled = errors.New("adb is not installed or not in PATH") ErrCoordinatesNotFound = errors.New("coordinates for an input event are missing") - ErrConnUSB = errors.New("cannot call connect to device using USB") + ErrConnUSB = errors.New("cannot call connect/disconnect to device using USB") ErrResolutionParseFail = errors.New("failed to parse screen size from input text") ErrUnspecified = errors.New("an unknown error has occurred, please open an issue on GitHub") )