android: disable PiP on Android Go devices

Despite running Android 8.1, they don't support Picture-in-Picture.
This commit is contained in:
Saúl Ibarra Corretgé 2020-07-21 11:13:24 +02:00 committed by Saúl Ibarra Corretgé
parent 0751c6ab48
commit ddaaeccafa
3 changed files with 39 additions and 15 deletions

View File

@ -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<JitsiMeetViewListener>
= ReactInstanceManagerHolder.getNativeModule(
PictureInPictureModule.class);
if (pipModule != null
&& PictureInPictureModule.isPictureInPictureSupported()
&& pipModule.isPictureInPictureSupported()
&& !JitsiMeetActivityDelegate.arePermissionsBeingRequested()
&& this.url != null) {
try {

View File

@ -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<String, Object> getConstants() {
Map<String, Object> 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;

View File

@ -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;
}