2016-05-22 06:23:26 +00:00
|
|
|
package adb
|
|
|
|
|
2020-07-13 06:18:10 +00:00
|
|
|
import "goadb/internal/errors"
|
2016-05-22 06:23:26 +00:00
|
|
|
|
|
|
|
// DeviceState represents one of the 3 possible states adb will report devices.
|
|
|
|
// A device can be communicated with when it's in StateOnline.
|
|
|
|
// A USB device will make the following state transitions:
|
|
|
|
// Plugged in: StateDisconnected->StateOffline->StateOnline
|
|
|
|
// Unplugged: StateOnline->StateDisconnected
|
|
|
|
//go:generate stringer -type=DeviceState
|
|
|
|
type DeviceState int8
|
|
|
|
|
|
|
|
const (
|
|
|
|
StateInvalid DeviceState = iota
|
|
|
|
StateDisconnected
|
|
|
|
StateOffline
|
|
|
|
StateOnline
|
2020-07-13 06:18:10 +00:00
|
|
|
StatUnauthorized
|
2016-05-22 06:23:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var deviceStateStrings = map[string]DeviceState{
|
2020-07-13 06:18:10 +00:00
|
|
|
"": StateDisconnected,
|
|
|
|
"offline": StateOffline,
|
|
|
|
"device": StateOnline,
|
|
|
|
"unauthorized": StatUnauthorized,
|
2016-05-22 06:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func parseDeviceState(str string) (DeviceState, error) {
|
|
|
|
state, ok := deviceStateStrings[str]
|
|
|
|
if !ok {
|
2016-05-22 17:49:32 +00:00
|
|
|
return StateInvalid, errors.Errorf(errors.ParseError, "invalid device state: %q", state)
|
2016-05-22 06:23:26 +00:00
|
|
|
}
|
|
|
|
return state, nil
|
|
|
|
}
|