Bläddra i källkod

android: add a uncaught exception handler

Its main task is to cleanup conferences (specially the connection services
stuff) to make sure the system is left in a working state even when the
unexpected happens.
j8
Saúl Ibarra Corretgé 5 år sedan
förälder
incheckning
803870ef8f

+ 10
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/BaseReactView.java Visa fil

@@ -29,6 +29,7 @@ import com.facebook.react.bridge.ReadableMap;
29 29
 import com.rnimmersive.RNImmersiveModule;
30 30
 
31 31
 import java.lang.reflect.Method;
32
+import java.util.ArrayList;
32 33
 import java.util.Collections;
33 34
 import java.util.Map;
34 35
 import java.util.Set;
@@ -77,6 +78,15 @@ public abstract class BaseReactView<ListenerT>
77 78
         return null;
78 79
     }
79 80
 
81
+    /**
82
+     * Gets all registered React views.
83
+     *
84
+     * @return An {@link ArrayList} containing all views currently held by React.
85
+     */
86
+    static ArrayList<BaseReactView> getViews() {
87
+        return new ArrayList<>(views);
88
+    }
89
+
80 90
     /**
81 91
      * The unique identifier of this {@code BaseReactView} within the process
82 92
      * for the purposes of {@link ExternalAPIModule}. The name scope was

+ 10
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/ConnectionService.java Visa fil

@@ -63,6 +63,16 @@ public class ConnectionService extends android.telecom.ConnectionService {
63 63
     static private final HashMap<String, Promise> startCallPromises
64 64
             = new HashMap<>();
65 65
 
66
+    /**
67
+     * Aborts all ongoing connections. This is a last resort mechanism which forces all resources to
68
+     * be freed on the system in case of fatal error.
69
+     */
70
+    static void abortConnections() {
71
+        for (ConnectionImpl connection: getConnections()) {
72
+            connection.onAbort();
73
+        }
74
+    }
75
+
66 76
     /**
67 77
      * Adds {@link ConnectionImpl} to the list.
68 78
      *

+ 58
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetUncaughtExceptionHandler.java Visa fil

@@ -0,0 +1,58 @@
1
+/*
2
+ * Copyright @ 2018-present 8x8, Inc.
3
+ * Copyright @ 2017-2018 Atlassian Pty Ltd
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ *     http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+package org.jitsi.meet.sdk;
19
+
20
+import android.util.Log;
21
+
22
+class JitsiMeetUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
23
+    private final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler;
24
+
25
+    public static void register() {
26
+        Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
27
+
28
+        JitsiMeetUncaughtExceptionHandler uncaughtExceptionHandler
29
+            = new JitsiMeetUncaughtExceptionHandler(defaultUncaughtExceptionHandler);
30
+
31
+        Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
32
+    }
33
+
34
+    private JitsiMeetUncaughtExceptionHandler(Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler) {
35
+        this.defaultUncaughtExceptionHandler = defaultUncaughtExceptionHandler;
36
+    }
37
+
38
+    @Override
39
+    public void uncaughtException(Thread t, Throwable e) {
40
+        Log.e(this.getClass().getSimpleName(), "FATAL ERROR", e);
41
+
42
+        // Terminate all conferences
43
+        for (BaseReactView view: BaseReactView.getViews()) {
44
+            if (view instanceof JitsiMeetView) {
45
+                ((JitsiMeetView) view).leave();
46
+            }
47
+        }
48
+
49
+        // Abort all ConnectionService ongoing calls
50
+        if (AudioModeModule.useConnectionService()) {
51
+            ConnectionService.abortConnections();
52
+        }
53
+
54
+        if (defaultUncaughtExceptionHandler != null) {
55
+            defaultUncaughtExceptionHandler.uncaughtException(t, e);
56
+        }
57
+    }
58
+}

+ 3
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java Visa fil

@@ -182,5 +182,8 @@ class ReactInstanceManagerHolder {
182 182
         if (devSettings != null) {
183 183
             devSettings.setBundleDeltasEnabled(false);
184 184
         }
185
+
186
+        // Register our uncaught exception handler.
187
+        JitsiMeetUncaughtExceptionHandler.register();
185 188
     }
186 189
 }

Laddar…
Avbryt
Spara