From ee17d352d641cdcfc955f0e37b0ca042427f2879 Mon Sep 17 00:00:00 2001 From: Charles He Date: Tue, 16 May 2017 14:55:35 +0100 Subject: [PATCH] Fingerprint: call onRemovalSucceeded with # of remaining templates. The onRemoved() callback from fingerprint daemon provides a "remaining" parameter which contains the number of fingerprint templates yet to be removed in the current removal operation. This is especially useful when a group is removed, as remaining == 0 indicates the end of the group removal. In this CL, we wire up FingerprintManager so that the "remaining" parameter gets passed to RemovalCallback#onRemovalSucceeded(). This would allow clients like Settings to make use of the information. Bug: 37938345 Test: manual, both with and without work profile Change-Id: Idf46ef42e1d178cd3dc267aaf4219f03e27be766 --- .../fingerprint/FingerprintManager.java | 63 +++++++++++-------- .../server/fingerprint/RemovalClient.java | 1 - 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/core/java/android/hardware/fingerprint/FingerprintManager.java b/core/java/android/hardware/fingerprint/FingerprintManager.java index 8e57e85ff80e6..b00e65a24fb70 100644 --- a/core/java/android/hardware/fingerprint/FingerprintManager.java +++ b/core/java/android/hardware/fingerprint/FingerprintManager.java @@ -100,8 +100,8 @@ public class FingerprintManager { public static final int FINGERPRINT_ERROR_CANCELED = 5; /** - * The {@link FingerprintManager#remove(Fingerprint, RemovalCallback)} call failed. Typically - * this will happen when the provided fingerprint id was incorrect. + * The {@link FingerprintManager#remove} call failed. Typically this will happen when the + * provided fingerprint id was incorrect. * * @hide */ @@ -398,10 +398,10 @@ public class FingerprintManager { }; /** - * Callback structure provided to {@link FingerprintManager#remove(int). Users of - * {@link #FingerprintManager()} may optionally provide an implementation of this to - * {@link FingerprintManager#remove(int, int, RemovalCallback)} for listening to - * fingerprint template removal events. + * Callback structure provided to {@link #remove}. Users of {@link FingerprintManager} may + * optionally provide an implementation of this to + * {@link #remove(Fingerprint, int, RemovalCallback)} for listening to fingerprint template + * removal events. * * @hide */ @@ -416,9 +416,13 @@ public class FingerprintManager { /** * Called when a given fingerprint is successfully removed. - * @param fingerprint the fingerprint template that was removed. + * @param fp The fingerprint template that was removed. + * @param remaining The number of fingerprints yet to be removed in this operation. If + * {@link #remove} is called on one fingerprint, this should be 0. If + * {@link #remove} is called on a group, this should be the number of remaining + * fingerprints in the group, and 0 after the last fingerprint is removed. */ - public void onRemovalSucceeded(Fingerprint fingerprint) { } + public void onRemovalSucceeded(Fingerprint fp, int remaining) { } }; /** @@ -878,8 +882,7 @@ public class FingerprintManager { msg.arg2 /* vendorCode */); break; case MSG_REMOVED: - sendRemovedResult((Long) msg.obj /* deviceId */, msg.arg1 /* fingerId */, - msg.arg2 /* groupId */); + sendRemovedResult((Fingerprint) msg.obj, msg.arg1 /* remaining */); break; case MSG_ENUMERATED: sendEnumeratedResult((Long) msg.obj /* deviceId */, msg.arg1 /* fingerId */, @@ -888,21 +891,29 @@ public class FingerprintManager { } } - private void sendRemovedResult(long deviceId, int fingerId, int groupId) { - if (mRemovalCallback != null) { - int reqFingerId = mRemovalFingerprint.getFingerId(); - int reqGroupId = mRemovalFingerprint.getGroupId(); - if (reqFingerId != 0 && fingerId != 0 && fingerId != reqFingerId) { - Log.w(TAG, "Finger id didn't match: " + fingerId + " != " + reqFingerId); - return; - } - if (groupId != reqGroupId) { - Log.w(TAG, "Group id didn't match: " + groupId + " != " + reqGroupId); - return; - } - mRemovalCallback.onRemovalSucceeded(new Fingerprint(null, groupId, fingerId, - deviceId)); + private void sendRemovedResult(Fingerprint fingerprint, int remaining) { + if (mRemovalCallback == null) { + return; } + if (fingerprint == null) { + Log.e(TAG, "Received MSG_REMOVED, but fingerprint is null"); + return; + } + + int fingerId = fingerprint.getFingerId(); + int reqFingerId = mRemovalFingerprint.getFingerId(); + if (reqFingerId != 0 && fingerId != 0 && fingerId != reqFingerId) { + Log.w(TAG, "Finger id didn't match: " + fingerId + " != " + reqFingerId); + return; + } + int groupId = fingerprint.getGroupId(); + int reqGroupId = mRemovalFingerprint.getGroupId(); + if (groupId != reqGroupId) { + Log.w(TAG, "Group id didn't match: " + groupId + " != " + reqGroupId); + return; + } + + mRemovalCallback.onRemovalSucceeded(fingerprint, remaining); } private void sendEnumeratedResult(long deviceId, int fingerId, int groupId) { @@ -1100,8 +1111,8 @@ public class FingerprintManager { @Override // binder call public void onRemoved(long deviceId, int fingerId, int groupId, int remaining) { - // TODO: propagate remaining - mHandler.obtainMessage(MSG_REMOVED, fingerId, groupId, deviceId).sendToTarget(); + mHandler.obtainMessage(MSG_REMOVED, remaining, 0, + new Fingerprint(null, groupId, fingerId, deviceId)).sendToTarget(); } @Override // binder call diff --git a/services/core/java/com/android/server/fingerprint/RemovalClient.java b/services/core/java/com/android/server/fingerprint/RemovalClient.java index 88a6bdda06dbc..8646107db9037 100644 --- a/services/core/java/com/android/server/fingerprint/RemovalClient.java +++ b/services/core/java/com/android/server/fingerprint/RemovalClient.java @@ -85,7 +85,6 @@ public abstract class RemovalClient extends ClientMonitor { IFingerprintServiceReceiver receiver = getReceiver(); try { if (receiver != null) { - // TODO: plumb remaining receiver.onRemoved(getHalDeviceId(), fingerId, groupId, remaining); } } catch (RemoteException e) {