Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc99e0e5 authored by Eric Biggers's avatar Eric Biggers
Browse files

Delete old failure_counter file when LSKF is changed

When an LSKF-based synthetic password protector is destroyed, all files
belonging to it should be deleted, including the failure_counter file.

Bug: 424597164
Test: atest FrameworksServicesTests:com.android.server.locksettings
Flag: EXEMPT trivial change that should not be flagged since we should
      clean up the file even if the flag goes from ENABLED => DISABLED.
Change-Id: Id95d589e8670914f85ccfdd9199db910c427cd98
parent 25fbdd63
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1822,6 +1822,7 @@ class SyntheticPasswordManager {
        destroyProtectorCommon(protectorId, userId);
        destroyState(PASSWORD_DATA_NAME, protectorId, userId);
        destroyState(PASSWORD_METRICS_NAME, protectorId, userId);
        destroyState(FAILURE_COUNTER_NAME, protectorId, userId);
    }

    private void destroyProtectorCommon(long protectorId, int userId) {
+17 −0
Original line number Diff line number Diff line
@@ -956,6 +956,23 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests {
        }
    }

    @Test
    public void testFailureCounterDeletedOnLskfChanged() throws Exception {
        final int userId = PRIMARY_USER_ID;
        final LockscreenCredential pin = newPin("1234");
        initSpAndSetCredential(userId, pin);
        final long oldProtectorId = mService.getCurrentLskfBasedProtectorId(userId);
        final LskfIdentifier oldLskfId = new LskfIdentifier(userId, oldProtectorId);

        mSpManager.writeFailureCounter(oldLskfId, 1);
        assertEquals(1, mSpManager.readFailureCounter(oldLskfId));
        assertTrue(mService.setLockCredential(nonePassword(), pin, userId));

        final long newProtectorId = mService.getCurrentLskfBasedProtectorId(userId);
        assertNotEquals(oldProtectorId, newProtectorId);
        assertEquals(0, mSpManager.readFailureCounter(oldLskfId));
    }

    // b/62213311
    //TODO: add non-migration work profile case, and unify/un-unify transition.
    //TODO: test token after user resets password