catch ISE when entering PIP

This commit is contained in:
Daniel Gultsch 2020-04-24 10:37:46 +02:00
parent 4f5415ecba
commit cacd85b4f1

View file

@ -12,6 +12,7 @@ import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.util.Log; import android.util.Log;
import android.util.Rational; import android.util.Rational;
@ -330,15 +331,26 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
public void onUserLeaveHint() { public void onUserLeaveHint() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && deviceSupportsPictureInPicture()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && deviceSupportsPictureInPicture()) {
if (shouldBePictureInPicture()) { if (shouldBePictureInPicture()) {
enterPictureInPictureMode( startPictureInPicture();
new PictureInPictureParams.Builder()
.setAspectRatio(new Rational(10, 16))
.build()
);
} }
} }
} }
@RequiresApi(api = Build.VERSION_CODES.O)
private void startPictureInPicture() {
try {
enterPictureInPictureMode(
new PictureInPictureParams.Builder()
.setAspectRatio(new Rational(10, 16))
.build()
);
} catch (IllegalStateException e) {
//this sometimes happens on Samsung phones (possibly when Knox is enabled)
Log.w(Config.LOGTAG, "unable to enter picture in picture mode", e);
}
}
private boolean deviceSupportsPictureInPicture() { private boolean deviceSupportsPictureInPicture() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE); return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);