diff options
| author | 2025-03-19 19:37:17 +0100 | |
|---|---|---|
| committer | 2025-03-19 19:37:17 +0100 | |
| commit | 7c47fa2871f4112b676ef209e334abe751406ea0 (patch) | |
| tree | 970cf616a66fc7b3fd4b9db0727db67c08fa2456 | |
| parent | 0f0dd1c43fb25781467c093b8780452383adaddd (diff) | |
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
| -rw-r--r-- | core/java/android/app/Activity.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index d5df48a2ea22..c129fde3f819 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -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(); |