feat(设备端): 每 5 秒账号巡检 + 打码名按账号库还原
- 后台线程每 5s 并行探测所有在线设备,账号变化才广播下发 - resolve_masked_name:锋哥苏***探访 → 账号库唯一匹配的完整昵称 - /api/device/agent/account 同一套还原(平台/手机手动切号都覆盖) - 多匹配用上次完整名 tiebreak,分不清不猜 - ACCOUNT_WATCH=0 可关闭;测试/文档同步
This commit is contained in:
+6
-11
@@ -154,19 +154,14 @@ def _account_cached(serial, fp, timeout=5):
|
||||
if hit and now - hit[0] < _ACCOUNT_CACHE_TTL:
|
||||
return hit[1]
|
||||
if serial:
|
||||
from core.account_probe import probe_one_dumpsys, mask_matches
|
||||
from core.account_probe import probe_one_dumpsys, resolve_masked_name
|
||||
r = probe_one_dumpsys(serial, timeout=timeout)
|
||||
# dumpsys 在 MIUI 上会把昵称打码;如果平台刚广播过完整昵称,
|
||||
# 且打码名与它匹配,就返回完整名(否则设备端轮询会把完整名覆盖成 ***)。
|
||||
# dumpsys 在 MIUI 上会把昵称打码;按账号库还原成完整名
|
||||
# (平台切号、手机手动切号都适用;还原不出才返回打码名)。
|
||||
if not r.get("error") and r.get("masked"):
|
||||
try:
|
||||
from core.models import Device
|
||||
row = Device.query.get(serial)
|
||||
full = ((row.cur_account_name or "").strip() if row else "")
|
||||
if full and "*" not in full and mask_matches(r.get("name"), full):
|
||||
r = dict(r, name=full, masked=False, source="platform")
|
||||
except Exception as e:
|
||||
_log.warning("读取完整账号名失败(继续用打码名): %s", e)
|
||||
full = resolve_masked_name(serial, r.get("name"))
|
||||
if full:
|
||||
r = dict(r, name=full, masked=False, source="roster")
|
||||
else:
|
||||
r = {"serial": serial, "name": "", "masked": False, "last_switch": "",
|
||||
"error": "无法识别设备(缺 serial)"}
|
||||
|
||||
Reference in New Issue
Block a user