Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e43e5b13 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Retrieve authenticatorId when already targetUserId

Previous change ag/13413165 stopped the framework from retrieving
authenticatorId when the current user is already the target user.
However, this happens immediately after enrollment, since enroll
and getAuthenticatorId are separate operations. So, add a way to
retrieve authenticatorId only when necessary.

Fixes: 179737483
Bug: 178018968
Test: manual
Change-Id: I71673fc672c60733616634a2fdf3153a3b2d02e1
parent e3ff87dd
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -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 {
+12 −4
Original line number Diff line number Diff line
@@ -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 */);
                    }
                }
            });
+4 −2
Original line number Diff line number Diff line
@@ -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;