Skip to content

Hold Shizuku alive across screen-off via WifiLock + loop defense#41

Closed
Suprhimp wants to merge 5 commits into
masterfrom
devplanningo/shizuku-stability
Closed

Hold Shizuku alive across screen-off via WifiLock + loop defense#41
Suprhimp wants to merge 5 commits into
masterfrom
devplanningo/shizuku-stability

Conversation

@Suprhimp

Copy link
Copy Markdown
Owner

Summary

  • Acquire WIFI_MODE_FULL_HIGH_PERF WifiLock in ShizukuSetup so the radio doesn't sleep on screen-off, preventing the AdbDebuggingManager "Network disconnected. Disabling adbwifi" cascade that killed Shizuku within 1-10s of lock on Samsung devices.
  • Add quick-death counter: if the binder dies <15s after being received 3 times in a row, stop auto-relaunching the Shizuku manager and post a high-priority ongoing notification asking the user to plug USB back in or keep the screen on. Breaks the infinite relaunch loop on OEM kills.
  • Add client-side frame-arrival watchdog so a silently stalled video socket (Shizuku death, encoder stall, VD end) no longer freezes the last frame on screen.
  • Relocate Home / density / playback-profile controls into a collapsible overlay menu to tidy the on-screen chrome.

Test plan

  • Build: ./gradlew :app:assembleDebug green
  • Galaxy Flip (SM-F741N, Android 14): WiFi on + USB unplugged + screen lock — Shizuku now survives ~40s (previously 1-10s). ShizukuWifiLock acquired confirmed in logcat; no Network disconnected. Disabling adbwifi event.
  • Quick-death loop defense: verified counter increments on rapid binder deaths; give-up notification channel wired and dismissable on successful reconnect.
  • Follow-up: a separate death trigger still kicks in ~24s after screen lock (likely Samsung doze/process freezer, not WADB teardown). Not fixed here; give-up notification is the user-facing mitigation.

🤖 Generated with Claude Code

Suprhimp and others added 2 commits April 18, 2026 17:04
Addresses repeated Shizuku death on Samsung (FreecessController kills
shell-UID processes aggressively, taking both shizuku_server and the
single-layer watchdog with it). Users had to re-run wireless-debugging
setup every time the hotspot transition killed the server.

New resilience stack:
- Dual-layer watchdog (outer supervises inner; inner supervises
  shizuku_server) spawned with nohup+setsid for session detachment.
- Heartbeat file written every 5s; 15s staleness threshold triggers
  reinstall.
- Best-effort fortification: doze whitelist, appops RUN_ANY/IN_BG,
  oom_score_adj = -900 on shizuku_server and the watchdogs.
- Staged rollback-safe install: write .new scripts, rename, teardown
  old processes via PID-file + exact argv-element cmdline match,
  spawn outer, verify.
- ShellDiag marker protocol (__STEP_BEGIN__/__STEP_END__ rc=$?) so
  stdout-only IPC can recover per-step exit codes and fail fast.
- Exact argv-element cmdline validation via tr '\0' '\n' | grep -Fxq
  (no substring or space-boundary heuristics).
- Single synchronized entrypoint ensureShizukuHardened() called from
  MainActivity and MirrorForegroundService.
- Legacy single-script watchdog cleanup via /proc/*/cmdline
  enumeration.
- SHIZUKU_FORTIFIED diagnostic event (informational; classifier ignores).

45 unit tests: 21 new for ShellDiag + ShizukuHealth, 3 regression
tests for DisconnectCauseClassifier's treatment of the new event.

Reviewed via DUUL (plan + code phases, approved).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Acquire WIFI_MODE_FULL_HIGH_PERF lock in ShizukuSetup so wireless
  ADB does not get torn down by the radio sleeping on screen-off
  (fixes the AdbDebuggingManager "Network disconnected. Disabling
  adbwifi" cascade that killed Shizuku within 1-10s of lock).
- Add quick-death counter: if the binder dies <15s after being
  received 3 times in a row, stop auto-relaunching the Shizuku
  manager and post a high-priority ongoing notification telling the
  user to plug USB back in or keep the screen on. Avoids an infinite
  relaunch loop on OEM kill.
- Add client-side frame-arrival watchdog so a silently stalled
  video socket (Shizuku death, encoder stall, VD end) no longer
  freezes the last frame on screen.
- Relocate Home / density / playback-profile controls into a
  collapsible overlay menu to tidy the on-screen chrome.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Suprhimp Suprhimp added the patch Version bump: patch (1.2.3 → 1.2.4) label Apr 19, 2026
Suprhimp and others added 3 commits April 24, 2026 12:12
Samsung's Default USB Configuration = File Transfer (MTP/PTP) causes the
OS to restart USB on every screen lock, killing Shizuku. Detect the
misconfig at startup and prompt the user to switch to Charging only,
with a shortcut to Developer Options. Respects a don't-show-again flag.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Single-VD mode: rely on the global IME state (mInputShown / mShowRequested)
alone so the bubble only appears when the phone keyboard actually shows.
The dumpsys window imeInputTarget fallback is reserved for true Samsung
dual-VD where cross-display focus mismatch makes the global state lie.

Add a 200ms hide watchdog while the bubble is visible so it disappears as
soon as the keyboard dismisses, and a browser→server bubbleClosed signal
that suppresses the hasTarget fallback until the user re-engages, so a
user-dismissed bubble doesn't immediately re-open.

Also move the split ratio controls into the overlay menu panel instead of
the separate floating toolbar/tap-zone.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
After an install/update (including adb install -r with no version bump),
shizuku_server holds a cached user-service record pointing at our previous
process's binder. Without intervention, the next bindUserService call
either never delivers onServiceConnected or connects then immediately
disconnects — the symptom users see as "Shizuku not responding until I
restart the manager".

Detect reinstall by comparing PackageInfo.lastUpdateTime against a saved
SharedPreferences value on init, and when they differ call
unbindUserService(args, conn, remove=true) before the first bind so the
stale record is wiped. Also watch the user-service ServiceConnection:
sessions that end within 3s of connecting trigger one automatic force
unbind-rebind (capped at two retries) to cover the case where the stale
record slipped past detection.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel

vercel Bot commented Apr 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
website Ready Ready Preview, Comment Apr 24, 2026 3:25am

@Suprhimp

Copy link
Copy Markdown
Owner Author

Superseded by #42 — branch renamed from devplanningo/shizuku-stability to shizuku-stability which closed this PR as a side effect. All commits preserved; new scope adds IME bubble dual-mode fix and Shizuku token-mismatch recovery.

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

Labels

patch Version bump: patch (1.2.3 → 1.2.4)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant