Skip to content

MediaProjectionForegroundService never stops #3

Description

@rogue-socket

Summary

MediaProjectionForegroundService is started when the user requests screen capture permission but is never stopped. No code path calls stopService() or stopSelf(). The persistent notification ("Screen capture active") stays forever.

How it starts

MainActivity.kt lines 89-91:

val serviceIntent = Intent(this, MediaProjectionForegroundService::class.java)
ContextCompat.startForegroundService(this, serviceIntent)

Why it never stops

  • MediaProjectionForegroundService has no stopSelf() call
  • MainActivity never calls stopService()
  • MediaProjectionController (in action-executor module) has no reference to the service
  • ScreenCaptureManager and ScrollerApp have no reference to the service

Consequences

  1. Permanent notification: "Screen capture active" with setOngoing(true) (not dismissible) stays in the tray after capture stops
  2. Service resurrection: START_STICKY (line 32) means Android restarts the service if the process dies, showing the notification again with no active projection
  3. Misleading state: User sees "Screen capture active" when capture is no longer active

Complication

The natural fix is to stop the service when MediaProjectionController fires onStopListener. But setOnStopListener is single-slot (not a list), and ScreenCaptureManager already claims it in its init block (line 44-47). Adding service teardown requires either changing to a listener list or wiring both actions from a single higher-level listener.

Files

  • app/src/main/java/com/scroller/agent/MediaProjectionForegroundService.kt
  • app/src/main/java/com/scroller/agent/MainActivity.kt (lines 89-93)
  • action-executor/src/main/java/com/scroller/agent/executor/MediaProjectionController.kt (line 90-92)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions