Merge changes from topic "face-profile-qt-dev" into qt-dev

* changes:
  Enroll for the correct user
  Do not updateActiveGroup on a handler
  Launch ConfirmDeviceCredential with actual userId
  Settings should be per-profile
This commit is contained in:
Kevin Chyn
2019-04-05 00:41:17 +00:00
committed by Android (Google) Code Review
3 changed files with 45 additions and 42 deletions

View File

@@ -351,6 +351,11 @@ public class BiometricService extends SystemService {
} }
private final class SettingObserver extends ContentObserver { private final class SettingObserver extends ContentObserver {
private static final boolean DEFAULT_KEYGUARD_ENABLED = true;
private static final boolean DEFAULT_APP_ENABLED = true;
private static final boolean DEFAULT_ALWAYS_REQUIRE_CONFIRMATION = false;
private final Uri FACE_UNLOCK_KEYGUARD_ENABLED = private final Uri FACE_UNLOCK_KEYGUARD_ENABLED =
Settings.Secure.getUriFor(Settings.Secure.FACE_UNLOCK_KEYGUARD_ENABLED); Settings.Secure.getUriFor(Settings.Secure.FACE_UNLOCK_KEYGUARD_ENABLED);
private final Uri FACE_UNLOCK_APP_ENABLED = private final Uri FACE_UNLOCK_APP_ENABLED =
@@ -359,9 +364,10 @@ public class BiometricService extends SystemService {
Settings.Secure.getUriFor(Settings.Secure.FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION); Settings.Secure.getUriFor(Settings.Secure.FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION);
private final ContentResolver mContentResolver; private final ContentResolver mContentResolver;
private boolean mFaceEnabledOnKeyguard;
private boolean mFaceEnabledForApps; private Map<Integer, Boolean> mFaceEnabledOnKeyguard = new HashMap<>();
private boolean mFaceAlwaysRequireConfirmation; private Map<Integer, Boolean> mFaceEnabledForApps = new HashMap<>();
private Map<Integer, Boolean> mFaceAlwaysRequireConfirmation = new HashMap<>();
/** /**
* Creates a content observer. * Creates a content observer.
@@ -379,63 +385,61 @@ public class BiometricService extends SystemService {
mContentResolver.registerContentObserver(FACE_UNLOCK_KEYGUARD_ENABLED, mContentResolver.registerContentObserver(FACE_UNLOCK_KEYGUARD_ENABLED,
false /* notifyForDescendents */, false /* notifyForDescendents */,
this /* observer */, this /* observer */,
UserHandle.USER_CURRENT); UserHandle.USER_ALL);
mContentResolver.registerContentObserver(FACE_UNLOCK_APP_ENABLED, mContentResolver.registerContentObserver(FACE_UNLOCK_APP_ENABLED,
false /* notifyForDescendents */, false /* notifyForDescendents */,
this /* observer */, this /* observer */,
UserHandle.USER_CURRENT); UserHandle.USER_ALL);
mContentResolver.registerContentObserver(FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, mContentResolver.registerContentObserver(FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION,
false /* notifyForDescendents */, false /* notifyForDescendents */,
this /* observer */, this /* observer */,
UserHandle.USER_CURRENT); UserHandle.USER_ALL);
// Update the value immediately
onChange(true /* selfChange */, FACE_UNLOCK_KEYGUARD_ENABLED);
onChange(true /* selfChange */, FACE_UNLOCK_APP_ENABLED);
onChange(true /* selfChange */, FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION);
} }
@Override @Override
public void onChange(boolean selfChange, Uri uri) { public void onChange(boolean selfChange, Uri uri, int userId) {
if (FACE_UNLOCK_KEYGUARD_ENABLED.equals(uri)) { if (FACE_UNLOCK_KEYGUARD_ENABLED.equals(uri)) {
mFaceEnabledOnKeyguard = mFaceEnabledOnKeyguard.put(userId, Settings.Secure.getIntForUser(
Settings.Secure.getIntForUser(
mContentResolver, mContentResolver,
Settings.Secure.FACE_UNLOCK_KEYGUARD_ENABLED, Settings.Secure.FACE_UNLOCK_KEYGUARD_ENABLED,
1 /* default */, DEFAULT_KEYGUARD_ENABLED ? 1 : 0 /* default */,
UserHandle.USER_CURRENT) != 0; userId) != 0);
List<EnabledOnKeyguardCallback> callbacks = mEnabledOnKeyguardCallbacks; if (userId == ActivityManager.getCurrentUser()) {
for (int i = 0; i < callbacks.size(); i++) { List<EnabledOnKeyguardCallback> callbacks = mEnabledOnKeyguardCallbacks;
callbacks.get(i).notify(BiometricSourceType.FACE, mFaceEnabledOnKeyguard); for (int i = 0; i < callbacks.size(); i++) {
callbacks.get(i).notify(BiometricSourceType.FACE,
mFaceEnabledOnKeyguard.getOrDefault(userId,
DEFAULT_KEYGUARD_ENABLED));
}
} }
} else if (FACE_UNLOCK_APP_ENABLED.equals(uri)) { } else if (FACE_UNLOCK_APP_ENABLED.equals(uri)) {
mFaceEnabledForApps = mFaceEnabledForApps.put(userId, Settings.Secure.getIntForUser(
Settings.Secure.getIntForUser(
mContentResolver, mContentResolver,
Settings.Secure.FACE_UNLOCK_APP_ENABLED, Settings.Secure.FACE_UNLOCK_APP_ENABLED,
1 /* default */, DEFAULT_APP_ENABLED ? 1 : 0 /* default */,
UserHandle.USER_CURRENT) != 0; userId) != 0);
} else if (FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION.equals(uri)) { } else if (FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION.equals(uri)) {
mFaceAlwaysRequireConfirmation = mFaceAlwaysRequireConfirmation.put(userId, Settings.Secure.getIntForUser(
Settings.Secure.getIntForUser(
mContentResolver, mContentResolver,
Settings.Secure.FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, Settings.Secure.FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION,
0 /* default */, DEFAULT_ALWAYS_REQUIRE_CONFIRMATION ? 1 : 0 /* default */,
UserHandle.USER_CURRENT) != 0; userId) != 0);
} }
} }
boolean getFaceEnabledOnKeyguard() { boolean getFaceEnabledOnKeyguard() {
return mFaceEnabledOnKeyguard; return mFaceEnabledOnKeyguard.getOrDefault(
ActivityManager.getCurrentUser(), DEFAULT_KEYGUARD_ENABLED);
} }
boolean getFaceEnabledForApps() { boolean getFaceEnabledForApps(int userId) {
return mFaceEnabledForApps; return mFaceEnabledForApps.getOrDefault(userId, DEFAULT_APP_ENABLED);
} }
boolean getFaceAlwaysRequireConfirmation() { boolean getFaceAlwaysRequireConfirmation(int userId) {
return mFaceAlwaysRequireConfirmation; return mFaceAlwaysRequireConfirmation
.getOrDefault(userId, DEFAULT_ALWAYS_REQUIRE_CONFIRMATION);
} }
} }
@@ -625,7 +629,7 @@ public class BiometricService extends SystemService {
mConfirmDeviceCredentialReceiver = receiver; mConfirmDeviceCredentialReceiver = receiver;
// Use this so we don't need to duplicate logic.. // Use this so we don't need to duplicate logic..
final Intent intent = kgm.createConfirmDeviceCredentialIntent(null /* title */, final Intent intent = kgm.createConfirmDeviceCredentialIntent(null /* title */,
null /* description */); null /* description */, userId);
// Then give it the bundle to do magic behavior.. // Then give it the bundle to do magic behavior..
intent.putExtra(KeyguardManager.EXTRA_BIOMETRIC_PROMPT_BUNDLE, bundle); intent.putExtra(KeyguardManager.EXTRA_BIOMETRIC_PROMPT_BUNDLE, bundle);
// Create a new task with this activity located at the root. // Create a new task with this activity located at the root.
@@ -884,7 +888,7 @@ public class BiometricService extends SystemService {
} }
if (authenticator.hasEnrolledTemplates(userId)) { if (authenticator.hasEnrolledTemplates(userId)) {
hasTemplatesEnrolled = true; hasTemplatesEnrolled = true;
if (isEnabledForApp(modality)) { if (isEnabledForApp(modality, userId)) {
// TODO(b/110907543): When face settings (and other settings) have both a // TODO(b/110907543): When face settings (and other settings) have both a
// user toggle as well as a work profile settings page, this needs to be // user toggle as well as a work profile settings page, this needs to be
// updated to reflect the correct setting. // updated to reflect the correct setting.
@@ -909,14 +913,14 @@ public class BiometricService extends SystemService {
return new Pair<>(modality, BiometricConstants.BIOMETRIC_SUCCESS); return new Pair<>(modality, BiometricConstants.BIOMETRIC_SUCCESS);
} }
private boolean isEnabledForApp(int modality) { private boolean isEnabledForApp(int modality, int userId) {
switch(modality) { switch(modality) {
case TYPE_FINGERPRINT: case TYPE_FINGERPRINT:
return true; return true;
case TYPE_IRIS: case TYPE_IRIS:
return true; return true;
case TYPE_FACE: case TYPE_FACE:
return mSettingObserver.getFaceEnabledForApps(); return mSettingObserver.getFaceEnabledForApps(userId);
default: default:
Slog.w(TAG, "Unsupported modality: " + modality); Slog.w(TAG, "Unsupported modality: " + modality);
return false; return false;
@@ -1363,7 +1367,7 @@ public class BiometricService extends SystemService {
if ((modality & TYPE_FACE) != 0) { if ((modality & TYPE_FACE) != 0) {
// Check if the user has forced confirmation to be required in Settings. // Check if the user has forced confirmation to be required in Settings.
requireConfirmation = requireConfirmation requireConfirmation = requireConfirmation
|| mSettingObserver.getFaceAlwaysRequireConfirmation(); || mSettingObserver.getFaceAlwaysRequireConfirmation(userId);
} }
// Generate random cookies to pass to the services that should prepare to start // Generate random cookies to pass to the services that should prepare to start
// authenticating. Store the cookie here and wait for all services to "ack" // authenticating. Store the cookie here and wait for all services to "ack"

View File

@@ -903,9 +903,8 @@ public abstract class BiometricServiceBase extends SystemService
} }
protected void setActiveUserInternal(int userId) { protected void setActiveUserInternal(int userId) {
mHandler.post(() -> { // Do not put on handler, since it should finish before returning to caller.
updateActiveGroup(userId, null /* clientPackage */); updateActiveGroup(userId, null /* clientPackage */);
});
} }
protected void removeInternal(RemovalClient client) { protected void removeInternal(RemovalClient client) {

View File

@@ -165,7 +165,7 @@ public class FaceService extends BiometricServiceBase {
} }
}; };
enrollInternal(client, UserHandle.getCallingUserId()); enrollInternal(client, mCurrentUserId);
} }
@Override // Binder call @Override // Binder call
@@ -813,7 +813,7 @@ public class FaceService extends BiometricServiceBase {
com.android.internal.R.integer.config_faceMaxTemplatesPerUser); com.android.internal.R.integer.config_faceMaxTemplatesPerUser);
final int enrolled = FaceService.this.getEnrolledTemplates(userId).size(); final int enrolled = FaceService.this.getEnrolledTemplates(userId).size();
if (enrolled >= limit) { if (enrolled >= limit) {
Slog.w(TAG, "Too many faces registered"); Slog.w(TAG, "Too many faces registered, user: " + userId);
return true; return true;
} }
return false; return false;