feat: 支持通过 adb broadcast 远程设置定位坐标#393
Open
MSCMonster wants to merge 1 commit into
Open
Conversation
Register a dynamic BroadcastReceiver in ServiceGo that listens for
com.zcshou.gogogo.action.SET_LOCATION and reuses ServiceGoBinder.setPosition()
to update lat/lng/alt. Enables scripted / automated coordinate injection
without touching the UI; both GPS and NETWORK mock providers refresh within
100ms and the joystick current position is kept in sync.
Usage (service must be started from the UI first so the receiver is alive):
adb shell am broadcast -p com.zcshou.gogogo \
-a com.zcshou.gogogo.action.SET_LOCATION \
--ed lat <latitude> --ed lng <longitude> [--ed alt <altitude>]
README updated with the full command, parameter notes and caveats.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #176
改动概述
为
ServiceGo增加一个动态注册的BroadcastReceiver,监听自定义 actioncom.zcshou.gogogo.action.SET_LOCATION,复用已有的ServiceGoBinder.setPosition()路径更新经纬度与海拔。适用场景:自动化测试、脚本批量切换位置、CI 环境下的定位模拟等无需手动操作 UI 的场合。
使用方法
服务必须先通过 APP UI 启动一次(让 receiver 注册),随后可在 adb 中执行:
adb shell am broadcast -p com.zcshou.gogogo \ -a com.zcshou.gogogo.action.SET_LOCATION \ --ed lat <纬度> --ed lng <经度> [--ed alt <海拔>]示例(注入上海外滩):
adb shell am broadcast -p com.zcshou.gogogo \ -a com.zcshou.gogogo.action.SET_LOCATION \ --ed lat 31.2304 --ed lng 121.4737 --ed alt 10广播到达后,GPS 与 NETWORK 两个 mock provider 会在 100ms 内同步刷新,摇杆的当前位也会一并更新。
设计说明
ServiceGoBinder.setPosition()路径,没有引入新的位置写入逻辑onCreate()中initAdbReceiver()注册,onDestroy()中反注册(包了IllegalArgumentException兜底)ServiceGo仍保持exported=falselat ∈ [-90, 90]、lng ∈ [-180, 180],越界忽略;alt可选,缺省沿用当前值RECEIVER_EXPORTED显式 flag,注释中已留备忘,未来升 33+ 时一并加上取舍点(请 reviewer 决定是否需要加强)
当前实现 没有对调用方做鉴权,任意 APP 只要知道 action 名都能发广播改坐标。考虑到本身就是定位修改类工具、坐标本来就由用户决定,影响有限。如果维护者认为需要加强,可以追加 signature 级 permission 或
Binder.getCallingUid() == Process.SHELL_UID校验,欢迎在 review 中指出偏好,我会跟进调整。测试
在 Xiaomi 13 Ultra (HyperOS, Android 14) 上实测:
dumpsys activity broadcasts可见SET_LOCATIONfilter)31.2304, 121.4737注入后dumpsys location的 GPS / NETWORK providerlast mock location立即变更39.9087, 116.3975alt缺省时正确沿用mCurAlt