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

Commit 71520ed2 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

23/n: Move LockoutResetCallback tracking to its own class

Decouples shared code in BiometricServiceBase. The code that notifies
clients (keyguard) of lockout reset will eventually also send the
sensorId that lockout was reset for. However, that will depend on
subsequent changes.

Bug: 157790417

Test: adb shell killall -9 com.android.systemui, see callback removed
Test: Lockout fingerprint, wait 30s, keyguard is notified and starts
      authenticating again
Change-Id: I791ce6c146500f81638a56587e4e90d8f1933f5e
parent 021755a1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -610,7 +610,7 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
                                    serverCallback.sendResult(null /* data */);
                                }
                            }
                        });
                        }, mContext.getOpPackageName());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ interface IFaceService {
    void resetLockout(int userId, in byte [] hardwareAuthToken);

    // Add a callback which gets notified when the face lockout period expired.
    void addLockoutResetCallback(IBiometricServiceLockoutResetCallback callback);
    void addLockoutResetCallback(IBiometricServiceLockoutResetCallback callback, String opPackageName);

    void setFeature(IBinder token, int userId, int feature, boolean enabled,
            in byte [] hardwareAuthToken, IFaceServiceReceiver receiver, String opPackageName);
+1 −1
Original line number Diff line number Diff line
@@ -768,7 +768,7 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
                            serverCallback.sendResult(null /* data */);
                        }
                    }
                });
                }, mContext.getOpPackageName());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ interface IFingerprintService {
    void resetLockout(int userId, in byte [] hardwareAuthToken);

    // Add a callback which gets notified when the fingerprint lockout period expired.
    void addLockoutResetCallback(IBiometricServiceLockoutResetCallback callback);
    void addLockoutResetCallback(IBiometricServiceLockoutResetCallback callback, String opPackageName);

    // Check if a client request is currently being handled
    boolean isClientActive();
+0 −90
Original line number Diff line number Diff line
@@ -34,17 +34,12 @@ import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.BiometricManager.Authenticators;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.hardware.biometrics.IBiometricService;
import android.hardware.biometrics.IBiometricServiceLockoutResetCallback;
import android.hardware.fingerprint.Fingerprint;
import android.os.Binder;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.Handler;
import android.os.IBinder;
import android.os.IHwBinder;
import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -82,11 +77,9 @@ public abstract class BiometricServiceBase<T> extends SystemService
    private final Context mContext;
    private final String mKeyguardPackage;
    protected final IActivityTaskManager mActivityTaskManager;
    private final PowerManager mPowerManager;
    protected final BiometricTaskStackListener mTaskStackListener =
            new BiometricTaskStackListener();
    private final ResetClientStateRunnable mResetClientState = new ResetClientStateRunnable();
    private final ArrayList<LockoutResetMonitor> mLockoutMonitors = new ArrayList<>();

    protected final IStatusBarService mStatusBarService;
    protected final Map<Integer, Long> mAuthenticatorIds =
@@ -263,65 +256,6 @@ public abstract class BiometricServiceBase<T> extends SystemService
        }
    }



    private final class LockoutResetMonitor implements IBinder.DeathRecipient {
        private static final long WAKELOCK_TIMEOUT_MS = 2000;
        private final IBiometricServiceLockoutResetCallback mCallback;
        private final PowerManager.WakeLock mWakeLock;

        public LockoutResetMonitor(IBiometricServiceLockoutResetCallback callback) {
            mCallback = callback;
            mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                    "lockout reset callback");
            try {
                mCallback.asBinder().linkToDeath(LockoutResetMonitor.this, 0);
            } catch (RemoteException e) {
                Slog.w(getTag(), "caught remote exception in linkToDeath", e);
            }
        }

        public void sendLockoutReset() {
            if (mCallback != null) {
                try {
                    mWakeLock.acquire(WAKELOCK_TIMEOUT_MS);
                    mCallback.onLockoutReset(new IRemoteCallback.Stub() {
                        @Override
                        public void sendResult(Bundle data) throws RemoteException {
                            releaseWakelock();
                        }
                    });
                } catch (DeadObjectException e) {
                    Slog.w(getTag(), "Death object while invoking onLockoutReset: ", e);
                    mHandler.post(mRemoveCallbackRunnable);
                } catch (RemoteException e) {
                    Slog.w(getTag(), "Failed to invoke onLockoutReset: ", e);
                    releaseWakelock();
                }
            }
        }

        private final Runnable mRemoveCallbackRunnable = new Runnable() {
            @Override
            public void run() {
                releaseWakelock();
                removeLockoutResetCallback(LockoutResetMonitor.this);
            }
        };

        @Override
        public void binderDied() {
            Slog.e(getTag(), "Lockout reset callback binder died");
            mHandler.post(mRemoveCallbackRunnable);
        }

        private void releaseWakelock() {
            if (mWakeLock.isHeld()) {
                mWakeLock.release();
            }
        }
    }

    /**
     * Initializes the system service.
     * <p>
@@ -341,7 +275,6 @@ public abstract class BiometricServiceBase<T> extends SystemService
        mKeyguardPackage = keyguardComponent != null ? keyguardComponent.getPackageName() : null;
        mAppOps = context.getSystemService(AppOpsManager.class);
        mActivityTaskManager = ActivityTaskManager.getService();
        mPowerManager = mContext.getSystemService(PowerManager.class);
        mPerformanceTracker = PerformanceTracker.getInstanceForSensorId(getSensorId());
    }

@@ -647,19 +580,6 @@ public abstract class BiometricServiceBase<T> extends SystemService
        startClient(client, true /* initiatedByClient */);
    }

    protected void addLockoutResetCallback(IBiometricServiceLockoutResetCallback callback) {
        if (callback == null) {
            Slog.w(getTag(), "Null LockoutResetCallback");
            return;
        }
        mHandler.post(() -> {
           final LockoutResetMonitor monitor = new LockoutResetMonitor(callback);
           if (!mLockoutMonitors.contains(monitor)) {
               mLockoutMonitors.add(monitor);
           }
        });
    }

    /**
     * Helper methods.
     */
@@ -931,12 +851,6 @@ public abstract class BiometricServiceBase<T> extends SystemService
        doTemplateCleanupForUser(userId);
    }

    protected void notifyLockoutResetMonitors() {
        for (int i = 0; i < mLockoutMonitors.size(); i++) {
            mLockoutMonitors.get(i).sendLockoutReset();
        }
    }

    private void listenForUserSwitches() {
        try {
            ActivityManager.getService().registerUserSwitchObserver(
@@ -951,8 +865,4 @@ public abstract class BiometricServiceBase<T> extends SystemService
            Slog.w(getTag(), "Failed to listen for user switching event" ,e);
        }
    }

    private void removeLockoutResetCallback(LockoutResetMonitor monitor) {
        mLockoutMonitors.remove(monitor);
    }
}
Loading