diff options
| author | 2018-01-25 13:58:20 -0800 | |
|---|---|---|
| committer | 2018-01-25 14:26:48 -0800 | |
| commit | 80fa2d88b4465e74927f393bd73b04fc6ece7790 (patch) | |
| tree | c1c76cc2a94d2bc7de64d8a4f86304e219dc287e | |
| parent | bb2af291c55857f581a6d228959dc3e8f99ebfed (diff) | |
Add feature check before entering PIP.
Bug: 72063615
Test: ActivityManagerPinnedStackTests
Change-Id: I4bed3a39c28c62121db47b8a61dda2516e41d245
| -rw-r--r-- | core/java/android/app/Activity.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index cd029c06b91d..039328afa264 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -2136,11 +2136,15 @@ public class Activity extends ContextThemeWrapper * @param params non-null parameters to be combined with previously set parameters when entering * picture-in-picture. * - * @return true if the system puts this activity into picture-in-picture mode or was already - * in picture-in-picture mode (@see {@link #isInPictureInPictureMode()) + * @return true if the system successfully put this activity into picture-in-picture mode or was + * already in picture-in-picture mode (@see {@link #isInPictureInPictureMode()). If the device + * does not support picture-in-picture, return false. */ public boolean enterPictureInPictureMode(@NonNull PictureInPictureParams params) { try { + if (!deviceSupportsPictureInPictureMode()) { + return false; + } if (params == null) { throw new IllegalArgumentException("Expected non-null picture-in-picture params"); } @@ -2168,6 +2172,9 @@ public class Activity extends ContextThemeWrapper */ public void setPictureInPictureParams(@NonNull PictureInPictureParams params) { try { + if (!deviceSupportsPictureInPictureMode()) { + return; + } if (params == null) { throw new IllegalArgumentException("Expected non-null picture-in-picture params"); } @@ -2190,6 +2197,13 @@ public class Activity extends ContextThemeWrapper } } + /** + * @return Whether this device supports picture-in-picture. + */ + private boolean deviceSupportsPictureInPictureMode() { + return getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE); + } + void dispatchMovedToDisplay(int displayId, Configuration config) { updateDisplay(displayId); onMovedToDisplay(displayId, config); |