diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index 8c34776717307..a06fa1b8dcfe0 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -2043,7 +2043,7 @@ final class ActivityManagerShellCommand extends ShellCommand { mInterface.stopLockTaskMode(); } else { int taskId = Integer.parseInt(taskIdStr); - mInterface.startLockTaskModeById(taskId); + mInterface.startSystemLockTaskMode(taskId); } pw.println("Activity manager is " + (mInterface.isInLockTaskMode() ? "" : "not ") + "in lockTaskMode"); diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index cd28da7f938db..7fea843b5ff2e 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -17,6 +17,7 @@ package com.android.server.am; import static android.app.ActivityManager.ENABLE_TASK_SNAPSHOTS; +import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; import static android.app.ActivityManager.StackId; import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; @@ -947,25 +948,30 @@ final class ActivityRecord implements AppWindowContainerListener { * the activity is not currently visible and {@param noThrow} is not set. */ boolean checkEnterPictureInPictureState(String caller, boolean noThrow) { + boolean isCurrentAppLocked = mStackSupervisor.getLockTaskModeState() != LOCK_TASK_MODE_NONE; boolean isKeyguardLocked = service.isKeyguardLocked(); boolean hasPinnedStack = mStackSupervisor.getStack(PINNED_STACK_ID) != null; + // Don't return early if !isNotLocked, since we want to throw an exception if the activity + // is in an incorrect state + boolean isNotLocked = !isKeyguardLocked && !isCurrentAppLocked; switch (state) { case RESUMED: - // When visible, allow entering PiP if not on the lockscreen. If there is another - // PiP activity, the logic to handle that comes later in enterPictureInPictureMode() - return !isKeyguardLocked; + // When visible, allow entering PiP if not on the lockscreen and if the task is not + // locked + return isNotLocked; case PAUSING: case PAUSED: - // When pausing, only allow enter PiP if not on the lockscreen and there is not - // already an existing PiP activity - return !isKeyguardLocked && !hasPinnedStack && supportsPictureInPictureWhilePausing + // When pausing, then only allow enter PiP as in the resume state, and in addition, + // require that there is not an existing PiP activity and that the current system + // state supports entering PiP + return isNotLocked && !hasPinnedStack && supportsPictureInPictureWhilePausing && checkEnterPictureInPictureOnHideAppOpsState(); case STOPPING: // When stopping in a valid state, then only allow enter PiP as in the pause state. // Otherwise, fall through to throw an exception if the caller is trying to enter // PiP in an invalid stopping state. if (supportsPictureInPictureWhilePausing) { - return !isKeyguardLocked && !hasPinnedStack + return isNotLocked && !hasPinnedStack && checkEnterPictureInPictureOnHideAppOpsState(); } default: