Browse Source

Use ANDROID_SERIAL for device selection (#75)

Closes #72
pull/79/merge
jugendhacker 3 years ago committed by GitHub
parent
commit
d8882fc307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      devices.go

16
devices.go

@ -5,6 +5,7 @@ package main
import (
"fmt"
"os"
"mvdan.cc/fdroidcl/adb"
)
@ -50,12 +51,21 @@ func maybeOneDevice() (*adb.Device, error) {
if err != nil {
return nil, fmt.Errorf("could not get devices: %v", err)
}
if len(devices) > 1 {
return nil, fmt.Errorf("at most one connected device can be used")
}
if len(devices) < 1 {
return nil, nil
}
envAndroidSerial := os.Getenv("ANDROID_SERIAL")
if len(envAndroidSerial) > 0 {
for _, device := range devices {
if device.ID == envAndroidSerial {
return device, nil
}
}
return nil, fmt.Errorf("ANDROID_SERIAL set, but no device with this serial found")
}
if len(devices) > 1 {
return nil, fmt.Errorf("at most one connected device can be used, if ANDROID_SERIAL was not set")
}
return devices[0], nil
}

Loading…
Cancel
Save