fix(设备端): 轮询不再用打码名覆盖广播的完整昵称

- push_account_name 成功后把完整名记进 device.cur_account_name
- /api/device/agent/account 在 dumpsys 打码名与完整名匹配时返回完整名
- cache_names 不再用匹配的打码名覆盖完整名
- 增加 mask_matches 用例
This commit is contained in:
2026-10-19 11:14:17 +08:00
parent c91b01524d
commit 3a6681c7b1
3 changed files with 77 additions and 2 deletions
+12 -1
View File
@@ -154,8 +154,19 @@ 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
from core.account_probe import probe_one_dumpsys, mask_matches
r = probe_one_dumpsys(serial, timeout=timeout)
# 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)
else:
r = {"serial": serial, "name": "", "masked": False, "last_switch": "",
"error": "无法识别设备(缺 serial)"}