Add debug-only receiver to trigger FGS limit notification on demand

Maintainers need a screenshot of the "Foreground service limit reached"
notification for user-facing docs (docs/user/security.md,
docs/user/troubleshooting.md), but reproducing the underlying Android
6-hour daily FGS budget exhaustion organically is impractical.

Adds DebugFgsLimitReceiver to the app module's debug source set (never
shipped in release builds) which invokes the same
FgsLimitNotifier.postLimitReachedNotification call that production uses
when startForeground throws ForegroundServiceStartNotAllowedException,
so the resulting notification is pixel-identical to what users see.

No refactor of FgsLimitNotifier was needed — it was already a public
object with a public function.

Trigger from a host shell:
  adb shell am broadcast \
    -a com.rousecontext.debug.FIRE_FGS_LIMIT \
    -n com.rousecontext.debug/com.rousecontext.app.debug.DebugFgsLimitReceiver

Verified both :app:assembleDebug and :app:assembleRelease succeed, and
the receiver is present only in the debug APK's merged manifest.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jason Monk 2026-04-15 15:45:39 -04:00
parent 8373faaed6
commit ef6a4cc684
2 changed files with 62 additions and 0 deletions

View file

@ -12,6 +12,18 @@
<action android:name="com.rousecontext.action.TEST_WAKE" />
</intent-filter>
</receiver>
<!--
Debug-only: fires the production "Foreground service limit reached"
notification on demand so maintainers can screenshot it for the
user-facing docs. See DebugFgsLimitReceiver for the adb command.
-->
<receiver
android:name=".debug.DebugFgsLimitReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.rousecontext.debug.FIRE_FGS_LIMIT" />
</intent-filter>
</receiver>
<provider
android:name=".testing.TestCommandProvider"
android:authorities="com.rousecontext.debug.test"

View file

@ -0,0 +1,50 @@
package com.rousecontext.app.debug
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.rousecontext.notifications.FgsLimitNotifier
import com.rousecontext.notifications.NotificationChannels
/**
* Debug-only broadcast receiver that posts the "Foreground service limit reached"
* notification on demand. Exists solely so maintainers can screenshot the real
* notification (same code path as production) for embedding in user-facing docs
* (`docs/user/security.md`, `docs/user/troubleshooting.md`).
*
* Reproducing the underlying Android FGS daily-budget exhaustion naturally is
* impractical; this receiver invokes the same [FgsLimitNotifier.postLimitReachedNotification]
* function that production uses when `startForeground` fails with
* `ForegroundServiceStartNotAllowedException`, so the resulting notification is
* pixel-identical to what users will actually see.
*
* Only compiled into the `debug` build variant — never shipped in release.
*
* Trigger from a host shell:
* ```
* adb shell am broadcast \
* -a com.rousecontext.debug.FIRE_FGS_LIMIT \
* -n com.rousecontext.debug/com.rousecontext.app.debug.DebugFgsLimitReceiver
* ```
*/
class DebugFgsLimitReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action != ACTION_FIRE_FGS_LIMIT) {
Log.w(TAG, "Unknown action: ${intent.action}")
return
}
// Ensure the notification channel exists — production normally creates
// it during app startup, but we also guard here so the receiver works
// on a freshly installed debug build before anything else runs.
NotificationChannels.createAll(context)
FgsLimitNotifier.postLimitReachedNotification(context)
Log.i(TAG, "Posted FGS limit notification via debug trigger")
}
companion object {
private const val TAG = "DebugFgsLimitReceiver"
private const val ACTION_FIRE_FGS_LIMIT = "com.rousecontext.debug.FIRE_FGS_LIMIT"
}
}