← Back to PRs

#22484: Android: add flashlight on/off control support

by ztechenbo open 2026-02-21 06:48 View on GitHub →
app: android extensions: phone-control size: S
## Summary Describe the problem and fix in 2–5 bullets: - Problem: Android 节点缺少控制手机闪光灯(手电筒)的功能,无法通过 openclaw 远程打开或关闭设备灯光 - Why it matters: 用户需要通过 AI 助手控制手机闪光灯,用于照明、信号等场景 - What changed: - 新增 `flashlight.on` 和 `flashlight.off` 命令支持 - 实现 `FlashlightHandler` 使用 Android CameraManager API 控制闪光灯 - 在 `phone-control` 扩展中添加 `flashlight` 命令组,支持权限管理 - 集成到节点命令分发器和运行时系统 - What did NOT change (scope boundary): - iOS 节点不受影响(仅 Android) - 现有相机、屏幕、位置等功能保持不变 - 不需要新的 Android 权限(使用现有 CAMERA 权限) ## Change Type (select all) - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Docs - [ ] Security hardening - [ ] Chore/infra ## Scope (select all touched areas) - [ ] Gateway / orchestration - [x] Skills / tool execution - [ ] Auth / tokens - [ ] Memory / storage - [x] Integrations - [x] API / contracts - [ ] UI / DX - [ ] CI/CD / infra ## Linked Issue/PR - Closes # - Related # ## User-visible / Behavior Changes 新增 Android 节点命令: - `flashlight.on` - 打开手机闪光灯 - `flashlight.off` - 关闭手机闪光灯 使用方式: 1. 通过 `phone-control` 扩展启用权限:`/phone arm flashlight` 2. 通过 CLI 调用:`openclaw nodes invoke --node <node-id> --command flashlight.on` ## Security Impact (required) - New permissions/capabilities? (`No`) - 使用现有 CAMERA 权限,无需新增权限 - Secrets/tokens handling changed? (`No`) - New/changed network calls? (`No`) - Command/tool execution surface changed? (`Yes`) - 新增两个节点命令 - Data access scope changed? (`No`) - If any `Yes`, explain risk + mitigation: - 新增命令通过 `phone-control` 扩展进行权限管理,默认在 deny 列表中,需要用户显式启用 - 命令仅控制设备硬件(闪光灯),不涉及数据访问或网络通信 - 错误处理完善,设备不支持闪光灯时返回明确错误信息 ## Repro + Verification ### Environment - OS: Android 12+ (API 31+) - Runtime/container: Android 节点应用 - Model/provider: N/A - Integration/channel (if any): Android 节点通过 Gateway WebSocket 连接 - Relevant config (redacted): ```json { "gateway": { "nodes": { "allowCommands": ["flashlight.on", "flashlight.off"] } } } ``` ### Steps 1. 在 Android 设备上安装并连接 openclaw 节点 2. 通过 `phone-control` 扩展启用权限:`/phone arm flashlight` 3. 通过 CLI 调用命令: ```bash openclaw nodes invoke --node <node-id> --command flashlight.on openclaw nodes invoke --node <node-id> --command flashlight.off ``` ### Expected - `flashlight.on` 命令执行后,手机闪光灯应打开 - `flashlight.off` 命令执行后,手机闪光灯应关闭 - 如果设备不支持闪光灯,应返回 `NO_FLASHLIGHT` 错误 ### Actual - 待实际设备测试验证 ## Evidence Attach at least one: - [ ] Failing test/log before + passing after - [ ] Trace/log snippets - [ ] Screenshot/recording - [ ] Perf numbers (if relevant) ## Human Verification (required) What you personally verified (not just CI), and how: - Verified scenarios: - 代码编译通过,无 lint 错误 - 命令注册和分发逻辑正确集成 - 错误处理覆盖设备无闪光灯、相机访问错误等场景 - Edge cases checked: - 设备不支持闪光灯的情况 - CameraManager 不可用的情况 - 相机访问权限被拒绝的情况 - What you did **not** verify: - 实际设备上的功能测试(需要 Android 设备) - 长时间运行稳定性 - 与其他相机功能(如拍照)同时使用的兼容性 ## Compatibility / Migration - Backward compatible? (`Yes`) - 完全向后兼容,仅新增功能 - Config/env changes? (`No`) - 无需配置变更 - Migration needed? (`No`) - 无需迁移步骤 - If yes, exact upgrade steps: N/A ## Failure Recovery (if this breaks) - How to disable/revert this change quickly: - 通过 `phone-control` 扩展禁用:`/phone disarm` - 或在配置中将 `flashlight.on` 和 `flashlight.off` 添加到 `gateway.nodes.denyCommands` - Files/config to restore: N/A - Known bad symptoms reviewers should watch for: - 如果设备相机正在使用(如正在拍照),可能无法同时控制闪光灯(Android 系统限制) - 某些设备可能不支持独立控制闪光灯 ## Risks and Mitigations List only real risks for this PR. Add/remove entries as needed. If none, write `None`. - Risk: 闪光灯可能与其他相机功能冲突(如正在使用相机时) - Mitigation: 错误处理会捕获并返回明确的错误信息,不会导致应用崩溃 - Risk: 某些 Android 设备可能不支持独立控制闪光灯 - Mitigation: 代码会检测设备是否支持闪光灯,不支持时返回 `NO_FLASHLIGHT` 错误 <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds flashlight control commands (`flashlight.on` and `flashlight.off`) to Android nodes, enabling remote control of the device flashlight through the OpenClaw gateway. The implementation follows existing patterns for Android node commands: - New `FlashlightHandler` uses Android's `CameraManager.setTorchMode()` API to control the flashlight - Commands are properly integrated into the `InvokeDispatcher` routing system - Permission management added to the `phone-control` extension with the new `flashlight` group - Error handling covers device capability detection and camera access errors **Issues found:** - Minor indentation inconsistency in `extensions/phone-control/index.ts` lines 118-121 <h3>Confidence Score: 4/5</h3> - Safe to merge after fixing the indentation issue - The implementation is well-structured and follows existing code patterns correctly. The flashlight functionality uses standard Android APIs appropriately with proper error handling. The only issue is a minor indentation inconsistency that needs correction. The code doesn't require camera permission checks because flashlight access through CameraManager uses the existing CAMERA permission already declared in the app. - extensions/phone-control/index.ts needs indentation fix at lines 118-121 <sub>Last reviewed commit: d25bec9</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs