Loading services/core/java/com/android/server/wm/ActivityStarter.java +11 −9 Original line number Diff line number Diff line Loading @@ -1665,11 +1665,6 @@ class ActivityStarter { final Task taskToAffiliate = (mLaunchTaskBehind && mSourceRecord != null) ? mSourceRecord.getTask() : null; setNewTask(taskToAffiliate); if (mService.getLockTaskController().isLockTaskModeViolation( mStartActivity.getTask())) { Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); return START_RETURN_LOCK_TASK_MODE_VIOLATION; } } else if (mAddingToTask) { addOrReparentStartingActivity(targetTask, "adding to task"); } Loading Loading @@ -1848,11 +1843,18 @@ class ActivityStarter { final boolean isNewClearTask = (mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); if (!newTask && mService.getLockTaskController().isLockTaskModeViolation(targetTask, if (!newTask) { if (mService.getLockTaskController().isLockTaskModeViolation(targetTask, isNewClearTask)) { Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); return START_RETURN_LOCK_TASK_MODE_VIOLATION; } } else { if (mService.getLockTaskController().isNewTaskLockTaskModeViolation(mStartActivity)) { Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); return START_RETURN_LOCK_TASK_MODE_VIOLATION; } } return START_SUCCESS; } Loading services/core/java/com/android/server/wm/LockTaskController.java +33 −18 Original line number Diff line number Diff line Loading @@ -274,11 +274,10 @@ public class LockTaskController { } /** * @return whether the requested task is allowed to be locked (either allowlisted, or declares * lockTaskMode="always" in the manifest). * @return whether the requested task auth is allowed to be locked. */ boolean isTaskAllowlisted(Task task) { switch(task.mLockTaskAuth) { static boolean isTaskAuthAllowlisted(int lockTaskAuth) { switch(lockTaskAuth) { case LOCK_TASK_AUTH_ALLOWLISTED: case LOCK_TASK_AUTH_LAUNCHABLE: case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: Loading @@ -302,7 +301,30 @@ public class LockTaskController { * @return whether the requested task is disallowed to be launched. */ boolean isLockTaskModeViolation(Task task, boolean isNewClearTask) { if (isLockTaskModeViolationInternal(task, isNewClearTask)) { // TODO: Double check what's going on here. If the task is already in lock task mode, it's // likely allowlisted, so will return false below. if (isTaskLocked(task) && !isNewClearTask) { // If the task is already at the top and won't be cleared, then allow the operation } else if (isLockTaskModeViolationInternal(task, task.mUserId, task.intent, task.mLockTaskAuth)) { showLockTaskToast(); return true; } return false; } /** * @param activity an activity that is going to be started in a new task as the root activity. * @return whether the given activity is allowed to be launched. */ boolean isNewTaskLockTaskModeViolation(ActivityRecord activity) { // Use the belong task (if any) to perform the lock task checks if (activity.getTask() != null) { return isLockTaskModeViolation(activity.getTask()); } int auth = getLockTaskAuth(activity, null /* task */); if (isLockTaskModeViolationInternal(activity, activity.mUserId, activity.intent, auth)) { showLockTaskToast(); return true; } Loading @@ -319,25 +341,19 @@ public class LockTaskController { return mLockTaskModeTasks.get(0); } private boolean isLockTaskModeViolationInternal(Task task, boolean isNewClearTask) { // TODO: Double check what's going on here. If the task is already in lock task mode, it's // likely allowlisted, so will return false below. if (isTaskLocked(task) && !isNewClearTask) { // If the task is already at the top and won't be cleared, then allow the operation return false; } private boolean isLockTaskModeViolationInternal(WindowContainer wc, int userId, Intent intent, int taskAuth) { // Allow recents activity if enabled by policy if (task.isActivityTypeRecents() && isRecentsAllowed(task.mUserId)) { if (wc.isActivityTypeRecents() && isRecentsAllowed(userId)) { return false; } // Allow emergency calling when the device is protected by a locked keyguard if (isKeyguardAllowed(task.mUserId) && isEmergencyCallTask(task)) { if (isKeyguardAllowed(userId) && isEmergencyCallIntent(intent)) { return false; } return !(isTaskAllowlisted(task) || mLockTaskModeTasks.isEmpty()); return !(isTaskAuthAllowlisted(taskAuth) || mLockTaskModeTasks.isEmpty()); } private boolean isRecentsAllowed(int userId) { Loading Loading @@ -369,8 +385,7 @@ public class LockTaskController { return isPackageAllowlisted(userId, packageName); } private boolean isEmergencyCallTask(Task task) { final Intent intent = task.intent; private boolean isEmergencyCallIntent(Intent intent) { if (intent == null) { return false; } Loading services/core/java/com/android/server/wm/RecentTasks.java +2 −2 Original line number Diff line number Diff line Loading @@ -658,8 +658,8 @@ class RecentTasks { } for (int i = mTasks.size() - 1; i >= 0; --i) { final Task task = mTasks.get(i); if (task.mUserId == userId && !mService.getLockTaskController().isTaskAllowlisted(task)) { if (task.mUserId == userId && !mService.getLockTaskController().isTaskAuthAllowlisted( task.mLockTaskAuth)) { remove(task); } } Loading services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java +1 −1 Original line number Diff line number Diff line Loading @@ -486,7 +486,7 @@ public class ActivityStarterTests extends WindowTestsBase { final ActivityStarter starter = prepareStarter(0); final LockTaskController lockTaskController = mAtm.getLockTaskController(); doReturn(true).when(lockTaskController).isLockTaskModeViolation(any()); doReturn(true).when(lockTaskController).isNewTaskLockTaskModeViolation(any()); final int result = starter.setReason("testTaskModeViolation").execute(); Loading Loading
services/core/java/com/android/server/wm/ActivityStarter.java +11 −9 Original line number Diff line number Diff line Loading @@ -1665,11 +1665,6 @@ class ActivityStarter { final Task taskToAffiliate = (mLaunchTaskBehind && mSourceRecord != null) ? mSourceRecord.getTask() : null; setNewTask(taskToAffiliate); if (mService.getLockTaskController().isLockTaskModeViolation( mStartActivity.getTask())) { Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); return START_RETURN_LOCK_TASK_MODE_VIOLATION; } } else if (mAddingToTask) { addOrReparentStartingActivity(targetTask, "adding to task"); } Loading Loading @@ -1848,11 +1843,18 @@ class ActivityStarter { final boolean isNewClearTask = (mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); if (!newTask && mService.getLockTaskController().isLockTaskModeViolation(targetTask, if (!newTask) { if (mService.getLockTaskController().isLockTaskModeViolation(targetTask, isNewClearTask)) { Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); return START_RETURN_LOCK_TASK_MODE_VIOLATION; } } else { if (mService.getLockTaskController().isNewTaskLockTaskModeViolation(mStartActivity)) { Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); return START_RETURN_LOCK_TASK_MODE_VIOLATION; } } return START_SUCCESS; } Loading
services/core/java/com/android/server/wm/LockTaskController.java +33 −18 Original line number Diff line number Diff line Loading @@ -274,11 +274,10 @@ public class LockTaskController { } /** * @return whether the requested task is allowed to be locked (either allowlisted, or declares * lockTaskMode="always" in the manifest). * @return whether the requested task auth is allowed to be locked. */ boolean isTaskAllowlisted(Task task) { switch(task.mLockTaskAuth) { static boolean isTaskAuthAllowlisted(int lockTaskAuth) { switch(lockTaskAuth) { case LOCK_TASK_AUTH_ALLOWLISTED: case LOCK_TASK_AUTH_LAUNCHABLE: case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: Loading @@ -302,7 +301,30 @@ public class LockTaskController { * @return whether the requested task is disallowed to be launched. */ boolean isLockTaskModeViolation(Task task, boolean isNewClearTask) { if (isLockTaskModeViolationInternal(task, isNewClearTask)) { // TODO: Double check what's going on here. If the task is already in lock task mode, it's // likely allowlisted, so will return false below. if (isTaskLocked(task) && !isNewClearTask) { // If the task is already at the top and won't be cleared, then allow the operation } else if (isLockTaskModeViolationInternal(task, task.mUserId, task.intent, task.mLockTaskAuth)) { showLockTaskToast(); return true; } return false; } /** * @param activity an activity that is going to be started in a new task as the root activity. * @return whether the given activity is allowed to be launched. */ boolean isNewTaskLockTaskModeViolation(ActivityRecord activity) { // Use the belong task (if any) to perform the lock task checks if (activity.getTask() != null) { return isLockTaskModeViolation(activity.getTask()); } int auth = getLockTaskAuth(activity, null /* task */); if (isLockTaskModeViolationInternal(activity, activity.mUserId, activity.intent, auth)) { showLockTaskToast(); return true; } Loading @@ -319,25 +341,19 @@ public class LockTaskController { return mLockTaskModeTasks.get(0); } private boolean isLockTaskModeViolationInternal(Task task, boolean isNewClearTask) { // TODO: Double check what's going on here. If the task is already in lock task mode, it's // likely allowlisted, so will return false below. if (isTaskLocked(task) && !isNewClearTask) { // If the task is already at the top and won't be cleared, then allow the operation return false; } private boolean isLockTaskModeViolationInternal(WindowContainer wc, int userId, Intent intent, int taskAuth) { // Allow recents activity if enabled by policy if (task.isActivityTypeRecents() && isRecentsAllowed(task.mUserId)) { if (wc.isActivityTypeRecents() && isRecentsAllowed(userId)) { return false; } // Allow emergency calling when the device is protected by a locked keyguard if (isKeyguardAllowed(task.mUserId) && isEmergencyCallTask(task)) { if (isKeyguardAllowed(userId) && isEmergencyCallIntent(intent)) { return false; } return !(isTaskAllowlisted(task) || mLockTaskModeTasks.isEmpty()); return !(isTaskAuthAllowlisted(taskAuth) || mLockTaskModeTasks.isEmpty()); } private boolean isRecentsAllowed(int userId) { Loading Loading @@ -369,8 +385,7 @@ public class LockTaskController { return isPackageAllowlisted(userId, packageName); } private boolean isEmergencyCallTask(Task task) { final Intent intent = task.intent; private boolean isEmergencyCallIntent(Intent intent) { if (intent == null) { return false; } Loading
services/core/java/com/android/server/wm/RecentTasks.java +2 −2 Original line number Diff line number Diff line Loading @@ -658,8 +658,8 @@ class RecentTasks { } for (int i = mTasks.size() - 1; i >= 0; --i) { final Task task = mTasks.get(i); if (task.mUserId == userId && !mService.getLockTaskController().isTaskAllowlisted(task)) { if (task.mUserId == userId && !mService.getLockTaskController().isTaskAuthAllowlisted( task.mLockTaskAuth)) { remove(task); } } Loading
services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java +1 −1 Original line number Diff line number Diff line Loading @@ -486,7 +486,7 @@ public class ActivityStarterTests extends WindowTestsBase { final ActivityStarter starter = prepareStarter(0); final LockTaskController lockTaskController = mAtm.getLockTaskController(); doReturn(true).when(lockTaskController).isLockTaskModeViolation(any()); doReturn(true).when(lockTaskController).isNewTaskLockTaskModeViolation(any()); final int result = starter.setReason("testTaskModeViolation").execute(); Loading