Files
auto_control/scripts/tests/test_dumpsys_account.py
T
butubb c91b01524d feat(设备端): 素材页轮询当前账号 + 切号/读名后广播下发
- 新增 GET /api/device/agent/account(adb dumpsys account,1.5s 缓存)
- push_account_name() 广播给设备端 AccountReceiver,不抢焦点
- switch_account 切号成功 / read_account_name 读名成功后自动推送
- probe_one_dumpsys 支持 timeout(HTTP 轮询用 5s)
- 测试与 DEVICE_AGENT/API 文档同步
2026-10-19 11:05:55 +08:00

70 lines
2.5 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()
if fails:
print('❌ 失败 %d 项:%s' % (len(fails), ' / '.join(fails)))
sys.exit(1)
print('✅ test_dumpsys_account 全部通过(纯解析,没连设备)')