am 1099ad41: am 47e04090: Merge "Remove redundant cancel events from FingerprintService" into mnc-dev

* commit '1099ad41e315f5e2b3638d39a1698472d61ea302':
  Remove redundant cancel events from FingerprintService
This commit is contained in:
Vineeta Srivastava
2015-07-16 07:30:38 +00:00
committed by Android Git Automerger

View File

@@ -85,6 +85,7 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
private static final int FINGERPRINT_ACQUIRED_GOOD = 0; private static final int FINGERPRINT_ACQUIRED_GOOD = 0;
Handler mHandler = new Handler() { Handler mHandler = new Handler() {
@Override
public void handleMessage(android.os.Message msg) { public void handleMessage(android.os.Message msg) {
switch (msg.what) { switch (msg.what) {
case MSG_USER_SWITCHING: case MSG_USER_SWITCHING:
@@ -273,7 +274,7 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
Slog.w(TAG, "enroll: no fingeprintd!"); Slog.w(TAG, "enroll: no fingeprintd!");
return; return;
} }
stopPendingOperations(); stopPendingOperations(true);
mEnrollClient = new ClientMonitor(token, receiver, groupId, restricted); mEnrollClient = new ClientMonitor(token, receiver, groupId, restricted);
final int timeout = (int) (ENROLLMENT_TIMEOUT_MS / MS_PER_SEC); final int timeout = (int) (ENROLLMENT_TIMEOUT_MS / MS_PER_SEC);
try { try {
@@ -314,17 +315,23 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
return 0; return 0;
} }
private void stopPendingOperations() { private void stopPendingOperations(boolean initiatedByClient) {
if (mEnrollClient != null) { if (mEnrollClient != null) {
stopEnrollment(mEnrollClient.token, true); stopEnrollment(mEnrollClient.token, initiatedByClient);
} }
if (mAuthClient != null) { if (mAuthClient != null) {
stopAuthentication(mAuthClient.token, true); stopAuthentication(mAuthClient.token, initiatedByClient);
} }
// mRemoveClient is allowed to continue // mRemoveClient is allowed to continue
} }
void stopEnrollment(IBinder token, boolean notify) { /**
* Stop enrollment in progress and inform client if they initiated it.
*
* @param token token for client
* @param initiatedByClient if this call is the result of client action (e.g. calling cancel)
*/
void stopEnrollment(IBinder token, boolean initiatedByClient) {
IFingerprintDaemon daemon = getFingerprintDaemon(); IFingerprintDaemon daemon = getFingerprintDaemon();
if (daemon == null) { if (daemon == null) {
Slog.w(TAG, "stopEnrollment: no fingeprintd!"); Slog.w(TAG, "stopEnrollment: no fingeprintd!");
@@ -332,6 +339,7 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
} }
final ClientMonitor client = mEnrollClient; final ClientMonitor client = mEnrollClient;
if (client == null || client.token != token) return; if (client == null || client.token != token) return;
if (initiatedByClient) {
try { try {
int result = daemon.cancelEnrollment(); int result = daemon.cancelEnrollment();
if (result != 0) { if (result != 0) {
@@ -340,7 +348,6 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
} catch (RemoteException e) { } catch (RemoteException e) {
Slog.e(TAG, "stopEnrollment failed", e); Slog.e(TAG, "stopEnrollment failed", e);
} }
if (notify) {
client.sendError(FingerprintManager.FINGERPRINT_ERROR_CANCELED); client.sendError(FingerprintManager.FINGERPRINT_ERROR_CANCELED);
} }
removeClient(mEnrollClient); removeClient(mEnrollClient);
@@ -353,7 +360,7 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
Slog.w(TAG, "startAuthentication: no fingeprintd!"); Slog.w(TAG, "startAuthentication: no fingeprintd!");
return; return;
} }
stopPendingOperations(); stopPendingOperations(true);
mAuthClient = new ClientMonitor(token, receiver, groupId, restricted); mAuthClient = new ClientMonitor(token, receiver, groupId, restricted);
if (inLockoutMode()) { if (inLockoutMode()) {
Slog.v(TAG, "In lockout mode; disallowing authentication"); Slog.v(TAG, "In lockout mode; disallowing authentication");
@@ -373,7 +380,13 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
} }
} }
void stopAuthentication(IBinder token, boolean notify) { /**
* Stop authentication in progress and inform client if they initiated it.
*
* @param token token for client
* @param initiatedByClient if this call is the result of client action (e.g. calling cancel)
*/
void stopAuthentication(IBinder token, boolean initiatedByClient) {
IFingerprintDaemon daemon = getFingerprintDaemon(); IFingerprintDaemon daemon = getFingerprintDaemon();
if (daemon == null) { if (daemon == null) {
Slog.w(TAG, "stopAuthentication: no fingeprintd!"); Slog.w(TAG, "stopAuthentication: no fingeprintd!");
@@ -381,6 +394,7 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
} }
final ClientMonitor client = mAuthClient; final ClientMonitor client = mAuthClient;
if (client == null || client.token != token) return; if (client == null || client.token != token) return;
if (initiatedByClient) {
try { try {
int result = daemon.cancelAuthentication(); int result = daemon.cancelAuthentication();
if (result != 0) { if (result != 0) {
@@ -389,7 +403,6 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
} catch (RemoteException e) { } catch (RemoteException e) {
Slog.e(TAG, "stopAuthentication failed", e); Slog.e(TAG, "stopAuthentication failed", e);
} }
if (notify) {
client.sendError(FingerprintManager.FINGERPRINT_ERROR_CANCELED); client.sendError(FingerprintManager.FINGERPRINT_ERROR_CANCELED);
} }
removeClient(mAuthClient); removeClient(mAuthClient);
@@ -485,12 +498,14 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
receiver = null; receiver = null;
} }
@Override
public void binderDied() { public void binderDied() {
token = null; token = null;
removeClient(this); removeClient(this);
receiver = null; receiver = null;
} }
@Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (token != null) { if (token != null) {