Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,13 @@ boolean enterAutoPictureInPicture() {

PictureInPictureParams params =
new PictureInPictureParams.Builder().setAspectRatio(getVideoAspectRatio()).build();
return activity.enterPictureInPictureMode(params);
try {
return activity.enterPictureInPictureMode(params);
} catch (IllegalStateException e) {
// Some OEM builds (e.g. Samsung Android 9 with TalkBack enabled) reject PiP in the
// system service even though FEATURE_PICTURE_IN_PICTURE is reported as supported.
return false;
}
}

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ public void enterAutoPictureInPictureEntersOnAndroid9WhenEligible() {
assertEquals(new Rational(16, 9), paramsCaptor.getValue().getAspectRatio());
}

@Test
@Config(sdk = 28)
public void enterAutoPictureInPictureReturnsFalseWhenSystemRejectsPip() {
Activity activity = mock(Activity.class);
PackageManager packageManager = mock(PackageManager.class);
when(activity.getPackageManager()).thenReturn(packageManager);
when(packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE))
.thenReturn(true);
when(fakeExoPlayer.isPlaying()).thenReturn(true);
when(activity.enterPictureInPictureMode(any(PictureInPictureParams.class)))
.thenThrow(
new IllegalStateException(
"enterPictureInPictureMode: Device doesn't support picture-in-picture mode."));

VideoPlayer videoPlayer = createVideoPlayer();
videoPlayer.setActivity(activity);
videoPlayer.setAutoPictureInPicture(true);

assertFalse(videoPlayer.enterAutoPictureInPicture());
verify(activity).enterPictureInPictureMode(any(PictureInPictureParams.class));
}

@Test
@Config(sdk = 28)
public void enterAutoPictureInPictureDoesNotEnterWhenIneligible() {
Expand Down