refactor: Centralize app flow handling and service event dispatching - #770
Draft
Mudit200408 wants to merge 1 commit into
Draft
refactor: Centralize app flow handling and service event dispatching#770Mudit200408 wants to merge 1 commit into
Mudit200408 wants to merge 1 commit into
Conversation
sameerasw
force-pushed
the
feat-app-detection
branch
from
August 21, 2026 09:19
62e0acd to
435d7f4
Compare
sameerasw
self-requested a review
August 21, 2026 09:22
sameerasw
requested changes
Aug 21, 2026
sameerasw
left a comment
Owner
There was a problem hiding this comment.
🟡 Logic Flaws & Design Concerns
⚠️ Race Condition between Accessibility Events & UsageStats Polling
- In
AppFlowHandler.onPackageChanged:val oldPackage = currentPackage currentPackage = packageName // <--- Mutated unconditionally on every call! ... if (isFromUsageStats == useUsageAccess) { checkAppLock(packageName) checkHighlightNightLight(packageName) checkAppAutomations(packageName) checkGestureBarAutomation(packageName) }
- If
useUsageAccessis enabled, accessibility window state changes still callonPackageChanged(..., isFromUsageStats = false). - This prematurely updates
currentPackagewithout executing any of the checks. WhenAppDetectionServicepolls shortly after,oldPackageandcurrentPackageare already corrupted or identical, potentially missing exit/entry actions in App Automations and App Lock.
📋 Summary Verdict
| Area | Status | Notes |
|---|---|---|
| Architectural Goal | Centralizing app flow is a good idea, but implementation drops core features. | |
| Shut Up & Freeze Features | ❌ Broken | Core restoration and countdown logic was completely deleted. |
| Lifecycle Safety | ❌ Broken | destroy() leaves a zombie singleton instance. |
| Gradle / Build Files | ❌ Unwanted | Adds a binary .jar and modifies gradlew. |
Owner
There was a problem hiding this comment.
🔴 Issue 1: Complete Deletion of "Shut Up" & "App Freeze on Exit" Logic (Severe Regression)
- What happened: Over 500 lines of critical background logic were deleted from
AppFlowHandler.ktwithout being moved anywhere:- Shut Up Settings Restoration:
restoreShutUpSettings(),checkShutUpRestore(), and Shizuku auto-restarting logic were completely stripped. - Restore Notification & Promoted Ongoing Notification: The ongoing restore notification (
NOTIFICATION_ID_SHUTUP_RESTORE),ACTION_RESTORE_NOW, and interactive restore actions were deleted. - Freeze on Exit / Auto-Archive Countdowns:
activeCountdowns,ACTION_FREEZE_NOW, andACTION_ABORT_FREEZEbroadcast receivers and notifications were removed.
- Shut Up Settings Restoration:
- Impact: Merging this will completely break the Shut Up feature and App Freeze-on-Exit automations, preventing system settings from ever being restored and frozen apps from being managed on app exit.
Comment on lines
+147
to
+151
| if (::appFlowHandler.isInitialized) { | ||
| appFlowHandler.destroy() | ||
| } | ||
| } catch (_: Exception) { | ||
| } |
Owner
There was a problem hiding this comment.
🔴 Issue 2: Singleton Lifecycle & Premature Listener Teardown (State Corruption)
- Location:
AppDetectionService.kt:147–151&AppFlowHandler.kt:84–95 - What happened:
AppFlowHandleris now a static singletonINSTANCE.- When
AppDetectionService.onDestroy()runs, it callsappFlowHandler.destroy(), which unregistersSharedPreferenceslisteners,ComponentCallbacks, and theMEDIA_PLAYBACK_CHANGEDbroadcast receiver from the application context. - However,
INSTANCEis never reset tonull.
- Impact: If
AppDetectionServicerestarts orScreenOffAccessibilityServicecontinues usingAppFlowHandler, the handler is left in a dead/unregistered state where preference changes and media events are permanently ignored until a full process kill.
Owner
There was a problem hiding this comment.
🔴 Issue 3: Unrelated / Suspicious Gradle Binary & Wrapper Script Changes
- Files Modified:
gradle/wrapper/gradle-wrapper.jar(Binary added: +53 KB)gradlew(Modified invocation from-jarto-classpath)
- Impact: Changes to binary wrapper jars or
gradlewexecution in a feature PR are a security concern, unnecessary, and out-of-scope.
sameerasw
marked this pull request as draft
August 21, 2026 09:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactors and centralizes app flow handling and service event dispatching.