diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java index 9c1bb2bd0..e69004611 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java @@ -1,6 +1,5 @@ /* - * Copyright @ 2018-present 8x8, Inc. - * Copyright @ 2017-2018 Atlassian Pty Ltd + * Copyright @ 2017-present 8x8, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -126,7 +125,7 @@ public class JitsiMeetView extends BaseReactView = ReactInstanceManagerHolder.getNativeModule( PictureInPictureModule.class); if (pipModule != null - && PictureInPictureModule.isPictureInPictureSupported() + && pipModule.isPictureInPictureSupported() && !JitsiMeetActivityDelegate.arePermissionsBeingRequested() && this.url != null) { try { diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java index 2123334d5..a8edcd957 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java @@ -1,5 +1,5 @@ /* - * Copyright @ 2017-present Atlassian Pty Ltd + * Copyright @ 2017-present 8x8, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.jitsi.meet.sdk; import android.annotation.TargetApi; import android.app.Activity; +import android.app.ActivityManager; import android.app.PictureInPictureParams; import android.os.Build; import android.util.Rational; @@ -30,20 +31,41 @@ import com.facebook.react.module.annotations.ReactModule; import org.jitsi.meet.sdk.log.JitsiMeetLogger; +import java.util.HashMap; +import java.util.Map; + +import static android.content.Context.ACTIVITY_SERVICE; + @ReactModule(name = PictureInPictureModule.NAME) -class PictureInPictureModule - extends ReactContextBaseJavaModule { +class PictureInPictureModule extends ReactContextBaseJavaModule { public static final String NAME = "PictureInPicture"; - private static final String TAG = NAME; - static boolean isPictureInPictureSupported() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; - } + private static boolean isSupported; public PictureInPictureModule(ReactApplicationContext reactContext) { super(reactContext); + + ActivityManager am = (ActivityManager) reactContext.getSystemService(ACTIVITY_SERVICE); + + // Android Go devices don't support PiP. There doesn't seem to be a better way to detect it than + // to use ActivityManager.isLowRamDevice(). + // https://stackoverflow.com/questions/58340558/how-to-detect-android-go + isSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !am.isLowRamDevice(); + } + + /** + * Gets a {@code Map} of constants this module exports to JS. Supports JSON + * types. + * + * @return a {@link Map} of constants this module exports to JS + */ + @Override + public Map getConstants() { + Map constants = new HashMap<>(); + constants.put("SUPPORTED", isSupported); + return constants; } /** @@ -61,7 +83,7 @@ class PictureInPictureModule */ @TargetApi(Build.VERSION_CODES.O) public void enterPictureInPicture() { - if (!isPictureInPictureSupported()) { + if (!isSupported) { throw new IllegalStateException("Picture-in-Picture not supported"); } @@ -104,6 +126,10 @@ class PictureInPictureModule } } + public boolean isPictureInPictureSupported() { + return isSupported; + } + @Override public String getName() { return NAME; diff --git a/react/features/mobile/picture-in-picture/components/PictureInPictureButton.js b/react/features/mobile/picture-in-picture/components/PictureInPictureButton.js index 2212b7d1b..63220a56e 100644 --- a/react/features/mobile/picture-in-picture/components/PictureInPictureButton.js +++ b/react/features/mobile/picture-in-picture/components/PictureInPictureButton.js @@ -1,6 +1,6 @@ // @flow -import { Platform } from 'react-native'; +import { NativeModules, Platform } from 'react-native'; import { PIP_ENABLED, getFeatureFlag } from '../../../base/flags'; import { translate } from '../../../base/i18n'; @@ -66,9 +66,8 @@ function _mapStateToProps(state): Object { const flag = Boolean(getFeatureFlag(state, PIP_ENABLED)); let enabled = flag; - // Override flag for Android < 26, PiP was introduced in Oreo. - // https://developer.android.com/guide/topics/ui/picture-in-picture - if (Platform.OS === 'android' && Platform.Version < 26) { + // Override flag for Android, since it might be unsupported. + if (Platform.OS === 'android' && !NativeModules.PictureInPicture.SUPPORTED) { enabled = false; }