Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Package Files #
*.jar
!gradle/wrapper/gradle-wrapper.jar
*.war
*.nar
*.ear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AppDetectionService : Service() {
override fun onCreate() {
super.onCreate()
isRunning = true
appFlowHandler = AppFlowHandler(this)
appFlowHandler = AppFlowHandler.getInstance(this)
createNotificationChannel()

val filter = IntentFilter().apply {
Expand Down Expand Up @@ -143,6 +143,12 @@ class AppDetectionService : Service() {
unregisterReceiver(authReceiver)
} catch (_: Exception) {
}
try {
if (::appFlowHandler.isInitialized) {
appFlowHandler.destroy()
}
} catch (_: Exception) {
}
Comment on lines +147 to +151

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🔴 Issue 2: Singleton Lifecycle & Premature Listener Teardown (State Corruption)

  • Location: AppDetectionService.kt:147–151 & AppFlowHandler.kt:84–95
  • What happened:
    • AppFlowHandler is now a static singleton INSTANCE.
    • When AppDetectionService.onDestroy() runs, it calls appFlowHandler.destroy(), which unregisters SharedPreferences listeners, ComponentCallbacks, and the MEDIA_PLAYBACK_CHANGED broadcast receiver from the application context.
    • However, INSTANCE is never reset to null.
  • Impact: If AppDetectionService restarts or ScreenOffAccessibilityService continues using AppFlowHandler, the handler is left in a dead/unregistered state where preference changes and media events are permanently ignored until a full process kill.

super.onDestroy()
}

Expand Down
Loading