From 57bbe3f75ac59a7b5cec79644d01be94d4988cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 15 Sep 2020 11:07:20 +0200 Subject: [PATCH] android: fix crash when requesting permissions The RN Permissions module calls this in a non-UI thread. What we observe is a crash in ViewGroup.dispatchCancelPendingInputEvents, which is called on the calling (ie, non-UI) thread. This doesn't look very safe, so try to avoid a crash by pretending the permission was denied. --- .../jitsi/meet/sdk/JitsiMeetActivityDelegate.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivityDelegate.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivityDelegate.java index 1a1147f39..b20f2b972 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivityDelegate.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivityDelegate.java @@ -24,6 +24,8 @@ import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactContext; import com.facebook.react.modules.core.PermissionListener; +import org.jitsi.meet.sdk.log.JitsiMeetLogger; + /** * Helper class to encapsulate the work which needs to be done on * {@link Activity} lifecycle methods in order for the React side to be aware of @@ -177,6 +179,16 @@ public class JitsiMeetActivityDelegate { public static void requestPermissions(Activity activity, String[] permissions, int requestCode, PermissionListener listener) { permissionListener = listener; - activity.requestPermissions(permissions, requestCode); + + // The RN Permissions module calls this in a non-UI thread. What we observe is a crash in ViewGroup.dispatchCancelPendingInputEvents, + // which is called on the calling (ie, non-UI) thread. This doesn't look very safe, so try to avoid a crash by pretending the permission + // was denied. + + try { + activity.requestPermissions(permissions, requestCode); + } catch (Exception e) { + JitsiMeetLogger.e(e, "Error requesting permissions"); + onRequestPermissionsResult(requestCode, permissions, new int[0]); + } } }