← Back to AI Insights
Gemini Executive Synthesis

Self-healing mechanism for Android TV applications against OEM `force-stop` actions, specifically using SyncAdapter.

Technical Positioning
Achieving robust application persistence and auto-recovery on Android TV platforms, particularly Xiaomi TVs, by leveraging system-level synchronization frameworks to bypass OEM process termination policies.
SaaS Insight & Market Implications
This extensive discussion centers on a critical Android TV challenge: OEM-specific `force-stop` policies that kill background processes and prevent auto-start, rendering apps like StudyOnTV unusable. The proposed SyncAdapter self-healing mechanism, leveraging system `settings` authority, demonstrates a sophisticated, device-side solution to bypass these restrictions, achieving rapid recovery from `force-stop` and cold boot. This contrasts with the developer's external ADB watchdog approach, which offloads persistence to external systems. The SyncAdapter solution, proven effective on Xiaomi TV, represents a superior technical strategy for internal app resilience. Its ability to clear the `stopped` flag and re-enable `BOOT_COMPLETED` is a significant breakthrough. For B2B SaaS targeting Android TV, internal self-healing is paramount for scalability, user experience, and reducing support overhead, offering a more robust and less intrusive solution than external dependencies.
Proprietary Technical Taxonomy
SyncAdapter 自愈机制 小米电视 冷启动必挂 死循环 killAllThirdApp stopped=true 无障碍串 开机不 bind

Raw Developer Origin & Technical Request

Source Icon GitHub Issue Nov 9, 2026
Repo: chadyi/StudyOnTV
提议:SyncAdapter 自愈机制,解决小米电视 中「冷启动必挂」的死循环(附完整参考实现)

承接 #48 的定位结论。#48 已把死循环讲透:`killAllThirdApp` 强停 → 包置 `stopped=true` → 无障碍串里本应用的段被系统清掉 → 开机不 bind → `proc=0`,只能靠外部 adb 补回。建议 6 里提到的 SyncAdapter 方向,我在同款场景下找到了一套**实测可用的开源实现**可以借鉴——Aerial 桌面(app.orchard.tv,MIT 协议)。同一次 `killAllThirdApp` 里 Aerial 也被强停,但它每次都能在 30–60 秒内自己回来,靠的就是 SyncAdapter。本文给出适合 StudyOnTV 的移植写法,全部组件 API 21 起可用。

## 一、为什么 SyncAdapter 能穿过 force-stop

force-stop 掐断 BOOT_COMPLETED 广播、AlarmManager、JobScheduler、START_STICKY 重启,但**掐不断系统同步框架**:同步调度由 system_server 里的 SyncManager 持有,sync adapter 的注册信息在系统侧缓存,对 stopped 包依然有效——调度到达时系统会显式 bind,进程随之启动。

## 二、关键技巧:挂在 "settings" authority 上,事件驱动,无需定时器

Aerial 的做法不是定时轮询,而是把 sync adapter 的 `contentAuthority` 指到系统的 **`settings`**:

- SettingsProvider 对每次系统设置写入都带 `syncToNetwork` 标记,SyncManager 随后约 30 秒内调度一次本地同步;
- 而固件强停应用时"把这一段从 `enabled_accessibility_services` 里裁掉"**本身就是一次 settings 写入**——等于系统杀应用的时候,顺手触发了应用的复活。杀得越准,来得越快。

