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

Commit a539a7f3 authored by Diya Bera's avatar Diya Bera Committed by Android (Google) Code Review
Browse files

Merge "Start fingerprint user client on reboot" into udc-dev

parents 2308d69a 729dea0f
Loading
Loading
Loading
Loading
+97 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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;

import android.app.IActivityManager;
import android.app.SynchronousUserSwitchObserver;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Slog;
import android.util.SparseArray;

/**
 * Keep track of the sensors that is supported by the HAL.
 * @param <T> T is either face sensor or fingerprint sensor.
 */
public class SensorList<T> {
    private static final String TAG = "SensorList";
    private final SparseArray<T> mSensors;
    private final IActivityManager mActivityManager;

    public SensorList(IActivityManager activityManager) {
        mSensors = new SparseArray<T>();
        mActivityManager = activityManager;
    }

    /**
     * Adding sensor to the map with the sensor id as key. Also, starts a session if the user Id is
     * NULL.
     */
    public void addSensor(int sensorId, T sensor, int sessionUserId,
            SynchronousUserSwitchObserver userSwitchObserver) {
        mSensors.put(sensorId, sensor);
        registerUserSwitchObserver(sessionUserId, userSwitchObserver);
    }

    private void registerUserSwitchObserver(int sessionUserId,
            SynchronousUserSwitchObserver userSwitchObserver) {
        try {
            mActivityManager.registerUserSwitchObserver(userSwitchObserver,
                    TAG);
            if (sessionUserId == UserHandle.USER_NULL) {
                userSwitchObserver.onUserSwitching(UserHandle.USER_SYSTEM);
            }
        } catch (RemoteException e) {
            Slog.e(TAG, "Unable to register user switch observer");
        }
    }

    /**
     * Returns the sensor corresponding to the key at a specific position.
     */
    public T valueAt(int position) {
        return mSensors.valueAt(position);
    }

    /**
     * Returns the sensor associated with sensorId as key.
     */
    public T get(int sensorId) {
        return mSensors.get(sensorId);
    }

    /**
     * Returns the sensorId at the specified position.
     */
    public int keyAt(int position) {
        return mSensors.keyAt(position);
    }

    /**
     * Returns the number of sensors added.
     */
    public int size() {
        return mSensors.size();
    }

    /**
     * Returns true if a sensor exists for the specified sensorId.
     */
    public boolean contains(int sensorId) {
        return mSensors.contains(sensorId);
    }
}
+61 −51

File changed.

Preview size limit exceeded, changes collapsed.

+0 −17
Original line number Diff line number Diff line
@@ -18,9 +18,6 @@ package com.android.server.biometrics.sensors.face.aidl;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.SynchronousUserSwitchObserver;
import android.app.UserSwitchObserver;
import android.content.Context;
import android.content.pm.UserInfo;
import android.hardware.biometrics.BiometricsProtoEnums;
@@ -94,14 +91,6 @@ public class Sensor {
    @NonNull private final Supplier<AidlSession> mLazySession;
    @Nullable private AidlSession mCurrentSession;

    private final UserSwitchObserver mUserSwitchObserver = new SynchronousUserSwitchObserver() {
        @Override
        public void onUserSwitching(int newUserId) {
            mProvider.scheduleInternalCleanup(
                    mSensorProperties.sensorId, newUserId, null /* callback */);
        }
    };

    @VisibleForTesting
    public static class HalSessionCallback extends ISessionCallback.Stub {
        /**
@@ -558,12 +547,6 @@ public class Sensor {
        mLockoutCache = new LockoutCache();
        mAuthenticatorIds = new HashMap<>();
        mLazySession = () -> mCurrentSession != null ? mCurrentSession : null;

        try {
            ActivityManager.getService().registerUserSwitchObserver(mUserSwitchObserver, mTag);
        } catch (RemoteException e) {
            Slog.e(mTag, "Unable to register user switch observer");
        }
    }

    @NonNull Supplier<AidlSession> getLazySession() {
+93 −76

File changed.

Preview size limit exceeded, changes collapsed.

+0 −17
Original line number Diff line number Diff line
@@ -18,9 +18,6 @@ package com.android.server.biometrics.sensors.fingerprint.aidl;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.SynchronousUserSwitchObserver;
import android.app.UserSwitchObserver;
import android.content.Context;
import android.content.pm.UserInfo;
import android.hardware.biometrics.BiometricsProtoEnums;
@@ -96,14 +93,6 @@ public class Sensor {
    @Nullable private AidlSession mCurrentSession;
    @NonNull private final Supplier<AidlSession> mLazySession;

    private final UserSwitchObserver mUserSwitchObserver = new SynchronousUserSwitchObserver() {
        @Override
        public void onUserSwitching(int newUserId) {
            mProvider.scheduleInternalCleanup(
                    mSensorProperties.sensorId, newUserId, null /* callback */);
        }
    };

    @VisibleForTesting
    public static class HalSessionCallback extends ISessionCallback.Stub {

@@ -512,12 +501,6 @@ public class Sensor {
                });
        mAuthenticatorIds = new HashMap<>();
        mLazySession = () -> mCurrentSession != null ? mCurrentSession : null;

        try {
            ActivityManager.getService().registerUserSwitchObserver(mUserSwitchObserver, mTag);
        } catch (RemoteException e) {
            Slog.e(mTag, "Unable to register user switch observer");
        }
    }

    @NonNull Supplier<AidlSession> getLazySession() {
Loading