forked from zach-klippenstein/goadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_state.go
34 lines (29 loc) · 962 Bytes
/
device_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package adb
import "github.com/zach-klippenstein/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
StateUnauthorized
StateDisconnected
StateOffline
StateOnline
)
var deviceStateStrings = map[string]DeviceState{
"": StateDisconnected,
"offline": StateOffline,
"device": StateOnline,
"unauthorized": StateUnauthorized,
}
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
}