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

Commit 0624b7b1 authored by Fyodor Kupolov's avatar Fyodor Kupolov Committed by Android (Google) Code Review
Browse files

Merge "Initialize daemon on a separate thread"

parents 1a9acd63 449e708a
Loading
Loading
Loading
Loading
+30 −22
Original line number Diff line number Diff line
@@ -46,7 +46,9 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.util.Slog;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.logging.MetricsLogger;
import com.android.server.FgThread;
import com.android.server.SystemService;

import org.json.JSONArray;
@@ -111,6 +113,7 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
    private Context mContext;
    private long mHalDeviceId;
    private int mFailedAttempts;
    @GuardedBy("this")
    private IFingerprintDaemon mDaemon;
    private final PowerManager mPowerManager;
    private final AlarmManager mAlarmManager;
@@ -195,19 +198,24 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
    public void binderDied() {
        Slog.v(TAG, "fingerprintd died");
        MetricsLogger.count(mContext, "fingerprintd_died", 1);
        synchronized (this) {
            mDaemon = null;
        }
        mCurrentUserId = UserHandle.USER_CURRENT;
        handleError(mHalDeviceId, FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE);
    }

    public IFingerprintDaemon getFingerprintDaemon() {
        synchronized (this) {
            if (mDaemon == null) {
            mDaemon = IFingerprintDaemon.Stub.asInterface(ServiceManager.getService(FINGERPRINTD));
                mDaemon = IFingerprintDaemon.Stub
                        .asInterface(ServiceManager.getService(FINGERPRINTD));
                if (mDaemon != null) {
                    try {
                        mDaemon.asBinder().linkToDeath(this, 0);
                        mDaemon.init(mDaemonCallback);
                        mHalDeviceId = mDaemon.openHal();
                        if (DEBUG) Slog.v(TAG, "Fingerprint HAL id: " + mHalDeviceId);
                        if (mHalDeviceId != 0) {
                            updateActiveGroup(ActivityManager.getCurrentUser(), null);
                        } else {
@@ -225,6 +233,7 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
            }
            return mDaemon;
        }
    }

    protected void handleEnumerate(long deviceId, int[] fingerIds, int[] groupIds) {
        if (fingerIds.length != groupIds.length) {
@@ -1005,8 +1014,7 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
    @Override
    public void onStart() {
        publishBinderService(Context.FINGERPRINT_SERVICE, new FingerprintServiceWrapper());
        IFingerprintDaemon daemon = getFingerprintDaemon();
        if (DEBUG) Slog.v(TAG, "Fingerprint HAL id: " + mHalDeviceId);
        FgThread.getHandler().post(() -> getFingerprintDaemon());
        listenForUserSwitches();
    }