From 37979c9db0a88039bb098645f4180dc04e987b96 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Fri, 5 Aug 2016 18:54:58 -0700 Subject: [PATCH] Fix bug where foreground activity fails to cancel auth/enrollment This fixes a bug where the currently authenticating application can't cancel itself in onPause(). The problem is that some applications can set FLAG_RESUME_WHILE_PAUSING (like the home screen), which changes the life cycle of IMPORTANCE_FOREGROUND to be removed before onPause() completes. The result is the currently authenticating activity can't cancel fingerprint authentication or enrollment. The fix is to allow apps to always cancel themselves. Fixes bug 30380234 Change-Id: If65c2028014da8d5129506d0b45cc6c1e25f7860 --- .../server/fingerprint/FingerprintService.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/fingerprint/FingerprintService.java b/services/core/java/com/android/server/fingerprint/FingerprintService.java index 1066434f10f17..df7fcb59b8c00 100644 --- a/services/core/java/com/android/server/fingerprint/FingerprintService.java +++ b/services/core/java/com/android/server/fingerprint/FingerprintService.java @@ -470,10 +470,10 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe /** * @param opPackageName name of package for caller - * @param foregroundOnly only allow this call while app is in the foreground + * @param requireForeground only allow this call while app is in the foreground * @return true if caller can use fingerprint API */ - private boolean canUseFingerprint(String opPackageName, boolean foregroundOnly, int uid, + private boolean canUseFingerprint(String opPackageName, boolean requireForeground, int uid, int pid) { checkPermission(USE_FINGERPRINT); if (isKeyguard(opPackageName)) { @@ -488,13 +488,21 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe Slog.w(TAG, "Rejecting " + opPackageName + " ; permission denied"); return false; } - if (foregroundOnly && !isForegroundActivity(uid, pid)) { + if (requireForeground && !(isForegroundActivity(uid, pid) || currentClient(opPackageName))){ Slog.w(TAG, "Rejecting " + opPackageName + " ; not in foreground"); return false; } return true; } + /** + * @param opPackageName package of the caller + * @return true if this is the same client currently using fingerprint + */ + private boolean currentClient(String opPackageName) { + return mCurrentClient != null && mCurrentClient.getOwnerString().equals(opPackageName); + } + /** * @param clientPackage * @return true if this is keyguard package