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

Commit 1497ec55 authored by Hao Dong's avatar Hao Dong
Browse files

Fix cleaning up all unknown hal templates.

Bug: 261577256
Test: manually tested on device, testing steps:
      1. manually add more than one unknown HAL templates
      2. switch to another user
      3. all unknown HAL templates should be cleared
Change-Id: Ic45301ab15dd83cdd946411e5b0b227f843602cb
parent 3f2da60d
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -113,7 +113,11 @@ public abstract class InternalCleanupClient<S extends BiometricAuthenticator.Ide
        @Override
        public void onClientFinished(@NonNull BaseClientMonitor clientMonitor, boolean success) {
            Slog.d(TAG, "Remove onClientFinished: " + clientMonitor + ", success: " + success);
            if (mUnknownHALTemplates.isEmpty()) {
                mCallback.onClientFinished(InternalCleanupClient.this, success);
            } else {
                startCleanupUnknownHalTemplates();
            }
        }
    };

@@ -237,4 +241,9 @@ public abstract class InternalCleanupClient<S extends BiometricAuthenticator.Ide
    public RemovalClient<S, T> getCurrentRemoveClient() {
        return (RemovalClient<S, T>) mCurrentTask;
    }

    @VisibleForTesting
    public ArrayList<UserTemplate> getUnknownHALTemplates() {
        return mUnknownHALTemplates;
    }
}
+26 −0
Original line number Diff line number Diff line
@@ -137,6 +137,32 @@ public class FingerprintInternalCleanupClientTest {
        verify(mCallback).onClientFinished(eq(mClient), eq(true));
    }

    @Test
    public void cleanupUnknownHalTemplatesAfterEnumerationWhenVirtualIsDisabled() {
        mClient = createClient();

        final List<Fingerprint> templates = List.of(
                new Fingerprint("one", 1, 1),
                new Fingerprint("two", 2, 1),
                new Fingerprint("three", 3, 1)
        );
        mClient.start(mCallback);
        for (int i = templates.size() - 1; i >= 0; i--) {
            mClient.getCurrentEnumerateClient().onEnumerationResult(templates.get(i), i);
        }
        // The first template is removed after enumeration
        assertThat(mClient.getUnknownHALTemplates().size()).isEqualTo(2);

        // Simulate finishing the removal of the first template.
        // |remaining| is 0 because one FingerprintRemovalClient is associated with only one
        // biometrics ID.
        mClient.getCurrentRemoveClient().onRemoved(templates.get(0), 0);
        assertThat(mClient.getUnknownHALTemplates().size()).isEqualTo(1);
        // Simulate finishing the removal of the second template.
        mClient.getCurrentRemoveClient().onRemoved(templates.get(1), 0);
        assertThat(mClient.getUnknownHALTemplates()).isEmpty();
    }

    protected FingerprintInternalCleanupClient createClient() {
        final List<Fingerprint> enrollments = new ArrayList<>();
        final Map<Integer, Long> authenticatorIds = new HashMap<>();