@@ -20,6 +20,8 @@ Includes a complete AIDL compiler that parses Android Interface Definition Langu
2020
2121## Quick start
2222
23+ <!-- BEGIN GENERATED QUICK_START -->
24+
2325** Go library** — ` go get github.com/xaionaro-go/binder ` and call any service:
2426
2527``` go
@@ -28,12 +30,13 @@ defer driver.Close(ctx)
2830transport , _ := versionaware.NewTransport (ctx, driver, 0 )
2931sm := servicemanager.New (transport)
3032
31- mgr , _ := location.GetLocationManager (ctx, sm)
32- loc , _ := mgr.GetLastLocation (ctx, string (location.ProviderFused ),
33- location.LastLocationRequest {}, " com.android.shell" )
34- fmt.Printf (" Lat: %.6f , Lon: %.6f \n " , loc.LatitudeDegrees , loc.LongitudeDegrees )
33+ power , _ := os.GetPowerManager (ctx, sm)
34+ interactive , _ := power.IsInteractive (ctx)
35+ fmt.Printf (" Screen on: %v \n " , interactive)
3536```
3637
38+ <!-- END GENERATED QUICK_START -->
39+
3740## Related Projects
3841
3942<details >
@@ -100,11 +103,17 @@ All three libraries talk to the same Android system services, but through differ
100103
101104## Usage Examples
102105
103- ### Get GPS Coordinates
106+ <!-- BEGIN GENERATED USAGE_EXAMPLES -->
107+
108+ ### Check Power State
104109
105110``` go
106111import (
107- " github.com/xaionaro-go/binder/android/location"
112+ " context"
113+ " fmt"
114+ " log"
115+
116+ genOs " github.com/xaionaro-go/binder/android/os"
108117 " github.com/xaionaro-go/binder/binder"
109118 " github.com/xaionaro-go/binder/binder/versionaware"
110119 " github.com/xaionaro-go/binder/kernelbinder"
@@ -125,19 +134,16 @@ import (
125134 }
126135 sm := servicemanager.New (transport)
127136
128- mgr , err := location. GetLocationManager (ctx, sm)
137+ power , err := genOs. GetPowerManager (ctx, sm)
129138 if err != nil {
130139 log.Fatal (err)
131140 }
132141
133- loc , err := mgr.GetLastLocation (ctx, string (location.ProviderFused ),
134- location.LastLocationRequest {}, " com.android.shell" )
135- if err != nil {
136- log.Fatal (err)
137- }
142+ interactive , _ := power.IsInteractive (ctx)
143+ fmt.Printf (" Screen on: %v \n " , interactive)
138144
139- fmt. Printf ( " Lat: %.6f , Lon: %.6f \n " , loc. LatitudeDegrees , loc. LongitudeDegrees )
140- fmt.Printf (" Altitude : %.1f m \n " , loc. AltitudeMeters )
145+ powerSave , _ := power. IsPowerSaveMode (ctx )
146+ fmt.Printf (" Power save : %v \n " , powerSave )
141147```
142148
143149### List Binder Services
@@ -158,39 +164,50 @@ import (
158164 }
159165```
160166
161- ### Call a System Service (PowerManager )
167+ ### Call a System Service (ActivityManager )
162168
163169``` go
164- import " github.com/xaionaro-go/binder/android/os"
170+ import (
171+ " github.com/xaionaro-go/binder/android/app"
172+ " github.com/xaionaro-go/binder/servicemanager"
173+ )
165174
166- pm , err := os. GetPowerManager (ctx, sm )
175+ svc , err := sm. GetService (ctx, servicemanager. ActivityService )
167176 if err != nil {
168177 log.Fatal (err)
169178 }
179+ am := app.NewActivityManagerProxy (svc)
170180
171- interactive , _ := pm. IsInteractive (ctx)
172- fmt.Printf (" Screen on : %v \n " , interactive )
181+ limit , _ := am. GetProcessLimit (ctx)
182+ fmt.Printf (" Process limit : %d \n " , limit )
173183
174- powerSave , _ := pm. IsPowerSaveMode (ctx)
175- fmt.Printf (" Power save : %v \n " , powerSave )
184+ monkey , _ := am. IsUserAMonkey (ctx)
185+ fmt.Printf (" Is monkey : %v \n " , monkey )
176186```
177187
178188More examples: [ ` examples/ ` ] ( examples/ )
179189
190+ <!-- END GENERATED USAGE_EXAMPLES -->
191+
192+ <!-- BEGIN GENERATED EXAMPLES_TABLE -->
193+
180194| Example | Queries |
181195| ---------------------------------------------------------- | --------------------------------------------------- |
182- | [ ` list_services ` ] ( examples/list_services/ ) | Enumerate all binder services, ping each |
183- | [ ` activity_manager ` ] ( examples/activity_manager/ ) | Process limits, monkey test flag, permission checks |
184- | [ ` battery_health ` ] ( examples/battery_health/ ) | Capacity, charge status, current draw |
185- | [ ` device_info ` ] ( examples/device_info/ ) | Device properties, build info |
186- | [ ` display_info ` ] ( examples/display_info/ ) | Display IDs, brightness, night mode |
187- | [ ` audio_status ` ] ( examples/audio_status/ ) | Audio device info, volume state |
188- | [ ` power_status ` ] ( examples/power_status/ ) | Power supply state, charging info |
189- | [ ` storage_info ` ] ( examples/storage_info/ ) | Storage device stats, mount points |
190- | [ ` package_query ` ] ( examples/package_query/ ) | Package list, installation info |
191- | [ ` softap_manage ` ] ( examples/softap_manage/ ) | WiFi hotspot enable/disable, config |
192- | [ ` softap_wifi_hal ` ] ( examples/softap_wifi_hal/ ) | WiFi chip info, AP interface state |
193- | [ ` softap_tether_offload ` ] ( examples/softap_tether_offload/ ) | Tethering offload config, stats |
196+ | [ ` activity_manager ` ] ( examples/activity_manager/ ) | Process limits, monkey test flag, permission checks |
197+ | [ ` audio_status ` ] ( examples/audio_status/ ) | Audio device info, volume state |
198+ | [ ` battery_health ` ] ( examples/battery_health/ ) | Capacity, charge status, current draw |
199+ | [ ` camera_connect ` ] ( examples/camera_connect/ ) | Camera device connection with callback stub |
200+ | [ ` device_info ` ] ( examples/device_info/ ) | Device properties, build info |
201+ | [ ` display_info ` ] ( examples/display_info/ ) | Display IDs, brightness, night mode |
202+ | [ ` list_services ` ] ( examples/list_services/ ) | Enumerate all binder services, ping each |
203+ | [ ` package_query ` ] ( examples/package_query/ ) | Package list, installation info |
204+ | [ ` power_status ` ] ( examples/power_status/ ) | Power supply state, charging info |
205+ | [ ` softap_manage ` ] ( examples/softap_manage/ ) | WiFi hotspot enable/disable, config |
206+ | [ ` softap_tether_offload ` ] ( examples/softap_tether_offload/ ) | Tethering offload config, stats |
207+ | [ ` softap_wifi_hal ` ] ( examples/softap_wifi_hal/ ) | WiFi chip info, AP interface state |
208+ | [ ` storage_info ` ] ( examples/storage_info/ ) | Storage device stats, mount points |
209+
210+ <!-- END GENERATED EXAMPLES_TABLE -->
194211
195212## bindercli Quick Start
196213
@@ -1009,6 +1026,7 @@ See the full [bindercli reference](#bindercli) for all subcommands and more exam
10091026
10101027</details >
10111028
1029+
10121030<!-- END GENERATED PACKAGES -->
10131031
10141032### Commands and Tools
@@ -1073,31 +1091,28 @@ bindercli service transact SurfaceFlinger 64
10731091</details >
10741092
10751093<details >
1076- <summary >Get GPS coordinates</summary >
1094+ <!-- BEGIN GENERATED BINDERCLI_POWER -->
1095+
1096+ <summary >Query power and battery state</summary >
10771097
10781098``` bash
1079- # List all location providers
1080- bindercli android.location.ILocationManager get-all-providers
1081- # Example output: {"result":["passive","network","fused","gps_hardware","gps"]}
1082-
1083- # Check if GPS provider is enabled
1084- bindercli android.location.ILocationManager is-provider-enabled-for-user \
1085- --provider gps --userId 0
1086-
1087- # Get GNSS hardware info
1088- bindercli android.location.ILocationManager get-gnss-hardware-model-name
1089- # Example output: {"result":"S.LSI,K041,SPOTNAV_4.15.4_9_250930_R1_291847"}
1090-
1091- bindercli android.location.ILocationManager get-gnss-year-of-hardware
1092- # Example output: {"result":2023}
1093-
1094- # Get last known GPS location (returns Location parcelable with lat/lon/alt)
1095- bindercli android.location.ILocationManager get-last-location \
1096- --provider gps \
1097- --packageName com.android.shell \
1098- --attributionTag " "
1099+ # Check if screen is on
1100+ bindercli android.os.IPowerManager is-interactive
1101+ # Example output: {"result":true}
1102+
1103+ # Check power save mode
1104+ bindercli android.os.IPowerManager is-power-save-mode
1105+ # Example output: {"result":false}
1106+
1107+ # Check if device is in Doze mode
1108+ bindercli android.os.IPowerManager is-device-idle-mode
1109+ # Example output: {"result":false}
1110+
1111+ # Get battery health info
1112+ bindercli android.hardware.health.IHealth get-health-info
10991113```
11001114
1115+ <!-- END GENERATED BINDERCLI_POWER -->
11011116</details >
11021117
11031118<details >
@@ -1471,6 +1486,8 @@ flowchart TD
14711486
14721487### Generated Code
14731488
1489+ <!-- BEGIN GENERATED GENERATED_CODE -->
1490+
14741491For an AIDL interface like:
14751492
14761493``` java
@@ -1493,8 +1510,14 @@ package app
14931510const DescriptorIActivityManager = " android.app.IActivityManager"
14941511
14951512const (
1496- TransactionIActivityManagerGetProcessLimit = binder.FirstCallTransaction + 52
1497- TransactionIActivityManagerCheckPermission = binder.FirstCallTransaction + 8
1513+ TransactionIActivityManagerGetProcessLimit = binder.FirstCallTransaction + 51
1514+ TransactionIActivityManagerCheckPermission = binder.FirstCallTransaction + 8
1515+ // ...
1516+ )
1517+
1518+ const (
1519+ MethodIActivityManagerGetProcessLimit = " getProcessLimit"
1520+ MethodIActivityManagerCheckPermission = " checkPermission"
14981521 // ...
14991522)
15001523
@@ -1506,19 +1529,25 @@ type IActivityManager interface {
15061529}
15071530
15081531type ActivityManagerProxy struct {
1509- remote binder.IBinder
1532+ Remote binder.IBinder
15101533}
15111534
15121535func NewActivityManagerProxy (remote binder .IBinder ) *ActivityManagerProxy {
1513- return &ActivityManagerProxy{remote : remote}
1536+ return &ActivityManagerProxy{Remote : remote}
15141537}
15151538
15161539func (p *ActivityManagerProxy ) GetProcessLimit (ctx context .Context ) (int32 , error ) {
15171540 var _result int32
15181541 _data := parcel.New ()
1542+ defer _data.Recycle ()
15191543 _data.WriteInterfaceToken (DescriptorIActivityManager)
15201544
1521- _reply , _err := p.remote .Transact (ctx, TransactionIActivityManagerGetProcessLimit, 0 , _data)
1545+ _code , _err := p.Remote .ResolveCode (ctx, DescriptorIActivityManager, MethodIActivityManagerGetProcessLimit)
1546+ if _err != nil {
1547+ return _result, fmt.Errorf (" resolving %s .%s : % w" , DescriptorIActivityManager, MethodIActivityManagerGetProcessLimit, _err)
1548+ }
1549+
1550+ _reply , _err := p.Remote .Transact (ctx, _code, 0 , _data)
15221551 if _err != nil {
15231552 return _result, _err
15241553 }
@@ -1536,6 +1565,8 @@ func (p *ActivityManagerProxy) GetProcessLimit(ctx context.Context) (int32, erro
15361565}
15371566```
15381567
1568+ <!-- END GENERATED GENERATED_CODE -->
1569+
15391570### Supported AIDL Constructs
15401571
15411572| Construct | Example | Generated Go |
@@ -1692,6 +1723,6 @@ A [weekly workflow](.github/workflows/check-aosp-updates.yml) checks for new AOS
16921723│ ├── hardware/ HAL interfaces
16931724│ └── ... 666 packages total
16941725├── com/ AOSP com.android.* service proxies
1695- ├── examples/ 12 runnable examples
1726+ ├── examples/ 13 runnable examples
16961727└── .github/workflows/ CI configuration
16971728```
0 commit comments