Skip to content

Commit 80fa01f

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
Add aidlcli section with usage examples to README
1 parent 59ed16d commit 80fa01f

1 file changed

Lines changed: 310 additions & 0 deletions

File tree

README.md

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,316 @@ Requires access to `/dev/binder` on the target device (typically available as `s
11681168
| [`tools/cmd/gen_e2e_smoke`](tools/cmd/gen_e2e_smoke/) | Generates smoke tests exercising every proxy type in generated packages |
11691169
| [`tools/cmd/genreadme`](tools/cmd/genreadme/) | Regenerates the package table in this README from generated packages |
11701170

1171+
## aidlcli
1172+
1173+
`aidlcli` is a unified command-line tool for interacting with Android Binder services and the AIDL compiler. It auto-generates subcommands for every AIDL interface in the project (1,500+ interfaces, 12,000+ methods), so you can call any Android system service method directly from the command line with typed flags.
1174+
1175+
Build and deploy:
1176+
1177+
```bash
1178+
GOOS=linux GOARCH=arm64 go build -o aidlcli ./tools/cmd/aidlcli/
1179+
adb push aidlcli /data/local/tmp/
1180+
```
1181+
1182+
Core subcommands:
1183+
1184+
| Command | Description |
1185+
|---|---|
1186+
| `aidlcli service list` | List all registered binder services with alive/dead status |
1187+
| `aidlcli service inspect <name>` | Show a service's handle, descriptor, and alive status |
1188+
| `aidlcli service methods <name>` | List all methods available on a service |
1189+
| `aidlcli service transact <name> <code> [hex]` | Send a raw binder transaction |
1190+
| `aidlcli aidl compile [-I path] <files>` | Compile `.aidl` files to Go |
1191+
| `aidlcli aidl parse <file>` | Dump parsed AIDL AST as JSON |
1192+
| `aidlcli aidl check <files>` | Validate AIDL files without generating |
1193+
| `aidlcli <descriptor> <method> [--flags]` | Call any AIDL method with typed parameters |
1194+
1195+
Global flags: `--format json|text|auto`, `--binder-device`, `--map-size`.
1196+
1197+
### Examples
1198+
1199+
<details>
1200+
<summary>Get GPS coordinates</summary>
1201+
1202+
```bash
1203+
# Check if GPS provider is enabled
1204+
aidlcli android.location.ILocationManager is-provider-enabled-for-user \
1205+
--provider gps --userId 0
1206+
1207+
# List all location providers
1208+
aidlcli android.location.ILocationManager get-all-providers
1209+
1210+
# Get last known GPS location (returns Location parcelable with lat/lon/alt)
1211+
aidlcli android.location.ILocationManager get-last-location \
1212+
--provider gps \
1213+
--packageName com.android.shell \
1214+
--attributionTag ""
1215+
1216+
# Get GNSS hardware info
1217+
aidlcli android.location.ILocationManager get-gnss-hardware-model-name
1218+
aidlcli android.location.ILocationManager get-gnss-year-of-hardware
1219+
```
1220+
1221+
</details>
1222+
1223+
<details>
1224+
<summary>Connect to a WiFi AP with SSID "MyNetwork" and PSK "secret123"</summary>
1225+
1226+
```bash
1227+
# Step 1: Add a new network via the supplicant
1228+
aidlcli android.hardware.wifi.supplicant.ISupplicantStaIface add-network
1229+
1230+
# Step 2: Set the SSID (pass as hex-encoded bytes; "MyNetwork" = 4d794e6574776f726b)
1231+
aidlcli android.hardware.wifi.supplicant.ISupplicantStaNetwork set-ssid \
1232+
--ssid 4d794e6574776f726b
1233+
1234+
# Step 3: Set the WPA passphrase
1235+
aidlcli android.hardware.wifi.supplicant.ISupplicantStaNetwork set-psk-passphrase \
1236+
--psk secret123
1237+
1238+
# Step 4: Set key management to WPA-PSK (bit 1 = 0x02)
1239+
aidlcli android.hardware.wifi.supplicant.ISupplicantStaNetwork set-key-mgmt \
1240+
--keyMgmtMask 2
1241+
1242+
# Step 5: Enable the network to trigger connection
1243+
aidlcli android.hardware.wifi.supplicant.ISupplicantStaNetwork enable \
1244+
--noConnect false
1245+
1246+
# Disconnect from current network
1247+
aidlcli android.hardware.wifi.supplicant.ISupplicantStaIface disconnect
1248+
1249+
# List saved networks
1250+
aidlcli android.hardware.wifi.supplicant.ISupplicantStaIface list-networks
1251+
```
1252+
1253+
</details>
1254+
1255+
<details>
1256+
<summary>Take a picture from the camera</summary>
1257+
1258+
```bash
1259+
# List available camera devices
1260+
aidlcli android.hardware.camera.provider.ICameraProvider get-camera-id-list
1261+
1262+
# Get camera characteristics (resolution, capabilities, etc.)
1263+
aidlcli android.hardware.camera.device.ICameraDevice get-camera-characteristics
1264+
1265+
# Toggle flashlight/torch mode
1266+
aidlcli android.hardware.camera.provider.ICameraProvider set-torch-mode \
1267+
--cameraDeviceName "0" --enabled true
1268+
```
1269+
1270+
Note: Full camera capture requires a callback-driven session flow (open → configure streams → capture request → receive frames). The individual steps are available as commands, but the session orchestration needs a script or the Go API directly.
1271+
1272+
</details>
1273+
1274+
<details>
1275+
<summary>Record from microphone</summary>
1276+
1277+
```bash
1278+
# Get active microphones on an input stream
1279+
aidlcli android.hardware.audio.core.IStreamIn get-active-microphones
1280+
1281+
# Set microphone field dimension (for directional recording)
1282+
aidlcli android.hardware.audio.core.IStreamIn set-microphone-field-dimension \
1283+
--zoom 1.0
1284+
1285+
# Set microphone direction
1286+
# 0=UNSPECIFIED, 1=FRONT, 2=BACK, 3=EXTERNAL
1287+
aidlcli android.hardware.audio.core.IStreamIn set-microphone-direction \
1288+
--direction 1
1289+
```
1290+
1291+
Note: Actual audio capture requires opening an input stream via `IModule.openInputStream()` with an audio configuration, then reading PCM data from the returned stream handle. Use the Go API for the full recording flow.
1292+
1293+
</details>
1294+
1295+
<details>
1296+
<summary>Send a notification</summary>
1297+
1298+
```bash
1299+
# Notifications are managed through the NotificationManager service.
1300+
# Check if a notification channel exists:
1301+
aidlcli android.app.INotificationManager get-notification-channel \
1302+
--callingPkg com.android.shell \
1303+
--userId 0 \
1304+
--pkg com.android.shell \
1305+
--channelId default
1306+
1307+
# Get notification policy (DND settings)
1308+
aidlcli android.app.INotificationManager get-notification-policy \
1309+
--pkg com.android.shell
1310+
1311+
# Check notification access
1312+
aidlcli android.app.INotificationManager is-notification-policy-access-granted \
1313+
--pkg com.android.shell
1314+
1315+
# Cancel a notification by tag and ID
1316+
aidlcli android.app.INotificationManager cancel-notification-with-tag \
1317+
--pkg com.android.shell \
1318+
--opPkg com.android.shell \
1319+
--tag "" \
1320+
--id 1 \
1321+
--userId 0
1322+
```
1323+
1324+
Note: Posting a new notification requires building a `Notification` parcelable with icon, title, text, channel, and other fields. Use `aidlcli service transact` with a pre-built parcel or the Go API.
1325+
1326+
</details>
1327+
1328+
<details>
1329+
<summary>Query battery and thermal status</summary>
1330+
1331+
```bash
1332+
# Get battery health status
1333+
aidlcli android.hardware.health.IHealth get-health-info
1334+
1335+
# Get charge status
1336+
aidlcli android.hardware.health.IHealth get-charge-status
1337+
1338+
# Get battery capacity percentage
1339+
aidlcli android.hardware.health.IHealth get-capacity
1340+
1341+
# Get current thermal status
1342+
aidlcli android.os.IThermalService get-current-thermal-status
1343+
1344+
# Check if device is in power save mode
1345+
aidlcli android.os.IPowerManager is-power-save-mode
1346+
1347+
# Check if device is interactive (screen on)
1348+
aidlcli android.os.IPowerManager is-interactive
1349+
1350+
# Reboot the device
1351+
aidlcli android.os.IPowerManager reboot \
1352+
--confirm false --reason "cli-reboot" --wait true
1353+
```
1354+
1355+
</details>
1356+
1357+
<details>
1358+
<summary>Query packages and app info</summary>
1359+
1360+
```bash
1361+
# Check if a package is installed
1362+
aidlcli android.content.pm.IPackageManager is-package-available \
1363+
--packageName com.android.settings --userId 0
1364+
1365+
# Get package info
1366+
aidlcli android.content.pm.IPackageManager get-package-info \
1367+
--packageName com.android.settings --flags 0 --userId 0
1368+
1369+
# Get the installer of a package
1370+
aidlcli android.content.pm.IPackageManager get-installer-package-name \
1371+
--packageName com.android.chrome
1372+
1373+
# Check a permission
1374+
aidlcli android.content.pm.IPackageManager check-permission \
1375+
--permName android.permission.INTERNET \
1376+
--pkgName com.android.chrome --userId 0
1377+
```
1378+
1379+
</details>
1380+
1381+
<details>
1382+
<summary>Manage display and brightness</summary>
1383+
1384+
```bash
1385+
# Get physical display IDs
1386+
aidlcli android.hardware.display.IDisplayManager get-display-ids \
1387+
--includeDisabled false
1388+
1389+
# Get display brightness
1390+
aidlcli android.hardware.display.IDisplayManager get-brightness \
1391+
--displayId 0
1392+
1393+
# Set display brightness
1394+
aidlcli android.hardware.display.IDisplayManager set-brightness \
1395+
--displayId 0 --brightness 0.5
1396+
```
1397+
1398+
</details>
1399+
1400+
<details>
1401+
<summary>Bluetooth operations</summary>
1402+
1403+
```bash
1404+
# Initialize Bluetooth HCI
1405+
aidlcli android.hardware.bluetooth.IBluetoothHci initialize \
1406+
--callback <callback_service>
1407+
1408+
# Send raw HCI command (hex bytes)
1409+
aidlcli android.hardware.bluetooth.IBluetoothHci send-hci-command \
1410+
--command 01030c00
1411+
1412+
# Close Bluetooth HCI
1413+
aidlcli android.hardware.bluetooth.IBluetoothHci close
1414+
```
1415+
1416+
</details>
1417+
1418+
<details>
1419+
<summary>Clipboard operations</summary>
1420+
1421+
```bash
1422+
# Check if clipboard has text
1423+
aidlcli android.content.IClipboard has-clipboard-text \
1424+
--callingPackage com.android.shell \
1425+
--attributionTag "" --userId 0 --deviceId 0
1426+
1427+
# Get primary clipboard content
1428+
aidlcli android.content.IClipboard get-primary-clip \
1429+
--pkg com.android.shell \
1430+
--attributionTag "" --userId 0 --deviceId 0
1431+
```
1432+
1433+
</details>
1434+
1435+
<details>
1436+
<summary>Telephony and SMS</summary>
1437+
1438+
```bash
1439+
# Get device IMEI
1440+
aidlcli com.android.internal.telephony.ITelephony get-imei-for-slot \
1441+
--slotIndex 0 --callingPackage com.android.shell --callingFeatureId ""
1442+
1443+
# Check if phone is ringing
1444+
aidlcli com.android.internal.telephony.ITelephony is-ringing \
1445+
--callingPackage com.android.shell
1446+
1447+
# Get active phone type (0=NONE, 1=GSM, 2=CDMA)
1448+
aidlcli com.android.internal.telephony.ITelephony get-active-phone-type
1449+
1450+
# Get network country ISO
1451+
aidlcli com.android.internal.telephony.ITelephony get-network-country-iso-for-phone \
1452+
--phoneId 0 --callingPackage com.android.shell --callingFeatureId ""
1453+
```
1454+
1455+
</details>
1456+
1457+
<details>
1458+
<summary>ActivityManager queries</summary>
1459+
1460+
```bash
1461+
# Check if user is a monkey (automated test)
1462+
aidlcli android.app.IActivityManager is-user-a-monkey
1463+
1464+
# Get process memory limit
1465+
aidlcli android.app.IActivityManager get-process-limit
1466+
1467+
# Check a permission for a process
1468+
aidlcli android.app.IActivityManager check-permission \
1469+
--permission android.permission.INTERNET --pid 1 --uid 0
1470+
1471+
# Force stop a package
1472+
aidlcli android.app.IActivityManager force-stop-package \
1473+
--packageName com.example.app --userId 0
1474+
1475+
# Check if app freezer is supported
1476+
aidlcli android.app.IActivityManager is-app-freezer-supported
1477+
```
1478+
1479+
</details>
1480+
11711481
## Architecture
11721482

11731483
The project has two major parts: a **compiler** that turns `.aidl` files into Go source code, and a **runtime** that implements the Binder IPC protocol for communicating with Android services.

0 commit comments

Comments
 (0)