Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c47fa28 authored by Jacqueline Bronger's avatar Jacqueline Bronger
Browse files

TV PiP: don't throw exception if entry restricted

Throwing exception when PiP entry is not allowed could crash existing
apps, instead simply log a helpful error message and don't go into PiP
silently.

Bug: 377961265
Test: use app that requests PiP entry in onPause and check logsi
Test: atest PinnedStackTests
Flag: android.app.enable_tv_implicit_enter_pip_restriction
Change-Id: I2b8d3802c7172f5d572e97d1a37dd40330ef6e37
parent 0f0dd1c4
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -3174,6 +3174,15 @@ public class Activity extends ContextThemeWrapper
            throw new IllegalArgumentException("Expected non-null picture-in-picture params");
        }
        if (!mCanEnterPictureInPicture) {
            if (isTvImplicitEnterPipProhibited()) {
                // Don't throw exception on TV so that apps don't crash when not adapted to new
                // restrictions.
                Log.e(TAG,
                        "Activity must be resumed to enter picture-in-picture and not about to be"
                                + " paused. Implicit app entry is only permitted on TV if android"
                                + ".permission.TV_IMPLICIT_ENTER_PIP is held by the app.");
                return false;
            }
            throw new IllegalStateException("Activity must be resumed to enter"
                    + " picture-in-picture");
        }
@@ -3212,7 +3221,7 @@ public class Activity extends ContextThemeWrapper
        return ActivityTaskManager.getMaxNumPictureInPictureActions(this);
    }

    private boolean isImplicitEnterPipProhibited() {
    private boolean isTvImplicitEnterPipProhibited() {
        PackageManager pm = getPackageManager();
        if (android.app.Flags.enableTvImplicitEnterPipRestriction()) {
            return pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
@@ -9346,7 +9355,7 @@ public class Activity extends ContextThemeWrapper
                    + mComponent.getClassName());
        }

        if (isImplicitEnterPipProhibited()) {
        if (isTvImplicitEnterPipProhibited()) {
            mCanEnterPictureInPicture = false;
        }

@@ -9376,7 +9385,7 @@ public class Activity extends ContextThemeWrapper
    final void performUserLeaving() {
        onUserInteraction();

        if (isImplicitEnterPipProhibited()) {
        if (isTvImplicitEnterPipProhibited()) {
            mCanEnterPictureInPicture = false;
        }
        onUserLeaveHint();