Files
auto_control/scripts/tests/test_dumpsys_account.py
T
butubb 3a6681c7b1 fix(设备端): 轮询不再用打码名覆盖广播的完整昵称
- push_account_name 成功后把完整名记进 device.cur_account_name
- /api/device/agent/account 在 dumpsys 打码名与完整名匹配时返回完整名
- cache_names 不再用匹配的打码名覆盖完整名
- 增加 mask_matches 用例
2026-10-19 11:14:17 +08:00

76 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
"""`dumpsys account` 解析用例(纯字符串,不连设备、不连库)。"""
import base64
import io
import os
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
os.chdir(sys.path[0])
from core import account_probe as ap # noqa: E402
from core.account_probe import parse_dumpsys_account # noqa: E402
fails = []
def check(label, got, want):
ok = got == want
if not ok:
fails.append(label)
print((' ✅ ' if ok else ' ❌ ') + label + ('' if ok else '\n 得到 %r\n 期望 %r' % (got, want)))
SAMPLE = """
Accounts: 2
Account {name=锋哥苏***实录, type=com.ss.android.ugc.aweme}
Account {[email protected], type=com.xiaomi}
AccountId,Action,Time,User,Accounts,Key
1,action_account_add,2026-10-18 09:00:00,10123,accounts,0
2,action_account_add,2026-10-18 10:00:00,10199,accounts,0
AuthenticatorDescription {type=com.ss.android.ugc.aweme}, uid 10123
"""
print('=== 1. 读出抖音账号 / 打码标记 / uid / 最近切号时间 ===')
r = parse_dumpsys_account(SAMPLE)
check('昵称(MIUI 打码)', r['name'], '锋哥苏***实录')
check('打码标记', r['masked'], True)
check('uid', r['uid'], '10123')
check('只取该 uid 的最近切号时间', r['last_switch'], '2026-10-18 09:00:00')
print('=== 2. 没有抖音账号 ===')
r = parse_dumpsys_account("Accounts: 1\n Account {name=abc, type=com.xiaomi}")
check('name 为空', r['name'], '')
check('masked=False', r['masked'], False)
print('=== 3. push_account_name 走广播(假 adb,不连设备)===')
_calls = []
_orig_adb = ap.adb_helper._adb
ap.adb_helper._adb = lambda *a, **kw: (
_calls.append(a), "Broadcast completed: result=0"
)[1]
try:
ok, msg = ap.push_account_name("A:5555", "锋哥苏***实录")
finally:
ap.adb_helper._adb = _orig_adb
check('返回 ok', ok, True)
check('消息', msg, '已下发 锋哥苏***实录')
check('显式广播组件', _calls[0][5:7],
("-n", "com.example.deviceagent/.AccountReceiver"))
check('使用 name_b64', _calls[0][10], "name_b64")
check('base64 是标准编码', base64.b64decode(_calls[0][11]).decode("utf-8"),
"锋哥苏***实录")
print('=== 4. 打码名 ↔ 完整名 匹配 ===')
check('前缀+后缀都对得上', ap.mask_matches('锋哥苏***探访', '锋哥苏州百业探访'), True)
check('前缀对、后缀不对 → 不匹配', ap.mask_matches('锋哥苏***探访', '锋哥苏州创业实录'), False)
check('没打码 → 全等', ap.mask_matches('同一名字', '同一名字'), True)
check('没打码但不是同一个 → 不匹配', ap.mask_matches('名字甲', '名字乙'), False)
print()
if fails:
print('❌ 失败 %d 项:%s' % (len(fails), ' / '.join(fails)))
sys.exit(1)
print('✅ test_dumpsys_account 全部通过(纯解析,没连设备)')