From cacd85b4f1b4b056772de43dedda913157bf170b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 24 Apr 2020 10:37:46 +0200 Subject: [PATCH] catch ISE when entering PIP --- .../conversations/ui/RtpSessionActivity.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 33a82e977..4758cdca9 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -12,6 +12,7 @@ import android.os.Bundle; import android.os.PowerManager; import android.os.SystemClock; import android.support.annotation.NonNull; +import android.support.annotation.RequiresApi; import android.support.annotation.StringRes; import android.util.Log; import android.util.Rational; @@ -330,15 +331,26 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe public void onUserLeaveHint() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && deviceSupportsPictureInPicture()) { if (shouldBePictureInPicture()) { - enterPictureInPictureMode( - new PictureInPictureParams.Builder() - .setAspectRatio(new Rational(10, 16)) - .build() - ); + startPictureInPicture(); } } } + + @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() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);