From 71d463f0633d6b2fdd34b8ee6a177ff2a3a683a0 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 21 Apr 2018 21:32:59 -0700 Subject: [PATCH] Avoid crashing from unexpected enterPictureInPictureMode() exceptions --- app/src/main/java/com/limelight/Game.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index 4f64e256..3c2eba1e 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -431,13 +431,20 @@ public class Game extends Activity implements SurfaceHolder.Callback, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (prefConfig.enablePip && connected) { - enterPictureInPictureMode( - new PictureInPictureParams.Builder() - .setAspectRatio(new Rational(prefConfig.width, prefConfig.height)) - .setSourceRectHint(new Rect( - streamView.getLeft(), streamView.getTop(), - streamView.getRight(), streamView.getBottom())) - .build()); + try { + // This has thrown all sorts of weird exceptions on Samsung devices + // running Oreo. Just eat them and close gracefully on leave, rather + // than crashing. + enterPictureInPictureMode( + new PictureInPictureParams.Builder() + .setAspectRatio(new Rational(prefConfig.width, prefConfig.height)) + .setSourceRectHint(new Rect( + streamView.getLeft(), streamView.getTop(), + streamView.getRight(), streamView.getBottom())) + .build()); + } catch (Exception e) { + e.printStackTrace(); + } } } }