-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
176 lines (156 loc) · 4.25 KB
/
main.go
File metadata and controls
176 lines (156 loc) · 4.25 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Check satellite telephony readiness by querying the telephony service.
//
// Queries the ITelephony proxy for radio state, data connectivity,
// network type, SIM presence, and satellite PLMNs. These are the
// prerequisite checks before satellite telephony can be used.
//
// Build:
//
// GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o build/satellite_check ./examples/satellite_check/
// adb push satellite_check /data/local/tmp/ && adb shell /data/local/tmp/satellite_check
package main
import (
"context"
"fmt"
"os"
"github.com/AndroidGoLab/binder/binder"
"github.com/AndroidGoLab/binder/binder/versionaware"
"github.com/AndroidGoLab/binder/com/android/internal_/telephony"
"github.com/AndroidGoLab/binder/kernelbinder"
"github.com/AndroidGoLab/binder/servicemanager"
)
func dataStateName(state int32) string {
switch state {
case 0:
return "disconnected"
case 1:
return "connecting"
case 2:
return "connected"
case 3:
return "suspended"
case 4:
return "disconnecting"
default:
return fmt.Sprintf("unknown(%d)", state)
}
}
func phoneTypeName(t int32) string {
switch t {
case 0:
return "none"
case 1:
return "GSM"
case 2:
return "CDMA"
case 3:
return "SIP"
default:
return fmt.Sprintf("unknown(%d)", t)
}
}
func callStateName(state int32) string {
switch state {
case 0:
return "idle"
case 1:
return "ringing"
case 2:
return "offhook"
default:
return fmt.Sprintf("unknown(%d)", state)
}
}
func main() {
ctx := context.Background()
driver, err := kernelbinder.Open(ctx, binder.WithMapSize(128*1024))
if err != nil {
fmt.Fprintf(os.Stderr, "open binder: %v\n", err)
os.Exit(1)
}
defer driver.Close(ctx)
transport, err := versionaware.NewTransport(ctx, driver, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "version-aware transport: %v\n", err)
os.Exit(1)
}
sm := servicemanager.New(transport)
fmt.Println("=== Satellite Telephony Readiness ===")
fmt.Println()
// Get the telephony service.
svc, err := sm.GetService(ctx, servicemanager.TelephonyService)
if err != nil {
fmt.Fprintf(os.Stderr, "get telephony service: %v\n", err)
os.Exit(1)
}
tel := telephony.NewTelephonyProxy(svc)
// Radio state — satellite requires an active radio.
radioOn, err := tel.IsRadioOn(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "IsRadioOn: %v\n", err)
} else {
fmt.Printf("Radio on: %v\n", radioOn)
}
// Call state
callState, err := tel.GetCallState(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetCallState: %v\n", err)
} else {
fmt.Printf("Call state: %s\n", callStateName(callState))
}
// Data state
dataState, err := tel.GetDataState(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetDataState: %v\n", err)
} else {
fmt.Printf("Data state: %s\n", dataStateName(dataState))
}
// Active phone type
phoneType, err := tel.GetActivePhoneType(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "GetActivePhoneType: %v\n", err)
} else {
fmt.Printf("Phone type: %s\n", phoneTypeName(phoneType))
}
// SIM card presence
hasIcc, err := tel.HasIccCard(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "HasIccCard: %v\n", err)
} else {
fmt.Printf("SIM present: %v\n", hasIcc)
}
// Network country
country, err := tel.GetNetworkCountryIsoForPhone(ctx, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "GetNetworkCountryIsoForPhone: %v\n", err)
} else {
if country == "" {
country = "(none)"
}
fmt.Printf("Network country: %s\n", country)
}
// Satellite PLMNs for default subscription
fmt.Println()
fmt.Println("Satellite PLMNs (sub 0):")
plmns, err := tel.GetSatellitePlmnsForCarrier(ctx, 0)
if err != nil {
fmt.Fprintf(os.Stderr, " GetSatellitePlmnsForCarrier: %v\n", err)
} else if len(plmns) == 0 {
fmt.Println(" (none — satellite not provisioned for this carrier)")
} else {
for _, p := range plmns {
fmt.Printf(" %s\n", p)
}
}
// Check satellite service registration
fmt.Println()
satSvc, err := sm.CheckService(ctx, servicemanager.SatelliteService)
if err != nil {
fmt.Fprintf(os.Stderr, "CheckService(satellite): %v\n", err)
} else if satSvc == nil {
fmt.Println("Satellite service: NOT REGISTERED (device may not support satellite telephony)")
} else {
fmt.Printf("Satellite service: FOUND (handle=%d, alive=%v)\n",
satSvc.Handle(), satSvc.IsAlive(ctx))
}
}