device: add support for running commands on a specific device
This commit is contained in:
30
device.go
Normal file
30
device.go
Normal file
@@ -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))
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user