Skip to content

Commit 86fb55a

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
docs: add ndkcli section with 17 usage examples to README
Covers: camera capture, audio record/play, sensors, thermal monitoring, EGL/GL info, media codecs, config, image decode, fonts, permissions, trace/logging, NNAPI, storage, looper, and window queries. Each example shows the exact adb shell commands to run on a device.
1 parent fb350fa commit 86fb55a

1 file changed

Lines changed: 273 additions & 0 deletions

File tree

README.md

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,279 @@ func main() {
10191019

10201020
</details>
10211021

1022+
## ndkcli
1023+
1024+
`ndkcli` is a cobra-based CLI tool that exposes the full NDK surface from the command line. It is auto-generated by `tools/cmd/cligen/` and includes hand-written workflow commands for end-to-end operations.
1025+
1026+
### Build & deploy
1027+
1028+
```bash
1029+
# Build for Android (requires NDK)
1030+
make ndkcli
1031+
1032+
# Push to device
1033+
adb push ndkcli /data/local/tmp/
1034+
adb shell chmod +x /data/local/tmp/ndkcli
1035+
```
1036+
1037+
### List all commands
1038+
1039+
```bash
1040+
# From source (no Android needed):
1041+
make ndkcli-commands
1042+
1043+
# On device:
1044+
adb shell /data/local/tmp/ndkcli --help
1045+
adb shell /data/local/tmp/ndkcli camera --help
1046+
```
1047+
1048+
### Examples
1049+
1050+
<details>
1051+
<summary>List available cameras and their characteristics</summary>
1052+
1053+
```bash
1054+
# List camera IDs
1055+
adb shell /data/local/tmp/ndkcli camera manager camera-id-list
1056+
1057+
# Show full details (lens facing, orientation, hardware level) for all cameras
1058+
adb shell /data/local/tmp/ndkcli camera list-details
1059+
1060+
# Query characteristics for a specific camera
1061+
adb shell /data/local/tmp/ndkcli camera manager get-camera-characteristics --camera-id 0
1062+
```
1063+
1064+
</details>
1065+
1066+
<details>
1067+
<summary>Capture raw frames from the camera</summary>
1068+
1069+
```bash
1070+
# Capture 10 frames from camera 0 at 640x480 in RGBA format, save to file
1071+
adb shell /data/local/tmp/ndkcli camera capture \
1072+
--id 0 --width 640 --height 480 --format 1 --count 10 \
1073+
--output /data/local/tmp/frames.raw
1074+
```
1075+
1076+
</details>
1077+
1078+
<details>
1079+
<summary>Record audio from the microphone</summary>
1080+
1081+
```bash
1082+
# Record 5 seconds of mono 44.1kHz PCM16 audio
1083+
adb shell /data/local/tmp/ndkcli audio record \
1084+
--output /data/local/tmp/recording.pcm \
1085+
--duration 5s --sample-rate 44100 --channels 1
1086+
1087+
# Record 10 seconds of stereo 48kHz audio
1088+
adb shell /data/local/tmp/ndkcli audio record \
1089+
--output /data/local/tmp/stereo.pcm \
1090+
--duration 10s --sample-rate 48000 --channels 2
1091+
```
1092+
1093+
</details>
1094+
1095+
<details>
1096+
<summary>Play back recorded audio</summary>
1097+
1098+
```bash
1099+
# Play a previously recorded PCM file
1100+
adb shell /data/local/tmp/ndkcli audio play \
1101+
--input /data/local/tmp/recording.pcm \
1102+
--sample-rate 44100 --channels 1
1103+
```
1104+
1105+
</details>
1106+
1107+
<details>
1108+
<summary>Query audio system capabilities</summary>
1109+
1110+
```bash
1111+
# Open a probe stream and print audio properties
1112+
adb shell /data/local/tmp/ndkcli audio stream-builder new
1113+
adb shell /data/local/tmp/ndkcli audio stream channel-count
1114+
adb shell /data/local/tmp/ndkcli audio stream sample-rate
1115+
adb shell /data/local/tmp/ndkcli audio stream frames-per-burst
1116+
```
1117+
1118+
</details>
1119+
1120+
<details>
1121+
<summary>List sensors and read sensor data</summary>
1122+
1123+
```bash
1124+
# List all available sensors (probes known types)
1125+
adb shell /data/local/tmp/ndkcli sensor read --type 1 # Accelerometer
1126+
adb shell /data/local/tmp/ndkcli sensor read --type 4 # Gyroscope
1127+
adb shell /data/local/tmp/ndkcli sensor read --type 5 # Light
1128+
1129+
# Query a specific sensor by type number
1130+
adb shell /data/local/tmp/ndkcli sensor manager default-sensor --value 1
1131+
adb shell /data/local/tmp/ndkcli sensor sensor name
1132+
adb shell /data/local/tmp/ndkcli sensor sensor vendor
1133+
adb shell /data/local/tmp/ndkcli sensor sensor resolution
1134+
```
1135+
1136+
</details>
1137+
1138+
<details>
1139+
<summary>Check thermal status</summary>
1140+
1141+
```bash
1142+
# One-shot thermal status
1143+
adb shell /data/local/tmp/ndkcli thermal manager current-status
1144+
1145+
# Monitor thermal status every 2 seconds for 30 seconds
1146+
adb shell /data/local/tmp/ndkcli thermal monitor --interval 2s --duration 30s
1147+
```
1148+
1149+
</details>
1150+
1151+
<details>
1152+
<summary>Query EGL and GPU capabilities</summary>
1153+
1154+
```bash
1155+
# EGL display information (vendor, version, extensions)
1156+
adb shell /data/local/tmp/ndkcli egl info
1157+
1158+
# List EGL configurations
1159+
adb shell /data/local/tmp/ndkcli egl configs
1160+
1161+
# OpenGL ES 2.0 info (creates pbuffer context, queries GL strings)
1162+
adb shell /data/local/tmp/ndkcli gles2 info
1163+
1164+
# OpenGL ES 3.0 info
1165+
adb shell /data/local/tmp/ndkcli gles3 info
1166+
```
1167+
1168+
</details>
1169+
1170+
<details>
1171+
<summary>Probe available media codecs</summary>
1172+
1173+
```bash
1174+
# Check which codecs are available (H.264, H.265, VP8/9, AV1, AAC, etc.)
1175+
adb shell /data/local/tmp/ndkcli media codecs
1176+
1177+
# Create specific encoder/decoder
1178+
adb shell /data/local/tmp/ndkcli media new-encoder --mime_type video/avc
1179+
adb shell /data/local/tmp/ndkcli media new-decoder --mime_type audio/mp4a-latm
1180+
1181+
# Probe a media file
1182+
adb shell /data/local/tmp/ndkcli media probe --file /sdcard/video.mp4
1183+
```
1184+
1185+
</details>
1186+
1187+
<details>
1188+
<summary>Read device configuration</summary>
1189+
1190+
```bash
1191+
# Show all configuration values (density, orientation, screen, SDK version)
1192+
adb shell /data/local/tmp/ndkcli config show
1193+
1194+
# Individual queries
1195+
adb shell /data/local/tmp/ndkcli config config density
1196+
adb shell /data/local/tmp/ndkcli config config sdk-version
1197+
adb shell /data/local/tmp/ndkcli config config screen-width-dp
1198+
adb shell /data/local/tmp/ndkcli config config orientation
1199+
```
1200+
1201+
</details>
1202+
1203+
<details>
1204+
<summary>Decode an image file</summary>
1205+
1206+
```bash
1207+
# Decode a JPEG/PNG and print dimensions, stride, format
1208+
adb shell /data/local/tmp/ndkcli image decode --file /sdcard/photo.jpg
1209+
1210+
# Decode with target size (downscale)
1211+
adb shell /data/local/tmp/ndkcli image decode --file /sdcard/photo.jpg --width 320 --height 240
1212+
```
1213+
1214+
</details>
1215+
1216+
<details>
1217+
<summary>Match system fonts</summary>
1218+
1219+
```bash
1220+
# Find a matching font by family name and weight
1221+
adb shell /data/local/tmp/ndkcli font match --family sans-serif --weight 400
1222+
adb shell /data/local/tmp/ndkcli font match --family serif --weight 700 --italic
1223+
```
1224+
1225+
</details>
1226+
1227+
<details>
1228+
<summary>Check permissions</summary>
1229+
1230+
```bash
1231+
# Check if a permission is granted for a PID/UID
1232+
adb shell /data/local/tmp/ndkcli permission check \
1233+
--name android.permission.CAMERA --pid 1000 --uid 1000
1234+
```
1235+
1236+
</details>
1237+
1238+
<details>
1239+
<summary>Trace and logging</summary>
1240+
1241+
```bash
1242+
# Check if tracing is enabled
1243+
adb shell /data/local/tmp/ndkcli trace is-enabled
1244+
1245+
# Add a trace marker
1246+
adb shell /data/local/tmp/ndkcli trace begin-section --section-name "my_operation"
1247+
adb shell /data/local/tmp/ndkcli trace end-section
1248+
1249+
# Set a trace counter
1250+
adb shell /data/local/tmp/ndkcli trace set-counter --counter-name "frames" --counter-value 42
1251+
1252+
# Write to Android log
1253+
adb shell /data/local/tmp/ndkcli log write --tag myapp --message "hello from ndkcli" --priority 4
1254+
```
1255+
1256+
</details>
1257+
1258+
<details>
1259+
<summary>NNAPI (Neural Networks) probe</summary>
1260+
1261+
```bash
1262+
# Check if NNAPI is available
1263+
adb shell /data/local/tmp/ndkcli nnapi probe
1264+
1265+
# Create and inspect a model
1266+
adb shell /data/local/tmp/ndkcli nnapi model new
1267+
```
1268+
1269+
</details>
1270+
1271+
<details>
1272+
<summary>Storage and OBB</summary>
1273+
1274+
```bash
1275+
# Check OBB mount status
1276+
adb shell /data/local/tmp/ndkcli storage obb --file /sdcard/main.obb
1277+
adb shell /data/local/tmp/ndkcli storage manager is-obb-mounted --filename /sdcard/main.obb
1278+
```
1279+
1280+
</details>
1281+
1282+
<details>
1283+
<summary>Looper and window utilities</summary>
1284+
1285+
```bash
1286+
# Test looper functionality (prepare, wake, poll)
1287+
adb shell /data/local/tmp/ndkcli looper test
1288+
1289+
# Query window properties via ImageReader-backed window
1290+
adb shell /data/local/tmp/ndkcli window query
1291+
```
1292+
1293+
</details>
1294+
10221295
## Supported Modules
10231296

10241297
| NDK Module | Go Package | Import Path |

0 commit comments

Comments
 (0)