-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdevice_state.go
43 lines (36 loc) · 1.02 KB
/
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
35
36
37
38
39
40
41
42
43
package adb
import (
"fmt"
"github.com/prife/goadb/wire"
)
// 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
StateAuthorizing
StateDisconnected
StateOffline
StateOnline
StateHost
)
var deviceStateStrings = map[string]DeviceState{
"": StateDisconnected,
"offline": StateOffline,
"device": StateOnline,
"unauthorized": StateUnauthorized,
"authorizing": StateAuthorizing,
"host": StateHost,
}
func parseDeviceState(str string) (DeviceState, error) {
state, ok := deviceStateStrings[str]
if !ok {
return StateInvalid, fmt.Errorf("%w: invalid device state: '%s'", wire.ErrParse, str)
}
return state, nil
}