Loading services/core/java/com/android/server/wm/LockTaskController.java +15 −9 Original line number Diff line number Diff line Loading @@ -802,18 +802,24 @@ public class LockTaskController { * leaves the pinned mode. */ private void lockKeyguardIfNeeded() { try { boolean shouldLockKeyguard = Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, USER_CURRENT) != 0; if (shouldLockKeyguard) { if (shouldLockKeyguard()) { mWindowManager.lockNow(null); mWindowManager.dismissKeyguard(null /* callback */, null /* message */); getLockPatternUtils().requireCredentialEntry(USER_ALL); } } private boolean shouldLockKeyguard() { // This functionality should be kept consistent with // com.android.settings.security.ScreenPinningSettings (see b/127605586) try { return Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, USER_CURRENT) != 0; } catch (Settings.SettingNotFoundException e) { // No setting, don't lock. // Log to SafetyNet for b/127605586 android.util.EventLog.writeEvent(0x534e4554, "127605586", -1, ""); return mLockPatternUtils.isSecure(USER_CURRENT); } } Loading services/tests/wmtests/src/com/android/server/wm/LockTaskControllerTest.java +75 −1 Original line number Diff line number Diff line Loading @@ -407,7 +407,7 @@ public class LockTaskControllerTest { mLockTaskController.startLockTaskMode(tr1, false, TEST_UID); mLockTaskController.startLockTaskMode(tr2, false, TEST_UID); // WHEN calling stopLockTaskMode on the root task // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the lock task mode should be inactive Loading @@ -420,6 +420,80 @@ public class LockTaskControllerTest { verifyLockTaskStopped(times(1)); } @Test public void testClearLockedTasks_noLockSetting_noPassword_deviceIsUnlocked() throws Exception { // GIVEN There is no setting set for LOCK_TO_APP_EXIT_LOCKED Settings.Secure.clearProviderForTest(); // AND no password is set when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt())) .thenReturn(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); // AND there is a task record TaskRecord tr1 = getTaskRecord(TaskRecord.LOCK_TASK_AUTH_WHITELISTED); mLockTaskController.startLockTaskMode(tr1, true, TEST_UID); // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the device should not be locked verify(mWindowManager, never()).lockNow(any()); } @Test public void testClearLockedTasks_noLockSetting_password_deviceIsLocked() throws Exception { // GIVEN There is no setting set for LOCK_TO_APP_EXIT_LOCKED Settings.Secure.clearProviderForTest(); // AND a password is set when(mLockPatternUtils.isSecure(anyInt())) .thenReturn(true); // AND there is a task record TaskRecord tr1 = getTaskRecord(TaskRecord.LOCK_TASK_AUTH_WHITELISTED); mLockTaskController.startLockTaskMode(tr1, true, TEST_UID); // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the device should be locked verify(mWindowManager, times(1)).lockNow(any()); } @Test public void testClearLockedTasks_lockSettingTrue_deviceIsLocked() throws Exception { // GIVEN LOCK_TO_APP_EXIT_LOCKED is set to 1 Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, 1, mContext.getUserId()); // AND there is a task record TaskRecord tr1 = getTaskRecord(TaskRecord.LOCK_TASK_AUTH_WHITELISTED); mLockTaskController.startLockTaskMode(tr1, true, TEST_UID); // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the device should be locked verify(mWindowManager, times(1)).lockNow(any()); } @Test public void testClearLockedTasks_lockSettingFalse_doesNotRequirePassword() throws Exception { // GIVEN LOCK_TO_APP_EXIT_LOCKED is set to 1 Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, 0, mContext.getUserId()); // AND there is a task record TaskRecord tr1 = getTaskRecord(TaskRecord.LOCK_TASK_AUTH_WHITELISTED); mLockTaskController.startLockTaskMode(tr1, true, TEST_UID); // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the device should be unlocked verify(mWindowManager, never()).lockNow(any()); } @Test public void testUpdateLockTaskPackages() { String[] whitelist1 = {TEST_PACKAGE_NAME, TEST_PACKAGE_NAME_2}; Loading Loading
services/core/java/com/android/server/wm/LockTaskController.java +15 −9 Original line number Diff line number Diff line Loading @@ -802,18 +802,24 @@ public class LockTaskController { * leaves the pinned mode. */ private void lockKeyguardIfNeeded() { try { boolean shouldLockKeyguard = Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, USER_CURRENT) != 0; if (shouldLockKeyguard) { if (shouldLockKeyguard()) { mWindowManager.lockNow(null); mWindowManager.dismissKeyguard(null /* callback */, null /* message */); getLockPatternUtils().requireCredentialEntry(USER_ALL); } } private boolean shouldLockKeyguard() { // This functionality should be kept consistent with // com.android.settings.security.ScreenPinningSettings (see b/127605586) try { return Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, USER_CURRENT) != 0; } catch (Settings.SettingNotFoundException e) { // No setting, don't lock. // Log to SafetyNet for b/127605586 android.util.EventLog.writeEvent(0x534e4554, "127605586", -1, ""); return mLockPatternUtils.isSecure(USER_CURRENT); } } Loading
services/tests/wmtests/src/com/android/server/wm/LockTaskControllerTest.java +75 −1 Original line number Diff line number Diff line Loading @@ -407,7 +407,7 @@ public class LockTaskControllerTest { mLockTaskController.startLockTaskMode(tr1, false, TEST_UID); mLockTaskController.startLockTaskMode(tr2, false, TEST_UID); // WHEN calling stopLockTaskMode on the root task // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the lock task mode should be inactive Loading @@ -420,6 +420,80 @@ public class LockTaskControllerTest { verifyLockTaskStopped(times(1)); } @Test public void testClearLockedTasks_noLockSetting_noPassword_deviceIsUnlocked() throws Exception { // GIVEN There is no setting set for LOCK_TO_APP_EXIT_LOCKED Settings.Secure.clearProviderForTest(); // AND no password is set when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt())) .thenReturn(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); // AND there is a task record TaskRecord tr1 = getTaskRecord(TaskRecord.LOCK_TASK_AUTH_WHITELISTED); mLockTaskController.startLockTaskMode(tr1, true, TEST_UID); // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the device should not be locked verify(mWindowManager, never()).lockNow(any()); } @Test public void testClearLockedTasks_noLockSetting_password_deviceIsLocked() throws Exception { // GIVEN There is no setting set for LOCK_TO_APP_EXIT_LOCKED Settings.Secure.clearProviderForTest(); // AND a password is set when(mLockPatternUtils.isSecure(anyInt())) .thenReturn(true); // AND there is a task record TaskRecord tr1 = getTaskRecord(TaskRecord.LOCK_TASK_AUTH_WHITELISTED); mLockTaskController.startLockTaskMode(tr1, true, TEST_UID); // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the device should be locked verify(mWindowManager, times(1)).lockNow(any()); } @Test public void testClearLockedTasks_lockSettingTrue_deviceIsLocked() throws Exception { // GIVEN LOCK_TO_APP_EXIT_LOCKED is set to 1 Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, 1, mContext.getUserId()); // AND there is a task record TaskRecord tr1 = getTaskRecord(TaskRecord.LOCK_TASK_AUTH_WHITELISTED); mLockTaskController.startLockTaskMode(tr1, true, TEST_UID); // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the device should be locked verify(mWindowManager, times(1)).lockNow(any()); } @Test public void testClearLockedTasks_lockSettingFalse_doesNotRequirePassword() throws Exception { // GIVEN LOCK_TO_APP_EXIT_LOCKED is set to 1 Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, 0, mContext.getUserId()); // AND there is a task record TaskRecord tr1 = getTaskRecord(TaskRecord.LOCK_TASK_AUTH_WHITELISTED); mLockTaskController.startLockTaskMode(tr1, true, TEST_UID); // WHEN calling clearLockedTasks on the root task mLockTaskController.clearLockedTasks("testClearLockedTasks"); // THEN the device should be unlocked verify(mWindowManager, never()).lockNow(any()); } @Test public void testUpdateLockTaskPackages() { String[] whitelist1 = {TEST_PACKAGE_NAME, TEST_PACKAGE_NAME_2}; Loading