Skip to content

Commit d21f707

Browse files
committed
Add ADB device selection menu
1 parent eff4ff5 commit d21f707

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/i582/cfmt/cmd/cfmt"
16+
"github.com/manifoldco/promptui"
1617
"github.com/mvt-project/androidqf/acquisition"
1718
"github.com/mvt-project/androidqf/adb"
1819
"github.com/mvt-project/androidqf/log"
@@ -38,6 +39,20 @@ func systemPause() {
3839
os.Stdin.Read(make([]byte, 1))
3940
}
4041

42+
func selectADBDevice(devices []string) (string, error) {
43+
promptDevice := promptui.Select{
44+
Label: "Multiple Android devices detected. Select the device to acquire",
45+
Items: devices,
46+
}
47+
48+
_, device, err := promptDevice.Run()
49+
if err != nil {
50+
return "", fmt.Errorf("failed to select ADB device: %v", err)
51+
}
52+
53+
return device, nil
54+
}
55+
4156
func main() {
4257
var err error
4358
var verbose bool
@@ -107,6 +122,20 @@ func main() {
107122

108123
// Initialization
109124
for {
125+
if serial == "" {
126+
devices, err := adb.Client.Devices()
127+
if err != nil {
128+
log.Error(fmt.Sprintf("Error listing ADB devices: %s", err))
129+
} else if len(devices) > 1 {
130+
serial, err = selectADBDevice(devices)
131+
if err != nil {
132+
log.Error(fmt.Sprintf("Error selecting ADB device: %s", err))
133+
time.Sleep(5 * time.Second)
134+
continue
135+
}
136+
}
137+
}
138+
110139
serial, err = adb.Client.SetSerial(serial)
111140
if err != nil {
112141
log.Error(fmt.Sprintf("Error trying to connect over ADB: %s", err))

0 commit comments

Comments
 (0)