diff --git a/device.go b/device.go new file mode 100644 index 0000000..3623a3c --- /dev/null +++ b/device.go @@ -0,0 +1,30 @@ +package goadb + +import ( + "fmt" + "log" + "strings" + +) + +// IsConnected checks if the device is currently connected via ADB +func (d *Device) IsConnected() bool { + output, err := ExecuteCommand("devices") + if err != nil { + log.Println(fmt.Errorf("Failed to determine device status: %w", err)) + return false + } + lines := strings.Split(string(output), "\n") + for _, line := range lines { + if strings.HasPrefix(line, d.Serial) && strings.Contains(line, "device") { + return true + } + } + return false +} + +// Run a command on this specific device +func (d *Device) RunCommand(command string) ([]byte, error) { + return ExecuteCommand(fmt.Sprintf("-s %s %s", d.Serial, command)) +} +