浏览代码

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 年前
父节点
当前提交
23b91c0336
共有 1 个文件被更改,包括 13 次插入4 次删除
  1. 13
    4
      android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java

+ 13
- 4
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java 查看文件

@@ -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
         }

正在加载...
取消
保存