diff --git a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java index 26a9606f4c..3df081a2c6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java @@ -125,6 +125,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan private WindowLayoutInfoConsumer windowLayoutInfoConsumer; private WindowInfoTrackerCallbackAdapter windowInfoTrackerCallbackAdapter; private ThrottledDebouncer requestNewSizesThrottle; + private PictureInPictureParams.Builder pipBuilderParams; private Disposable ephemeralStateDisposable = Disposable.empty(); @@ -156,6 +157,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan initializeResources(); initializeViewModel(isLandscapeEnabled); + initializePictureInPictureParams(); processIntent(getIntent()); @@ -275,14 +277,16 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan } private boolean enterPipModeIfPossible() { - if (viewModel.canEnterPipMode() && isSystemPipEnabledAndAvailable()) { - PictureInPictureParams params = new PictureInPictureParams.Builder() - .setAspectRatio(new Rational(9, 16)) - .build(); - enterPictureInPictureMode(params); - CallParticipantsListDialog.dismiss(getSupportFragmentManager()); + if (isSystemPipEnabledAndAvailable()) { + if (viewModel.canEnterPipMode()) { + enterPictureInPictureMode(pipBuilderParams.build()); + CallParticipantsListDialog.dismiss(getSupportFragmentManager()); - return true; + return true; + } + if (Build.VERSION.SDK_INT >= 31) { + pipBuilderParams.setAutoEnterEnabled(false); + } } return false; } @@ -362,6 +366,19 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan }); } + private void initializePictureInPictureParams() { + if (isSystemPipEnabledAndAvailable()) { + pipBuilderParams = new PictureInPictureParams.Builder(); + pipBuilderParams.setAspectRatio(new Rational(9, 16)); + if (Build.VERSION.SDK_INT >= 31) { + pipBuilderParams.setAutoEnterEnabled(true); + } + if (Build.VERSION.SDK_INT >= 26) { + setPictureInPictureParams(pipBuilderParams.build()); + } + } + } + private void handleViewModelEvent(@NonNull WebRtcCallViewModel.Event event) { if (event instanceof WebRtcCallViewModel.Event.StartCall) { startCall(((WebRtcCallViewModel.Event.StartCall) event).isVideoCall());