Browse Source

android: disable PiP on Android Go devices

Despite running Android 8.1, they don't support Picture-in-Picture.
master
Saúl Ibarra Corretgé 4 years ago
parent
commit
ddaaeccafa

+ 2
- 3
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java View File

@@ -1,6 +1,5 @@
1 1
 /*
2
- * Copyright @ 2018-present 8x8, Inc.
3
- * Copyright @ 2017-2018 Atlassian Pty Ltd
2
+ * Copyright @ 2017-present 8x8, Inc.
4 3
  *
5 4
  * Licensed under the Apache License, Version 2.0 (the "License");
6 5
  * you may not use this file except in compliance with the License.
@@ -126,7 +125,7 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
126 125
             = ReactInstanceManagerHolder.getNativeModule(
127 126
                 PictureInPictureModule.class);
128 127
         if (pipModule != null
129
-                && PictureInPictureModule.isPictureInPictureSupported()
128
+                && pipModule.isPictureInPictureSupported()
130 129
                 && !JitsiMeetActivityDelegate.arePermissionsBeingRequested()
131 130
                 && this.url != null) {
132 131
             try {

+ 34
- 8
android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java View File

@@ -1,5 +1,5 @@
1 1
 /*
2
- * Copyright @ 2017-present Atlassian Pty Ltd
2
+ * Copyright @ 2017-present 8x8, Inc.
3 3
  *
4 4
  * Licensed under the Apache License, Version 2.0 (the "License");
5 5
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.jitsi.meet.sdk;
18 18
 
19 19
 import android.annotation.TargetApi;
20 20
 import android.app.Activity;
21
+import android.app.ActivityManager;
21 22
 import android.app.PictureInPictureParams;
22 23
 import android.os.Build;
23 24
 import android.util.Rational;
@@ -30,20 +31,41 @@ import com.facebook.react.module.annotations.ReactModule;
30 31
 
31 32
 import org.jitsi.meet.sdk.log.JitsiMeetLogger;
32 33
 
34
+import java.util.HashMap;
35
+import java.util.Map;
36
+
37
+import static android.content.Context.ACTIVITY_SERVICE;
38
+
33 39
 @ReactModule(name = PictureInPictureModule.NAME)
34
-class PictureInPictureModule
35
-    extends ReactContextBaseJavaModule {
40
+class PictureInPictureModule extends ReactContextBaseJavaModule {
36 41
 
37 42
     public static final String NAME = "PictureInPicture";
38
-
39 43
     private static final String TAG = NAME;
40 44
 
41
-    static boolean isPictureInPictureSupported() {
42
-        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
43
-    }
45
+    private static boolean isSupported;
44 46
 
45 47
     public PictureInPictureModule(ReactApplicationContext reactContext) {
46 48
         super(reactContext);
49
+
50
+        ActivityManager am = (ActivityManager) reactContext.getSystemService(ACTIVITY_SERVICE);
51
+
52
+        // Android Go devices don't support PiP. There doesn't seem to be a better way to detect it than
53
+        // to use ActivityManager.isLowRamDevice().
54
+        // https://stackoverflow.com/questions/58340558/how-to-detect-android-go
55
+        isSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !am.isLowRamDevice();
56
+    }
57
+
58
+    /**
59
+     * Gets a {@code Map} of constants this module exports to JS. Supports JSON
60
+     * types.
61
+     *
62
+     * @return a {@link Map} of constants this module exports to JS
63
+     */
64
+    @Override
65
+    public Map<String, Object> getConstants() {
66
+        Map<String, Object> constants = new HashMap<>();
67
+        constants.put("SUPPORTED", isSupported);
68
+        return constants;
47 69
     }
48 70
 
49 71
     /**
@@ -61,7 +83,7 @@ class PictureInPictureModule
61 83
      */
62 84
     @TargetApi(Build.VERSION_CODES.O)
63 85
     public void enterPictureInPicture() {
64
-        if (!isPictureInPictureSupported()) {
86
+        if (!isSupported) {
65 87
             throw new IllegalStateException("Picture-in-Picture not supported");
66 88
         }
67 89
 
@@ -104,6 +126,10 @@ class PictureInPictureModule
104 126
         }
105 127
     }
106 128
 
129
+    public boolean isPictureInPictureSupported() {
130
+        return isSupported;
131
+    }
132
+
107 133
     @Override
108 134
     public String getName() {
109 135
         return NAME;

+ 3
- 4
react/features/mobile/picture-in-picture/components/PictureInPictureButton.js View File

@@ -1,6 +1,6 @@
1 1
 // @flow
2 2
 
3
-import { Platform } from 'react-native';
3
+import { NativeModules, Platform } from 'react-native';
4 4
 
5 5
 import { PIP_ENABLED, getFeatureFlag } from '../../../base/flags';
6 6
 import { translate } from '../../../base/i18n';
@@ -66,9 +66,8 @@ function _mapStateToProps(state): Object {
66 66
     const flag = Boolean(getFeatureFlag(state, PIP_ENABLED));
67 67
     let enabled = flag;
68 68
 
69
-    // Override flag for Android < 26, PiP was introduced in Oreo.
70
-    // https://developer.android.com/guide/topics/ui/picture-in-picture
71
-    if (Platform.OS === 'android' && Platform.Version < 26) {
69
+    // Override flag for Android, since it might be unsupported.
70
+    if (Platform.OS === 'android' && !NativeModules.PictureInPicture.SUPPORTED) {
72 71
         enabled = false;
73 72
     }
74 73
 

Loading…
Cancel
Save