Pārlūkot izejas kodu

fix(android) fix crash when starting foreground service

If we attempt to start it while in the background we'll get a crash. A
more elegant fix would be to wait until the app transitions to the
foreground to start it, but the crash is hurting us now.
master
Saúl Ibarra Corretgé 3 gadus atpakaļ
vecāks
revīzija
23b91c0336

+ 13
- 4
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java Parādīt failu

@@ -51,11 +51,20 @@ public class JitsiMeetOngoingConferenceService extends Service
51 51
         intent.setAction(Action.START.getName());
52 52
 
53 53
         ComponentName componentName;
54
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
55
-            componentName = context.startForegroundService(intent);
56
-        } else {
57
-            componentName = context.startService(intent);
54
+
55
+        try {
56
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
57
+                componentName = context.startForegroundService(intent);
58
+            } else {
59
+                componentName = context.startService(intent);
60
+            }
61
+        } catch (RuntimeException e) {
62
+            // Avoid crashing due to ForegroundServiceStartNotAllowedException (API level 31).
63
+            // See: https://developer.android.com/guide/components/foreground-services#background-start-restrictions
64
+            JitsiMeetLogger.w(TAG + " Ongoing conference service not started", e);
65
+            return;
58 66
         }
67
+
59 68
         if (componentName == null) {
60 69
             JitsiMeetLogger.w(TAG + " Ongoing conference service not started");
61 70
         }

Notiek ielāde…
Atcelt
Saglabāt