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

Commit 40983d08 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

26/n: Move ClientActiveCallbacks to its own file

This logic is fingerprint-only and will eventually be need to
be updated when multiple HIDLs are supported. Most likely clients
will be notified when _any_ HIDL is authenticating/enrolling

Bug: 157790417

Test: AccessibilityFingerprintGestureTest
Change-Id: Ie07345fd62aa0a182d570a5c349f023b392cc73e
parent cc6b2ba4
Loading
Loading
Loading
Loading
+5 −15
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.app.AppOpsManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.hardware.biometrics.IBiometricSensorReceiver;
@@ -84,7 +83,6 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * A service to manage multiple clients that want to access the fingerprint HAL API.
@@ -101,6 +99,7 @@ public class FingerprintService extends BiometricServiceBase<IBiometricsFingerpr

    private final LockoutResetTracker mLockoutResetTracker;
    private final ClientMonitor.LazyDaemon<IBiometricsFingerprint> mLazyDaemon;
    private final GestureAvailabilityTracker mGestureAvailabilityTracker;

    /**
     * Receives the incoming binder calls from FingerprintManager.
@@ -358,13 +357,13 @@ public class FingerprintService extends BiometricServiceBase<IBiometricsFingerpr
        @Override
        public void addClientActiveCallback(IFingerprintClientActiveCallback callback) {
            checkPermission(MANAGE_FINGERPRINT);
            mClientActiveCallbacks.add(callback);
            mGestureAvailabilityTracker.registerCallback(callback);
        }

        @Override
        public void removeClientActiveCallback(IFingerprintClientActiveCallback callback) {
            checkPermission(MANAGE_FINGERPRINT);
            mClientActiveCallbacks.remove(callback);
            mGestureAvailabilityTracker.removeCallback(callback);
        }

        @Override // Binder call
@@ -472,8 +471,6 @@ public class FingerprintService extends BiometricServiceBase<IBiometricsFingerpr
    }

    private final LockoutFrameworkImpl mLockoutTracker;
    private final CopyOnWriteArrayList<IFingerprintClientActiveCallback> mClientActiveCallbacks =
            new CopyOnWriteArrayList<>();
    private IUdfpsOverlayController mUdfpsOverlayController;

    @GuardedBy("this")
@@ -555,6 +552,7 @@ public class FingerprintService extends BiometricServiceBase<IBiometricsFingerpr
    public FingerprintService(Context context) {
        super(context);
        mLazyDaemon = FingerprintService.this::getFingerprintDaemon;
        mGestureAvailabilityTracker = new GestureAvailabilityTracker();
        mLockoutResetTracker = new LockoutResetTracker(context);
        final LockoutFrameworkImpl.LockoutResetCallback lockoutResetCallback = userId -> {
            mLockoutResetTracker.notifyLockoutResetCallbacks();
@@ -691,15 +689,7 @@ public class FingerprintService extends BiometricServiceBase<IBiometricsFingerpr

    @Override
    protected void notifyClientActiveCallbacks(boolean isActive) {
        List<IFingerprintClientActiveCallback> callbacks = mClientActiveCallbacks;
        for (int i = 0; i < callbacks.size(); i++) {
            try {
                callbacks.get(i).onClientActiveChanged(isActive);
            } catch (RemoteException re) {
                // If the remote is dead, stop notifying it
                mClientActiveCallbacks.remove(callbacks.get(i));
            }
        }
        mGestureAvailabilityTracker.notifyClientActiveCallbacks(isActive);
    }

    @Override
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.biometrics.sensors.fingerprint;

import android.hardware.fingerprint.IFingerprintClientActiveCallback;
import android.os.RemoteException;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Keeps track of sensor gesture availability (e.g. swipe), and notifies clients when its
 * availability changes
 */
class GestureAvailabilityTracker {
    private final CopyOnWriteArrayList<IFingerprintClientActiveCallback> mClientActiveCallbacks =
            new CopyOnWriteArrayList<>();

    void registerCallback(IFingerprintClientActiveCallback callback) {
        mClientActiveCallbacks.add(callback);
    }

    void removeCallback(IFingerprintClientActiveCallback callback) {
        mClientActiveCallbacks.remove(callback);
    }

    void notifyClientActiveCallbacks(boolean isActive) {
        for (IFingerprintClientActiveCallback callback : mClientActiveCallbacks) {
            try {
                callback.onClientActiveChanged(isActive);
            } catch (RemoteException re) {
                // If the remote is dead, stop notifying it
                mClientActiveCallbacks.remove(callback);
            }
        }
    }
}