Skip to content

Commit 95acf7e

Browse files
authored
fix(signaling): call startForeground() first in onCreate() to reduce FGS timeout risk (#1100)
Move startForeground() to be the first call after super.onCreate(), before any SharedPreferences IPC. Under memory pressure (Xiaomi HyperOS), the SharedPrefs read in getCallbackDispatcher() can block the main thread for 50-500ms, pushing startForeground() past Xiaomi's aggressive ~1.2s window and causing ForegroundServiceDidNotStartInTimeException. startForeground() has no dependency on FlutterEngineHelper or callbackHandle — the engine starts in onStartCommand(), which runs after onCreate() completes.
1 parent a1b410b commit 95acf7e

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

  • packages/webtrit_signaling_service/webtrit_signaling_service_android/android/src/main/kotlin/com/webtrit/signaling_service

packages/webtrit_signaling_service/webtrit_signaling_service_android/android/src/main/kotlin/com/webtrit/signaling_service/SignalingForegroundService.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ class SignalingForegroundService : Service() {
5959

6060
override fun onCreate() {
6161
super.onCreate()
62-
Log.d(TAG, "SignalingForegroundService onCreate")
62+
startForeground()
6363

64+
Log.d(TAG, "SignalingForegroundService onCreate")
6465
instance = this
65-
6666
val callbackHandle = StorageDelegate.getCallbackDispatcher(applicationContext)
6767
flutterEngineHelper = FlutterEngineHelper(applicationContext, callbackHandle, this)
68-
69-
startForeground()
7068
isRunning = true
7169
}
7270

0 commit comments

Comments
 (0)