Skip to content

awa 泠云酱好可爱!!! - #10

Open
XFJ-YYQF wants to merge 2 commits into
ReCloudStudio:mainfrom
XFJ-YYQF:main
Open

awa 泠云酱好可爱!!!#10
XFJ-YYQF wants to merge 2 commits into
ReCloudStudio:mainfrom
XFJ-YYQF:main

Conversation

@XFJ-YYQF

@XFJ-YYQF XFJ-YYQF commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

1.新增了一个后台进程做处理,防止system_server 主线程被占用的情况下,系统直接卡死,最终触发 Watchdog 杀掉 system_server
2.缓存进程的名字,在15s的期间不会完整再走一遍扫描和检查之类的,或许能减少些资源占用(?
3.减少了管道死锁的风险,防止媒体状态太多阻塞了,导致全部爆炸!!
4.ModuleHooks.kt我寻思也没用到啊,哪个啥子ai写的,滚出去滚出去

总结:提高系统的稳定性,优化系统的流畅度()


This change is Reviewable

Summary by CodeRabbit

  • 性能与稳定性

    • 优化前台应用监控,减少系统服务线程阻塞,提升后台任务处理稳定性。
    • 改进媒体状态读取,避免进程输出导致卡死或超时。
    • 将状态刷新移至 IO 线程,减少界面与主线程负担。
  • 兼容性

    • 增强遗留 Xposed 模块加载兼容性,避免相关模块在构建后失效。

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

本次变更为前台监控增加专用后台线程和反射缓存,修复 dumpsys media_session 输出读取阻塞,将状态收集移至 Dispatchers.IO,并新增 Legacy Xposed 的 R8 保活规则。

Changes

运行时稳定性与模块兼容性

Layer / File(s) Summary
前台监控后台线程调度
app/src/main/java/io/github/recloudstudio/sleepyxposed/ForegroundAppMonitor.kt
ForegroundAppMonitor 使用 HandlerThread 执行配置加载、锁屏广播、心跳、应用查询和自定义操作。前台恢复钩子只同步读取内存字段。反射字段解析增加并发缓存。跨用户包匹配标志同步更新。
媒体与状态 I/O 调度
app/src/main/java/io/github/recloudstudio/sleepyxposed/MediaStatusMonitor.kt, app/src/main/java/io/github/recloudstudio/sleepyxposed/ui/SleepyApp.kt
readViaDumpsys 在线程中持续读取进程输出,并在等待结束后解析已捕获内容。StatusSnapshot.collect(context) 改用 Dispatchers.IO
Legacy Xposed 入口保活
app/proguard-rules.pro
R8 保留 LegacyEntry,并保留所有实现 IXposedHookLoadPackage 的类。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant XposedHook
  participant ForegroundAppMonitor
  participant HandlerThread
  participant AndroidSystem
  XposedHook->>ForegroundAppMonitor: 恢复钩子读取前台包名和活动名
  ForegroundAppMonitor->>HandlerThread: 投递心跳、查询和自定义操作
  HandlerThread->>AndroidSystem: 查询应用信息并注册锁屏接收器
  AndroidSystem-->>HandlerThread: 返回查询结果或广播回调
Loading

Possibly related PRs

Suggested reviewers: rhencloud

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning 标题“awa 泠云酱好可爱!!!”与后台处理、I/O 阻塞修复及稳定性优化无关。 将标题改为简洁、明确地描述主要变更,例如“修复后台 I/O 阻塞并优化前台应用监控”。
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
app/src/main/java/io/github/recloudstudio/sleepyxposed/ForegroundAppMonitor.kt (1)

225-242: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

缓存缺失字段时不要返回 null

ConcurrentHashMap.computeIfAbsent 在 mapping 函数返回 null 时不会保存映射。当前代码不会缓存缺失字段。缺少 OEM 字段时,每次 activity resume 都会再次遍历继承链。

使用非空哨兵值表示字段缺失,或缓存一个非空包装类型。这样才可以实现负缓存。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/main/java/io/github/recloudstudio/sleepyxposed/ForegroundAppMonitor.kt`
around lines 225 - 242, Update the fieldCache logic in ForegroundAppMonitor
around the computeIfAbsent call so missing fields are represented by a non-null
sentinel or wrapper and therefore cached by ConcurrentHashMap. Ensure field
lookup still traverses the superclass chain once and callers correctly interpret
the sentinel as an absent field.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@app/src/main/java/io/github/recloudstudio/sleepyxposed/MediaStatusMonitor.kt`:
- Around line 248-249: 在读取线程处理逻辑中检查 readerThread.join(...) 返回后的
readerThread.isAlive 状态;若线程仍存活,记录读取超时并立即返回 null,禁止继续调用
outputRef.toString(),仅在线程结束后解析完整输出。
- Around line 222-239: 在 MediaStatusMonitor 中负责读取 dumpsys 输出的 readerThread 逻辑里,为
outputRef 设置明确的最大输出字节数;读取过程中一旦达到上限,立即停止读取并销毁子进程,随后让调用流程返回
null,禁止继续解析不完整的输出。保留正常结束和超时关闭流的现有处理。

---

Nitpick comments:
In
`@app/src/main/java/io/github/recloudstudio/sleepyxposed/ForegroundAppMonitor.kt`:
- Around line 225-242: Update the fieldCache logic in ForegroundAppMonitor
around the computeIfAbsent call so missing fields are represented by a non-null
sentinel or wrapper and therefore cached by ConcurrentHashMap. Ensure field
lookup still traverses the superclass chain once and callers correctly interpret
the sentinel as an absent field.
🪄 Autofix

❌ Autofix failed (check again to retry)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 54e75374-ee42-4b1b-b389-9f79c0400c81

📥 Commits

Reviewing files that changed from the base of the PR and between 870eeea and 45a14ca.

📒 Files selected for processing (4)
  • app/proguard-rules.pro
  • app/src/main/java/io/github/recloudstudio/sleepyxposed/ForegroundAppMonitor.kt
  • app/src/main/java/io/github/recloudstudio/sleepyxposed/MediaStatusMonitor.kt
  • app/src/main/java/io/github/recloudstudio/sleepyxposed/ui/SleepyApp.kt

Comment on lines +222 to +239
val outputRef = StringBuilder()
val reader = process.inputStream
val readerThread =
Thread {
try {
BufferedReader(InputStreamReader(reader)).use { br ->
val buf = CharArray(4096)
while (true) {
val n = br.read(buf)
if (n < 0) break
outputRef.append(buf, 0, n)
}
}
} catch (_: IOException) {
// Stream closed because we destroyed the process on timeout; ignore.
}
}
.also { it.isDaemon = true; it.start() }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

限制 dumpsys 输出的最大缓存量。

outputRef 没有容量上限。dumpsys media_session 输出越大,system_server 的堆分配越大。此变更消除了管道背压,但把风险转移为无界内存增长。

设置最大输出大小。达到上限时停止读取、销毁子进程并返回 null,不要继续解析不完整输出。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/io/github/recloudstudio/sleepyxposed/MediaStatusMonitor.kt`
around lines 222 - 239, 在 MediaStatusMonitor 中负责读取 dumpsys 输出的 readerThread
逻辑里,为 outputRef 设置明确的最大输出字节数;读取过程中一旦达到上限,立即停止读取并销毁子进程,随后让调用流程返回
null,禁止继续解析不完整的输出。保留正常结束和超时关闭流的现有处理。

Comment on lines +248 to +249
readerThread.join(TimeUnit.SECONDS.toMillis(DUMPSYS_TIMEOUT_SECONDS))
val output = outputRef.toString()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

仅在读取线程结束后解析输出。

readerThread.join(...) 有超时,但代码未检查 readerThread.isAlive。如果读取线程仍在追加内容,outputRef.toString() 会与 StringBuilder.append() 并发执行,并且可能解析部分或不一致的媒体状态。

如果 join 超时,记录读取超时并返回 null。不要读取仍在被写入的 outputRef

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/io/github/recloudstudio/sleepyxposed/MediaStatusMonitor.kt`
around lines 248 - 249, 在读取线程处理逻辑中检查 readerThread.join(...) 返回后的
readerThread.isAlive 状态;若线程仍存活,记录读取超时并立即返回 null,禁止继续调用
outputRef.toString(),仅在线程结束后解析完整输出。

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ Branch updated during autofix.

The branch was updated while autofix was in progress. Please try again.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ Branch updated during autofix.

The branch was updated while autofix was in progress. Please try again.

@XFJ-YYQF

XFJ-YYQF commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

呜哇不好好起标题被泠云酱责备了…
但是这并不妨碍窝觉得她很可爱喵!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant