goadb/adb/device_state.go

35 lines
931 B
Go
Raw Normal View History

package adb
2020-07-13 06:18:10 +00:00
import "goadb/internal/errors"
// 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
)
var deviceStateStrings = map[string]DeviceState{
2020-07-13 06:18:10 +00:00
"": StateDisconnected,
"offline": StateOffline,
"device": StateOnline,
"unauthorized": StatUnauthorized,
}
func parseDeviceState(str string) (DeviceState, error) {
state, ok := deviceStateStrings[str]
if !ok {
return StateInvalid, errors.Errorf(errors.ParseError, "invalid device state: %q", state)
}
return state, nil
}