Parcourir la source

fix(PictureInPictureModule): catch the RuntimeException

Activity.enterPictureInPictureMode can fail for a couple of reasons
mentioned in the JSDoc:

"The system may disallow entering picture-in-picture in various cases,
including when the activity is not visible, if the screen is locked or
if the user has an activity pinned."

It seems to be safe to assume that those cases will be caught by
a RuntimeException handler (only RuntimeExceptions can be left without
explicit catch block).

Anyway the root cause for problems is the fact that the current process
for going to the picture in picture mode is not synchronised with
Activity's lifecycle. On Activity's "userLeaveHint" callback we dispatch
async task to the JS code which only then after dispatching some more
stuff eventually call native method that enter PiP. In case we spend too
much time on the JS side and the Activity goes to PAUSED state the call
will fail with IllegalStatException: "activity is not visible",
"activity is paused" etc. This means with this fix the app will not
crash, but we'll see it sometimes not go to the PiP mode as expected.
master
paweldomas il y a 7 ans
Parent
révision
9cbcbf6e26

+ 17
- 5
android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java Voir le fichier

@@ -44,14 +44,26 @@ public class PictureInPictureModule extends ReactContextBaseJavaModule {
44 44
             PictureInPictureParams.Builder builder
45 45
                 = new PictureInPictureParams.Builder()
46 46
                     .setAspectRatio(new Rational(1, 1));
47
-            boolean r
48
-                = currentActivity.enterPictureInPictureMode(builder.build());
47
+            Throwable error;
49 48
 
50
-            if (r) {
49
+            // https://developer.android.com/reference/android/app/Activity.html#enterPictureInPictureMode(android.app.PictureInPictureParams)
50
+            //
51
+            // The system may disallow entering picture-in-picture in various
52
+            // cases, including when the activity is not visible, if the screen
53
+            // is locked or if the user has an activity pinned.
54
+            try {
55
+                error
56
+                    = currentActivity.enterPictureInPictureMode(builder.build())
57
+                        ? null
58
+                        : new Exception("Failed to enter Picture-in-Picture");
59
+            } catch (RuntimeException re) {
60
+                error = re;
61
+            }
62
+
63
+            if (error == null) {
51 64
                 promise.resolve(null);
52 65
             } else {
53
-                promise.reject(
54
-                    new Exception("Failed to enter Picture-in-Picture"));
66
+                promise.reject(error);
55 67
             }
56 68
 
57 69
             return;

+ 4
- 0
react/features/mobile/picture-in-picture/actions.js Voir le fichier

@@ -23,6 +23,10 @@ export function enterPictureInPicture() {
23 23
     return (dispatch: Dispatch, getState: Function) => {
24 24
         const state = getState();
25 25
         const { app } = state['features/app'];
26
+
27
+        // FIXME We want to be able to enter Picture-in-Picture as soon as we
28
+        // are on the Conference page i.e. even before `joining` was set in the
29
+        // reducer.
26 30
         const { conference, joining } = state['features/base/conference'];
27 31
 
28 32
         if (app

Chargement…
Annuler
Enregistrer