-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsettings.go
47 lines (41 loc) · 969 Bytes
/
settings.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
44
45
46
47
package adb
import (
"strings"
)
func checkNameValid(name string) bool {
return !(name == "" || name == "null" || strings.Contains(strings.ToLower(name), "error"))
}
// see: https://stackoverflow.com/questions/16704597/how-do-you-get-the-user-defined-device-name-in-android
func (d *Device) GetDeviceName() (name string, err error) {
// fist try
resp, err := d.RunCommand("settings get global device_name")
if err != nil {
return
}
name = string(resp)
if checkNameValid(name) {
return
}
// try again
resp, err = d.RunCommand("settings get secure bluetooth_name")
if err != nil {
return
}
name = string(resp)
if checkNameValid(name) {
return
}
// final try
name, err = d.GetProperty(PropProductName)
return
}
func (d *Device) SetAccelerometerRotation(enable bool) error {
var value string
if enable {
value = "1"
} else {
value = "0"
}
_, err := d.RunCommand("settings put system accelerometer_rotation " + value)
return err
}