-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
batterydiagnostics.go
57 lines (51 loc) · 1.82 KB
/
batterydiagnostics.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
48
49
50
51
52
53
54
55
56
57
package ios
type BatteryInfo struct {
BatteryCurrentCapacity uint64
BatteryIsCharging bool
ExternalChargeCapable bool
ExternalConnected bool
FullyCharged bool
GasGaugeCapability bool
HasBattery bool
}
const batteryDomain = "com.apple.mobile.battery"
type Connection struct {
deviceConn DeviceConnectionInterface
plistCodec PlistCodec
}
func GetBatteryDiagnostics(device DeviceEntry) (BatteryInfo, error) {
batteryConn, err := ConnectLockdownWithSession(device)
if err != nil {
return BatteryInfo{}, err
}
defer batteryConn.Close()
capacityResp, err := batteryConn.GetValueForDomain("BatteryCurrentCapacity", batteryDomain)
if err != nil {
return BatteryInfo{}, err
}
chargingResp, err := batteryConn.GetValueForDomain("BatteryIsCharging", batteryDomain)
if err != nil {
return BatteryInfo{}, err
}
externalChargeResp, err := batteryConn.GetValueForDomain("ExternalChargeCapable", batteryDomain)
if err != nil {
return BatteryInfo{}, err
}
externalResp, err := batteryConn.GetValueForDomain("ExternalConnected", batteryDomain)
if err != nil {
return BatteryInfo{}, err
}
chargedResp, err := batteryConn.GetValueForDomain("FullyCharged", batteryDomain)
if err != nil {
return BatteryInfo{}, err
}
gasGaugeResp, err := batteryConn.GetValueForDomain("GasGaugeCapability", batteryDomain)
if err != nil {
return BatteryInfo{}, err
}
hasBatteryResp, err := batteryConn.GetValueForDomain("HasBattery", batteryDomain)
if err != nil {
return BatteryInfo{}, err
}
return BatteryInfo{BatteryCurrentCapacity: capacityResp.(uint64), BatteryIsCharging: chargingResp.(bool), ExternalChargeCapable: externalChargeResp.(bool), ExternalConnected: externalResp.(bool), FullyCharged: chargedResp.(bool), GasGaugeCapability: gasGaugeResp.(bool), HasBattery: hasBatteryResp.(bool)}, nil
}