Merge "Retrieve authenticatorId when already targetUserId" into sc-dev

This commit is contained in:
Kevin Chyn
2021-02-17 22:17:07 +00:00
committed by Android (Google) Code Review
3 changed files with 16 additions and 7 deletions

View File

@@ -390,7 +390,6 @@ public class BiometricManager {
* in Keystore land as SIDs, and are used during key generation.
* @hide
*/
@RequiresPermission(USE_BIOMETRIC_INTERNAL)
public long[] getAuthenticatorIds() {
if (mService != null) {
try {

View File

@@ -463,26 +463,33 @@ public class Fingerprint21 implements IHwBinder.DeathRecipient, ServiceProvider
for (UserInfo user : UserManager.get(mContext).getAliveUsers()) {
final int targetUserId = user.id;
if (!mAuthenticatorIds.containsKey(targetUserId)) {
scheduleUpdateActiveUserWithoutHandler(targetUserId);
scheduleUpdateActiveUserWithoutHandler(targetUserId, true /* force */);
}
}
});
}
private void scheduleUpdateActiveUserWithoutHandler(int targetUserId) {
scheduleUpdateActiveUserWithoutHandler(targetUserId, false /* force */);
}
/**
* Schedules the {@link FingerprintUpdateActiveUserClient} without posting the work onto the
* handler. Many/most APIs are user-specific. However, the HAL requires explicit "setActiveUser"
* invocation prior to authenticate/enroll/etc. Thus, internally we usually want to schedule
* this operation on the same lambda/runnable as those operations so that the ordering is
* correct.
*
* @param targetUserId Switch to this user, and update their authenticatorId
* @param force Always retrieve the authenticatorId, even if we are already the targetUserId
*/
private void scheduleUpdateActiveUserWithoutHandler(int targetUserId) {
private void scheduleUpdateActiveUserWithoutHandler(int targetUserId, boolean force) {
final boolean hasEnrolled =
!getEnrolledFingerprints(mSensorProperties.sensorId, targetUserId).isEmpty();
final FingerprintUpdateActiveUserClient client =
new FingerprintUpdateActiveUserClient(mContext, mLazyDaemon, targetUserId,
mContext.getOpPackageName(), mSensorProperties.sensorId, mCurrentUserId,
hasEnrolled, mAuthenticatorIds);
hasEnrolled, mAuthenticatorIds, force);
mScheduler.scheduleClientMonitor(client, new BaseClientMonitor.Callback() {
@Override
public void onClientFinished(@NonNull BaseClientMonitor clientMonitor,
@@ -563,7 +570,8 @@ public class Fingerprint21 implements IHwBinder.DeathRecipient, ServiceProvider
boolean success) {
if (success) {
// Update authenticatorIds
scheduleUpdateActiveUserWithoutHandler(clientMonitor.getTargetUserId());
scheduleUpdateActiveUserWithoutHandler(clientMonitor.getTargetUserId(),
true /* force */);
}
}
});

View File

@@ -41,6 +41,7 @@ public class FingerprintUpdateActiveUserClient extends HalClientMonitor<IBiometr
private static final String FP_DATA_DIR = "fpdata";
private final int mCurrentUserId;
private final boolean mForceUpdateAuthenticatorId;
private final boolean mHasEnrolledBiometrics;
private final Map<Integer, Long> mAuthenticatorIds;
private File mDirectory;
@@ -48,11 +49,12 @@ public class FingerprintUpdateActiveUserClient extends HalClientMonitor<IBiometr
FingerprintUpdateActiveUserClient(@NonNull Context context,
@NonNull LazyDaemon<IBiometricsFingerprint> lazyDaemon, int userId,
@NonNull String owner, int sensorId, int currentUserId, boolean hasEnrolledBiometrics,
@NonNull Map<Integer, Long> authenticatorIds) {
@NonNull Map<Integer, Long> authenticatorIds, boolean forceUpdateAuthenticatorId) {
super(context, lazyDaemon, null /* token */, null /* listener */, userId, owner,
0 /* cookie */, sensorId, BiometricsProtoEnums.MODALITY_UNKNOWN,
BiometricsProtoEnums.ACTION_UNKNOWN, BiometricsProtoEnums.CLIENT_UNKNOWN);
mCurrentUserId = currentUserId;
mForceUpdateAuthenticatorId = forceUpdateAuthenticatorId;
mHasEnrolledBiometrics = hasEnrolledBiometrics;
mAuthenticatorIds = authenticatorIds;
}
@@ -61,7 +63,7 @@ public class FingerprintUpdateActiveUserClient extends HalClientMonitor<IBiometr
public void start(@NonNull Callback callback) {
super.start(callback);
if (mCurrentUserId == getTargetUserId()) {
if (mCurrentUserId == getTargetUserId() && !mForceUpdateAuthenticatorId) {
Slog.d(TAG, "Already user: " + mCurrentUserId + ", returning");
callback.onClientFinished(this, true /* success */);
return;