mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-19 09:25:02 +00:00
ForegroundServiceDidNotStartInTimeException was reported on Play Console (Android 14+, OEM-throttled devices, app in foreground). The stop helpers stopTrackingService()/stopFocusModeService() used Activity.stopService(), which bypasses onStartCommand and tears the service down directly. When a focus/tracking session is started and quickly cancelled, AOSP bringDownServiceLocked() crashes the process if the service is destroyed while fgRequired is still true, i.e. before its first startForeground(). Add an isStartPending flag to each service companion (set before startForegroundService(), cleared after promotion in onStartCommand and in onDestroy) and route stops through ACTION_STOP via startService() while a start is pending or the service is running, so onStartCommand promotes the service before tearing it down. Cold no-op stops still use stopService(). A backgrounded stop (startService disallowed) falls back to stopService() only when no start is pending; a pending start is left for onStartCommand to promote and a later foreground sync to stop, so the fallback can never re-trigger the same crash. |
||
|---|---|---|
| .. | ||
| src | ||
| .gitignore | ||
| app_config.properties | ||
| build.gradle | ||
| capacitor.build.gradle | ||
| config.gradle | ||
| google.properties | ||
| proguard-rules.pro | ||