# -*- coding: utf-8 -*- """第三批:补回被误删的字段,并修 runDiagnostics() 的调用点。 又缺: frameCount int 帧计数 currentFps float (0f) fpsWindowStart long (System.currentTimeMillis()) logBuffer StringBuilder (insert/length/setLength/toString) 以及 3016 行还在调已删掉的 runDiagnostics()。 """ from __future__ import annotations import sys from pathlib import Path MAIN = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\android\src" r"\com\lanremote\watch\MainActivity.java") ANCHOR = ''' // 正在接收的文件缓冲 + 文件名 private ByteArrayOutputStream incoming; private String incomingName = "";''' NEW = ANCHOR + ''' // 屏幕镜像的帧率统计 private int frameCount; private float currentFps; private long fpsWindowStart; // 界面日志缓冲(限制长度,免得越滚越长) private final StringBuilder logBuffer = new StringBuilder();''' CALL_OLD = " public void run() { runDiagnostics(); }" CALL_NEW = (" public void run() {\n" " // 设备诊断已按用户要求移除\n" " appendLog(\"设备诊断已移除\");\n" " }") def main() -> int: text = MAIN.read_text(encoding="utf-8") ok = True if "private int frameCount;" in text: print(" 帧率字段已在") elif ANCHOR in text: text = text.replace(ANCHOR, NEW, 1) print(" 补回 frameCount / currentFps / fpsWindowStart / logBuffer") else: print(" [失败] 找不到字段锚点") ok = False if CALL_OLD in text: text = text.replace(CALL_OLD, CALL_NEW, 1) print(" 修掉 runDiagnostics() 的调用点") else: print(f" runDiagnostics 剩余引用 {text.count('runDiagnostics')} 处") MAIN.write_text(text, encoding="utf-8", newline="\n") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())