@@ -23,7 +23,7 @@ type ADB struct {
23
23
var Client * ADB
24
24
25
25
// New returns a new ADB instance.
26
- func New (serial string ) (* ADB , error ) {
26
+ func New () (* ADB , error ) {
27
27
adb := ADB {}
28
28
err := adb .findExe ()
29
29
if err != nil {
@@ -35,33 +35,41 @@ func New(serial string) (*ADB, error) {
35
35
log .Debug ("Killing existing ADB server if running" )
36
36
adb .KillServer ()
37
37
38
- // Managing devices
39
- devices , err : = adb .Devices ()
38
+ // Confirm that we can call "adb devices" without errors
39
+ _ , err = adb .Devices ()
40
40
if err != nil {
41
41
return nil , err
42
42
}
43
+ return & adb , nil
44
+ }
45
+
46
+ func (a * ADB ) SetSerial (serial string ) (string , error ) {
47
+ devices , err := a .Devices ()
48
+ if err != nil {
49
+ return "" , err
50
+ }
43
51
44
52
serial = strings .TrimSpace (serial )
45
53
if len (devices ) == 0 {
46
- return nil , fmt .Errorf ("no devices connected to adb " )
54
+ return "" , fmt .Errorf ("no devices detected over ADB " )
47
55
}
56
+
48
57
if serial != "" {
49
58
// Check that the serial match one of the devices
50
59
// Can be replace with the go package slices in 1.21
51
60
if ! saveSlice .ContainsNoCase (devices , serial ) {
52
61
// Serial is not an existing device
53
- return nil , fmt .Errorf ("serial %s not found in the device list" , serial )
62
+ return "" , fmt .Errorf ("serial %s not found in the device list" , serial )
54
63
}
55
- adb .Serial = serial
64
+ a .Serial = serial
56
65
} else {
57
66
// Problem if multiple devices
58
67
if len (devices ) > 1 {
59
- return nil , fmt .Errorf ("multiple devices connected, please provide a serial number" )
68
+ return "" , fmt .Errorf ("multiple devices connected, please stop AndroidQF and provide a serial number" )
60
69
}
61
- adb .Serial = ""
70
+ a .Serial = ""
62
71
}
63
-
64
- return & adb , nil
72
+ return a .Serial , nil
65
73
}
66
74
67
75
// List existing devices
@@ -78,6 +86,7 @@ func (a *ADB) Devices() ([]string, error) {
78
86
dev := strings .Split (s , "\t " )
79
87
if len (dev ) == 2 {
80
88
devices = append (devices , strings .TrimSpace (dev [0 ]))
89
+ log .Debug ("Found new device: " , dev [0 ])
81
90
}
82
91
}
83
92
0 commit comments