不需要网络,不需要轮询,也不会被"系统周期性改写白名单"(#48 里 `rt_pkg_white_list` 失效的原因)影响。

## 三、适配 StudyOnTV 的完整参考实现

### 1. AndroidManifest.xml

```xml

Developer Debate & Comments

cx5311 • Nov 9, 2026
## 已实现并真机验证 ✅(补丁附后,v3 更新) 按上面的方案在 MiTV-MFFU0(小米电视,Android 14)上完整实现了自愈,编译为内部测试版实测通过,补丁可以直接 apply。 **(本次为第三次更新:修复了前两版在小米电视上"开机/待机后拉不起"的两个关键缺陷,见下方"小米实测补充")** ### 许可说明 同步适配器结构参考并改写自 **Aerial TV (aerial-tv, https://github.com/pengchujin/aerial-tv) 的 RevivalSync.kt / GuardSetup.kt**,该项目为 **MIT 许可**,Copyright (c) 2026 pengchujin。按 MIT 条款要求,完整版权声明与许可文本已保留在 `GuardSync.kt` 文件头(本评论 diff 中已包含),与 StudyOnTV 的源码许可不冲突。 ### 改动清单(4 新增 + 4 修改,不涉及版本号与签名) | 文件 | 改动 | |---|---| | `GuardSync.kt` | **新增**:GuardSync(ensure/heal)+ GuardSyncService(SyncAdapter)+ GuardAccountService | | `GuardListener.kt` | **新增**:通知监听复活通道(参考 Aerial RevivalListener,不读通知,仅作复活入口) | | `res/xml/guard_account.xml` | **新增**:accountType=`com.studyontv.tv` | | `res/xml/guard_sync.xml` | **新增**:authority=`settings` 的本地同步,**supportsUploading 必须为 true**(见下) | | `AndroidManifest.xml` | 加 `WRITE_SECURE_SETTINGS` / `READ_SYNC_SETTINGS` / `WRITE_SYNC_SETTINGS` / `FOREGROUND_SERVICE_SPECIAL_USE` 权限 + GuardSyncService/GuardAccountService/Gu...
cx5311 • Nov 10, 2026
## 最终双场景实测通过 ✅(真机:MiTV-MFFU0,Android 14) 接上面的分析,v4(`supportsUploading="true"`)部署后做了两轮真机验证,结果如下: ### 实测结果 | 场景 | 结果 | 实测细节 | |---|---|---| | 运行中强杀进程 | **3 秒内自动复活** | 杀进程时系统强制摘除无障碍服务 → settings 写入本身触发 LOCAL 同步 → SyncManager bind 拉起进程 → heal 补回无障碍串 | | 普通待机 → 开屏 | **恢复瞬间立即拉起**(未走 15min 周期同步) | 待机约 40s,恢复当秒监控捕获进程 UP,无障碍段直接恢复 | | **拔电冷启动 → 开机** | **约 10 秒拉起** | 开机后 adb 复核:进程存活、`enabled_accessibility_services` 完整含本 App 段(其他厂商段保留)、stopped=false | 冷启动这一轮走的是 **BOOT_COMPLETED 通道**——这是之前一直不生效的最后一环,根因和解法补充如下: ### 两个关键坑(补充情报) 1. **stopped 标记是持久化的,且会拦截 BOOT_COMPLETED**:`dumpsys activity broadcasts` 的开机派发名单 = 所有非 stopped 包的清单接收器。force-stop 过的包即使重启也进不了名单。解法:只要系统曾主动拉起过该进程(同步/监听重绑都会),stopped 标记即被自动清除 → 下次开机稳定进派发名单。所以 LOCAL 同步通道(v4)其实是开机自启的前置条件,两层是联动的。 2. **通知监听通道必须官方授权**:直接写 `enabled_notification_listeners` 自批准无效(NMS 只认允许列表)。用 `cmd notification allow_listener /`(Aerial install.sh 同款做法)授权一次即可长期生效。 ### 最终形态(三层拉起) ``` LOCAL 同步(秒级,随 settings 写入触发) └─ 兜底 15min 周期同步(stopped 状态也能拉起进程清除标记) ...
chadyi • Nov 10, 2026
感谢你写了这么完整的 SyncAdapter 参考实现!我们评估后这版没有合入 SyncAdapter:它同样受 `force-stop` 的 stopped 状态约束,救不了 / / / 这类强停,只会改善“只杀进程”的清理。因此 v0.3.22 改为提供外部 ADB 看门狗,作为不依赖 App 自身复活的恢复路径。 针对厂商 force-stop / 系统清理导致的进程被杀,APK 自己无法解除(系统 stopped 状态会阻止广播和自启),所以 v0.3.22 同时提供了一个**外部看门狗**,想请你帮忙在设备上试试能否恢复: 1. 电视保持亮屏,开启并授权局域网 ADB,与电脑 / NAS 在同一可信局域网。 2. 电脑安装 Python 3.10+ 和 ADB,先只读检查: `python scripts/device-watchdog.py status --serial :5555` 3. 再持续恢复(同时修复缺失的无障碍记录): `python scripts/device-watchdog.py watch --serial :5555 --interval 30 --repair-accessibility` 4. 想长期运行,可用 `deploy/watchdog/` 里的 Windows 计划任务、macOS LaunchAgent、Linux systemd、NAS Docker 或路由器脚本。 原理和边界见 [后台恢复文档](https://github.com/chadyi/StudyOnTV/blob/main/docs/background-recovery.md):电视重启后如果固件关闭了网络 ADB,看门狗也连不上;恢复只是“请求启动”,由下一轮复核,不能保证零空窗。脚本只检查本应用,不会清理其他应用,也不会修改厂商全局设置。 如果试过之后仍会被强停,请把 `status` 输出、电视型号 / 系统版本和 `/api/logs/export` 诊断日志发上来,我们继续定位。谢谢!
cx5311 • Nov 10, 2026
## 澄清一下方向,并同步最终实测结果 感谢回复!不过这里可能有个误会,先说明我们的定位: - **我们没有开 PR、也没有要求合入**(项目许可是 Personal-Use Only / 禁止向第三方再分发衍生作品,所以当时就选择只把 diff 作为参考实现贴在 issue 里,供参考)。 - **我们也不在「外部 ADB 看门狗」这条路上**。11-09 我们确实自己写过一个电脑端 Python ADB 看门狗(逻辑和 v0.3.22 的 `device-watchdog.py` 基本一致:轮询 + 补无障碍 + `am start`),但当晚 23:08 已删除其自启项与进程。下面所有测试都是在**电脑上没有任何看门狗、没有常驻 adb 连接、没有人手工打开 App** 的条件下完成的。 - 我们想反馈的是:**在这台电视上,设备端自恢复已经实测闭环**,其中就包括 描述的「拔电冷启动被固件强停」场景。 ### 需要更正的一个机制判断 > 「SyncAdapter 同样受 force-stop 的 stopped 状态约束……APK 自己无法解除(stopped 会阻止广播和自启)」 后半句对**广播 / AlarmManager / JobScheduler / 普通 startService** 是成立的,但 **SyncManager 的同步不属于这一类**:同步任务由 system_server 调度,系统以显式 bind 拉起应用的 SyncAdapterService。实测 `dumpsys content` 可见,即使包处于 `stopped=true`,周期同步到点照样把进程拉起来执行 `onPerformSync`;而 Android 对「系统主动拉起进程」会自动清除 stopped 标记 → 之后 `BOOT_COMPLETED` 的派发名单才会包含该包。 也就是说,并不是「APK 自己解除了 stopped」,而是**同步框架(系统进程)发起的拉起绕过了 stopped 拦截,并顺带清掉了标记**。Aerial TV 在这台电视上也是这么工作的:待机/关机时它同样被固件 force-stop(events log 可见),但 225ms 后就被同一个 LOCAL 同步机制拉回。所以这不是「只改善杀进程的清理」,实测强停...
cx5311 • Nov 10, 2026
## 另外想正式请求一份授权:可否另开一条实验分支做多机型验证? 完全理解并尊重不合入 SyncAdapter 的决定,这里不再讨论方案取舍,只提一个后续请求。 ### 背景 目前的实测结论只在**一台** MiTV-MFFU0 / Android 14 上取得,不敢外推。要判断这套机制到底适用到什么范围,还需要在更多小米电视上验证,比如: - 不同型号 / 不同 MIUI for TV 版本的待机与拔电 `force-stop` 策略差异 - `low_ram` 机型上通知监听器通道是否被 NMS 拒绝(Aerial 的注释里提到过这个限制) - SettingsProvider 的 LOCAL 同步 / `supportsUploading` 行为在不同系统版本上是否一致 - 15 分钟周期同步的兜底是否普遍可靠 要做到这一点,比较现实的方式是维护**一条能持续同步上游更新的分支**:否则每次您发新版,补丁就得手工重新 apply 一次,参与测试的人也很难拿到一致的构建。 ### 为什么需要先问您授权 我查了 LICENSE(Source Available — Personal Use Only),条款写得很清楚: - 允许:个人非商业/家庭用途下下载、编译、安装、运行,以及 **fork 或修改源码供个人使用** - 未经著作权人**事先书面许可**禁止:向第三方再分发本软件或**任何衍生作品(源码或二进制)**;商业使用;**使用项目名 / logo / 品牌做背书或推广** 一旦把带自愈补丁的源码或测试 APK 提供给其他小米电视用户,就超出了 "personal use" 的范围,会碰到上面两条。LICENSE 里也写明授权请求走 GitHub Issues,所以就在这个线程里正式问一下,不想擅自发布。 (补充说明:补丁里 SyncAdapter 的结构来自 aerial-tv,那部分是 MIT,可自由分发;需要您授权的是对 StudyOnTV 主体代码做增量修改后形成衍生作品的部分。) ### 想请求的授权范围(挑一个您觉得最省事的即可) 1. **在您的仓库里开一条实验分支**,例如 `experimental/selfheal-sync`(我可以只提交补丁、不碰 `main`;需要您把我加为协作者,或您帮忙建好分支我来推)...

Adjacent Repository Pain Points

Other highly discussed features and pain points extracted from chadyi/StudyOnTV.

Extracted Positioning
Application functionality and persistence on Xiaomi TV S 75 minLED, specifically regarding accessibility services, timers, and pop-up quizzes.
Ensuring core screen-time management features function reliably on specific Android TV OEM devices, particularly against aggressive system process termination.
Top Replies
cx5311 • Nov 10, 2026
看,或者让agent来读取,我已经完美搞定,不知道作者啥时候能加入到他的项目了,我迭代出来的版本已经完美验证。
chadyi • Nov 10, 2026
感谢反馈小米电视 S 75 miniLED 无法使用的问题!v0.3.22 增加了更完整的设备诊断(`/api/device` 的 monitor / keepalive 字段)和后台自检,想请你先更新后帮忙确认几项状态。 针对厂商 force-stop / 系统清理...
chadyi • Nov 10, 2026
补充一个排查信息,方便判断是厂商强停、无障碍被系统清掉,还是计时/弹窗链路断开: 1. 电视开启 ADB 后,先清一次日志再复现: ``` adb logcat -c adb logcat -d | grep -i studyontv ``` 把输出贴上来即可(如...
Extracted Positioning
Application stability and persistence on Xiaomi TV with Hyper OS.
Ensuring core application functionality (auto-start, background process) on specific Android TV OEM platforms.
Extracted Positioning
Application update mechanism.
Ensuring application maintainability and user access to new features/bug fixes on Android TV.
Top Replies
Promise585 • Nov 7, 2026
666
cx5311 • Nov 9, 2026
走aerial tv的白名单路线呢?
Promise585 • Nov 10, 2026
https://github.com/heimi51168/planyourtv
Top Replies
qidunhu • Nov 6, 2026
遇到同样问题,息屏后,电视会杀掉所有进程,且没有root的情况下无法更改。 我用ADB 常开外加看门狗的方式暂时解决了一部分(进程保活): 1、电视打开ADB 常开 2、写了一个看门狗进程,息屏后再唤醒看门狗自动拉起...
chadyi • Nov 6, 2026
感谢您的反馈和建议,正在探索保活的方案
cx5311 • Nov 9, 2026
> 感谢您的反馈和建议,正在探索保活的方案 能不能编译白名单版本来解决小米保活的问题呢?

Frequently Asked Questions

Market intelligence mapped to Self-healing mechanism for Android TV applications against OEM `force-stop` actions, specifically using SyncAdapter..

How is Self-healing mechanism for Android TV applications against OEM `force-stop` actions, specifically using SyncAdapter. positioned in the market?
Based on our AI analysis of the original developer request, its primary technical positioning is: Achieving robust application persistence and auto-recovery on Android TV platforms, particularly Xiaomi TVs, by leveraging system-level synchronization frameworks to bypass OEM process termination policies.
Are engineers actively discussing Self-healing mechanism for Android TV applications against OEM `force-stop` actions, specifically using SyncAdapter.?
Yes, we have tracked 7 direct responses and active debates regarding this specific topic originating from GitHub Issue.
What architecture is tied to Self-healing mechanism for Android TV applications against OEM `force-stop` actions, specifically using SyncAdapter.?
Our proprietary extraction maps Self-healing mechanism for Android TV applications against OEM `force-stop` actions, specifically using SyncAdapter. to adjacent architectural concepts including SyncAdapter 自愈机制, 小米电视, 冷启动必挂, 死循环.

Engagement Signals

7
Replies
open
Issue Status

Cross-Market Term Frequency

Counts stored text matches for foundational terms like settings and Android 14 in analysed public discussions. These counts do not measure adoption.

Stored text matches, not adoption or market-share measurements.

  • settings: 33 records
  • Android 14: 4 records
  • 小米电视: 3 records
  • system_server: 3 records
  • SyncAdapter 自愈机制: 1 records
  • 冷启动必挂: 1 records
  • 死循环: 1 records
  • killAllThirdApp: 1 records
  • stopped=true: 1 records
  • 无障碍串: 1 records
  • 开机不 bind: 1 records
  • proc=0: 1 records
  • 外部 adb 补回: 1 records
  • SyncManager: 1 records
  • sync adapter: 1 records
  • BOOT_COMPLETED 广播: 1 records
  • AlarmManager: 1 records
  • JobScheduler: 1 records
  • START_STICKY: 1 records
  • 系统同步框架: 1 records
  • 显式 bind: 1 records
  • contentAuthority: 1 records
  • SettingsProvider: 1 records
  • syncToNetwork: 1 records
  • LOCAL 同步: 1 records
  • enabled_accessibility_services: 1 records
  • rt_pkg_white_list: 1 records
  • API 21: 1 records
  • MiTV-MFFU0: 1 records
  • GuardSync.kt: 1 records
  • GuardSyncService: 1 records
  • GuardAccountService: 1 records
  • GuardListener.kt: 1 records
  • RevivalSync.kt: 1 records
  • GuardSetup.kt: 1 records
  • MIT 许可: 1 records
  • accountType=com.studyontv.tv: 1 records
  • authority=settings: 1 records
  • supportsUploading=true: 1 records
  • AndroidManifest.xml: 1 records
  • WRITE_SECURE_SETTINGS: 1 records
  • READ_SYNC_SETTINGS: 1 records
  • WRITE_SYNC_SETTINGS: 1 records
  • FOREGROUND_SERVICE_SPECIAL_USE: 1 records
  • dumpsys activity broadcasts: 1 records
  • stopped 标记: 1 records
  • 通知监听通道: 1 records
  • enabled_notification_listeners: 1 records
  • NMS: 1 records
  • cmd notification allow_listener: 1 records
  • 三层拉起: 1 records
  • 外部 ADB 看门狗: 1 records
  • am start: 1 records