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

Commit 51a4fd95 authored by Hao Dong's avatar Hao Dong Committed by Android (Google) Code Review
Browse files

Merge "Fix cleaning up all unknown hal templates."

parents 9e58bd06 1497ec55
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<>();