ErrorProtect is the built-in watchdog for the Shevery server process (shizuku_server). It monitors main-thread responsiveness and critical Android system service bindings, terminating the server when a fault occurs so the native starter daemon can restart it cleanly.
-
Main-thread heartbeat monitoring:
- When enabled,
ShizukuServiceposts a heartbeat (ErrorProtect.beat()) on its main looper thread every 5 seconds. ErrorProtect.start()records an initial baseline timestamp immediately so a freeze before the first scheduled beat is still caught.- A dedicated daemon
HandlerThread(errorprotect) checks heartbeat freshness dynamically against the configured timeout (60s), scheduling follow-up checks atmin(pollInterval, remainingTimeout)so stalls are detected promptly at the timeout boundary rather than up to2xtimeout. - Before killing a stalled server process (
Process.killProcess(Process.myPid())), ErrorProtect captures and logs the main looper thread's stack trace to aid debugging.
- When enabled,
-
System service death & recovery monitoring:
- ErrorProtect registers
IBinder.linkToDeathrecipients on four critical system services (package,activity,user,appops) and optionalpermissionmgr. - Each health-check cycle also performs a fallback
pingBinder()check and properly unlinks stale death recipients before rebinding. - When a service dies or becomes unresponsive, ErrorProtect deduplicates pending rebinds per service and retries with exponential backoff (
5s,10s,20s,40s,60s, up to 10 attempts), verifying that the replacement binder is alive (pingBinder()) before accepting it. - When a service recovers (
ErrorProtect.Listener.onServiceRecovered),ShizukuServiceinvalidates cachedAndroid17Compatproxy handles (package/permissionmgr), re-registersBinderSenderprocess/UID observers (ifactivityrestarted), and re-dispatches binders to the manager and client apps. - If a critical service cannot be recovered after all 10 attempts, ErrorProtect terminates the server process so the starter daemon can respawn it and wait for system services cleanly.
- ErrorProtect registers
ErrorProtect is controlled via Settings -> ErrorProtect(Watchdog) across Phone, Wear OS, and Android TV:
ErrorProtectClientcommunicates withShizukuServiceover Binder IPC (BINDER_TRANSACTION_setErrorProtectEnabled/BINDER_TRANSACTION_getErrorProtectEnabled).- On the server,
ShizukuConfigManagerflusheserrorprotect_enabledchanges immediately to/data/user_de/0/com.android.shell/shizuku.json. - If toggled in the manager while the server is offline,
ErrorProtectClientcaches the preference locally and synchronizes it automatically as soon as the server binder is received.
When shizuku_server is launched or exits abnormally / is killed by ErrorProtect:
- The native
starter(manager/src/main/jni/starter.cpp) ignoresSIGPIPEandSIGHUP(SIG_IGN) so closing the launching ADB/root shell cannot kill the background supervisor or trigger broken-pipe terminations, while restoringSIG_DFLinside the spawnedshizuku_serverchild beforeexecvp. - Before spawning a new supervisor,
starterterminates both staleshizuku_serverinstances and any lingering previousstartersupervisor processes (matched via/proc/<pid>/exe) so duplicate supervisors never race each other. starterforks a detached background supervisor (setsid,/dev/nullstdio) and communicates the initialshizuku_serverPID over a pipe so the foreground starter process immediately printsinfo: shizuku_server pid is <pid>andinfo: shizuku_starter exit with 0and exits cleanly without blockingStarterActivityor wireless ADB sessions.- The detached supervisor waits on
shizuku_serverviawaitpid(retrying onEINTR), logs lifecycle events to Android logcat (Shizukutag), and waits 5 seconds before respawningshizuku_serveron abnormal exit. - Rapid crash loops are capped at 5 consecutive restarts (
max_restarts = 5). - If
shizuku_serverruns stably for at least 60 seconds (STABLE_UPTIME_RESET_SECS), the consecutive crash counter resets to0, allowing ErrorProtect to recover the server across multi-day uptimes without exhausting the retry budget. - Clean exits (
0) and manager-uninstalled exits (50/MANAGER_APP_NOT_FOUND) stop the starter without restarting.
| Parameter | Default | Description |
|---|---|---|
| Heartbeat interval | 5 s | Main thread heartbeat cadence |
| Heartbeat timeout | 60 s | Maximum allowed time without a heartbeat before process termination |
| Poll interval | 60 s | Maximum interval between fallback pingBinder() checks |
| Initial rebind delay | 2 s | Delay before first rebind attempt after service death |
| Backoff range | 5 s – 60 s | Exponential backoff delay between failed rebind attempts |
| Max rebind attempts | 10 | Maximum attempts before terminating server for starter recovery |
| Stable uptime reset | 60 s | Server uptime threshold that resets starter's consecutive crash counter |
errorprotect/src/main/java/rikka/shizuku/errorprotect/ErrorProtect.ktserver/src/main/java/rikka/shizuku/server/ShizukuService.javaserver/src/main/java/rikka/shizuku/server/ShizukuConfigManager.javaserver/src/main/java/rikka/shizuku/server/BinderSender.ktmanager/src/main/jni/starter.cppstarter/src/main/java/moe/shizuku/starter/ServiceStarter.javamanager/src/main/java/moe/shizuku/manager/errorprotect/ErrorProtectClient.ktmanager/src/main/java/moe/shizuku/manager/service/WatchdogManager.ktmanager/src/main/java/moe/shizuku/manager/settings/SettingsScreen.kt