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

Commit 11e1f825 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

19/n: Remove dead code

I don't think getUserOrWorkProfileId, getEffectiveUserId are
necessary/used anymore.

UserIds are distinct for owners, managed profiles, and multi-user
AFAIK. This code might have been for before some methods in
Fingerprint/FaceService had userId as a parameter from the caller.
In addition one lock does not apply to biometrics.

Bug: 157790417

Test: Able to authenticate for owner, work profile, and secondary user

Change-Id: I342a162015b9a90f802affc839f16e73f0e6130a
parent da27daf8
Loading
Loading
Loading
Loading
+9 −37
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public abstract class BiometricServiceBase extends SystemService
            if (!hasEnrolledBiometrics(userId)) {
                Slog.d(getTag(), "Last biometric removed for user: " + userId
                        + ", updating active group");
                updateActiveGroup(userId, null);
                updateActiveGroup(userId);
            }
        }

@@ -153,9 +153,8 @@ public abstract class BiometricServiceBase extends SystemService
    /**
     * Notifies the HAL that the user has changed.
     * @param userId
     * @param clientPackage
     */
    protected abstract void updateActiveGroup(int userId, String clientPackage);
    protected abstract void updateActiveGroup(int userId);

    /**
     * @param userId
@@ -456,7 +455,7 @@ public abstract class BiometricServiceBase extends SystemService
            // When enrollment finishes, update this group's authenticator id, as the HAL has
            // already generated a new authenticator id when the new biometric is enrolled.
            if (identifier instanceof Fingerprint) {
                updateActiveGroup(((Fingerprint)identifier).getGroupId(), null);
                updateActiveGroup(((Fingerprint)identifier).getGroupId());
            }
        }
    }
@@ -855,9 +854,9 @@ public abstract class BiometricServiceBase extends SystemService
        long t = System.currentTimeMillis();
        mAuthenticatorIds.clear();
        for (UserInfo user : UserManager.get(getContext()).getUsers(true /* excludeDying */)) {
            int userId = getUserOrWorkProfileId(null, user.id);
            int userId = user.id;
            if (!mAuthenticatorIds.containsKey(userId)) {
                updateActiveGroup(userId, null);
                updateActiveGroup(userId);
            }
        }

@@ -867,17 +866,6 @@ public abstract class BiometricServiceBase extends SystemService
        }
    }

    /**
     * @param clientPackage the package of the caller
     * @return the profile id
     */
    protected int getUserOrWorkProfileId(String clientPackage, int userId) {
        if (!isKeyguard(clientPackage) && isWorkProfile(userId)) {
            return userId;
        }
        return getEffectiveUserId(userId);
    }

    protected boolean isRestricted() {
        // Only give privileged apps (like Settings) access to biometric info
        final boolean restricted = !hasPermission(getManageBiometricPermission());
@@ -920,8 +908,7 @@ public abstract class BiometricServiceBase extends SystemService
     * @return authenticator id for the calling user
     */
    protected long getAuthenticatorId(int callingUserId) {
        final int userId = getUserOrWorkProfileId(null /* clientPackage */, callingUserId);
        return mAuthenticatorIds.getOrDefault(userId, 0L);
        return mAuthenticatorIds.getOrDefault(callingUserId, 0L);
    }

    /**
@@ -937,7 +924,7 @@ public abstract class BiometricServiceBase extends SystemService
        if (getCurrentClient() instanceof InternalCleanupClient) {
            Slog.w(getTag(), "User switched while performing cleanup");
        }
        updateActiveGroup(userId, null);
        updateActiveGroup(userId);
        doTemplateCleanupForUser(userId);
    }

@@ -962,26 +949,12 @@ public abstract class BiometricServiceBase extends SystemService
        return userInfo != null && userInfo.isManagedProfile();
    }


    private int getEffectiveUserId(int userId) {
        UserManager um = UserManager.get(mContext);
        if (um != null) {
            final long callingIdentity = Binder.clearCallingIdentity();
            userId = um.getCredentialOwnerProfile(userId);
            Binder.restoreCallingIdentity(callingIdentity);
        } else {
            Slog.e(getTag(), "Unable to acquire UserManager");
        }
        return userId;
    }


    private void listenForUserSwitches() {
        try {
            ActivityManager.getService().registerUserSwitchObserver(
                    new SynchronousUserSwitchObserver() {
                        @Override
                        public void onUserSwitching(int newUserId) throws RemoteException {
                        public void onUserSwitching(int newUserId) {
                            mHandler.obtainMessage(MSG_USER_SWITCHING, newUserId, 0 /* unused */)
                                    .sendToTarget();
                        }
@@ -991,8 +964,7 @@ public abstract class BiometricServiceBase extends SystemService
        }
    }

    private void removeLockoutResetCallback(
            LockoutResetMonitor monitor) {
    private void removeLockoutResetCallback(LockoutResetMonitor monitor) {
        mLockoutMonitors.remove(monitor);
    }
}
+9 −12
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@ import android.hardware.biometrics.IBiometricSensorReceiver;
import android.hardware.biometrics.IBiometricServiceLockoutResetCallback;
import android.hardware.biometrics.face.V1_0.IBiometricsFace;
import android.hardware.biometrics.face.V1_0.IBiometricsFaceClientCallback;
import android.hardware.biometrics.face.V1_0.OptionalBool;
import android.hardware.biometrics.face.V1_0.Status;
import android.hardware.face.Face;
import android.hardware.face.IFaceService;
import android.hardware.face.IFaceServiceReceiver;
@@ -157,7 +155,7 @@ public class FaceService extends BiometricServiceBase {
                final IFaceServiceReceiver receiver, final String opPackageName,
                final int[] disabledFeatures, Surface surface) throws RemoteException {
            checkPermission(MANAGE_BIOMETRIC);
            updateActiveGroup(userId, opPackageName);
            updateActiveGroup(userId);

            mHandler.post(() -> {
                mNotificationManager.cancelAsUser(NOTIFICATION_TAG, NOTIFICATION_ID,
@@ -201,7 +199,7 @@ public class FaceService extends BiometricServiceBase {
                final IFaceServiceReceiver receiver, final int flags,
                final String opPackageName) throws RemoteException {
            checkPermission(USE_BIOMETRIC_INTERNAL);
            updateActiveGroup(userId, opPackageName);
            updateActiveGroup(userId);

            final IBiometricsFace daemon = getFaceDaemon();
            if (daemon == null) {
@@ -228,7 +226,7 @@ public class FaceService extends BiometricServiceBase {
                String opPackageName, int cookie, int callingUid, int callingPid,
                int callingUserId) throws RemoteException {
            checkPermission(USE_BIOMETRIC_INTERNAL);
            updateActiveGroup(userId, opPackageName);
            updateActiveGroup(userId);

            final IBiometricsFace daemon = getFaceDaemon();
            if (daemon == null) {
@@ -275,7 +273,7 @@ public class FaceService extends BiometricServiceBase {
                final IFaceServiceReceiver receiver, final String opPackageName)
                throws RemoteException {
            checkPermission(MANAGE_BIOMETRIC);
            updateActiveGroup(userId, opPackageName);
            updateActiveGroup(userId);

            if (token == null) {
                Slog.w(TAG, "remove(): token is null");
@@ -392,7 +390,7 @@ public class FaceService extends BiometricServiceBase {
                    return;
                }

                updateActiveGroup(userId, null /* opPackageName */);
                updateActiveGroup(userId);
                final FaceResetLockoutClient client = new FaceResetLockoutClient(
                        mClientFinishCallback, getContext(), daemon, userId,
                        getContext().getOpPackageName(), getSensorId(), hardwareAuthToken);
@@ -410,7 +408,7 @@ public class FaceService extends BiometricServiceBase {
                if (DEBUG) {
                    Slog.d(TAG, "setFeature for user(" + userId + ")");
                }
                updateActiveGroup(userId, opPackageName);
                updateActiveGroup(userId);
                if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) {
                    Slog.e(TAG, "No enrolled biometrics while setting feature: " + feature);
                    return;
@@ -442,7 +440,7 @@ public class FaceService extends BiometricServiceBase {
                if (DEBUG) {
                    Slog.d(TAG, "getFeature for user(" + userId + ")");
                }
                updateActiveGroup(userId, opPackageName);
                updateActiveGroup(userId);
                // This should ideally return tri-state, but the user isn't shown settings unless
                // they are enrolled so it's fine for now.
                if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) {
@@ -670,12 +668,11 @@ public class FaceService extends BiometricServiceBase {
    }

    @Override
    protected void updateActiveGroup(int userId, String clientPackage) {
    protected void updateActiveGroup(int userId) {
        IBiometricsFace daemon = getFaceDaemon();

        if (daemon != null) {
            try {
                userId = getUserOrWorkProfileId(clientPackage, userId);
                if (userId != mCurrentUserId) {
                    final File baseDir = Environment.getDataVendorDeDirectory(userId);
                    final File faceDir = new File(baseDir, FACE_DATA_DIR);
@@ -803,7 +800,7 @@ public class FaceService extends BiometricServiceBase {
            if (DEBUG) Slog.v(TAG, "Face HAL id: " + halId);
            if (halId != 0) {
                loadAuthenticatorIds();
                updateActiveGroup(ActivityManager.getCurrentUser(), null);
                updateActiveGroup(ActivityManager.getCurrentUser());
                doTemplateCleanupForUser(ActivityManager.getCurrentUser());
            } else {
                Slog.w(TAG, "Failed to open Face HAL!");
+6 −7
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ public class FingerprintService extends BiometricServiceBase {
                final IFingerprintServiceReceiver receiver, final int flags,
                final String opPackageName, Surface surface) throws RemoteException {
            checkPermission(MANAGE_FINGERPRINT);
            updateActiveGroup(userId, opPackageName);
            updateActiveGroup(userId);

            final IBiometricsFingerprint daemon = getFingerprintDaemon();
            if (daemon == null) {
@@ -173,7 +173,7 @@ public class FingerprintService extends BiometricServiceBase {
        public void authenticate(final IBinder token, final long opId, final int userId,
                final IFingerprintServiceReceiver receiver, final int flags,
                final String opPackageName, Surface surface) throws RemoteException {
            updateActiveGroup(userId, opPackageName);
            updateActiveGroup(userId);

            final IBiometricsFingerprint daemon = getFingerprintDaemon();
            if (daemon == null) {
@@ -208,7 +208,7 @@ public class FingerprintService extends BiometricServiceBase {
                int cookie, int callingUid, int callingPid, int callingUserId,
                Surface surface) throws RemoteException {
            checkPermission(MANAGE_BIOMETRIC);
            updateActiveGroup(userId, opPackageName);
            updateActiveGroup(userId);

            final IBiometricsFingerprint daemon = getFingerprintDaemon();
            if (daemon == null) {
@@ -257,7 +257,7 @@ public class FingerprintService extends BiometricServiceBase {
                final IFingerprintServiceReceiver receiver, final String opPackageName)
                throws RemoteException {
            checkPermission(MANAGE_FINGERPRINT);
            updateActiveGroup(userId, opPackageName);
            updateActiveGroup(userId);

            if (token == null) {
                Slog.w(TAG, "remove(): token is null");
@@ -536,12 +536,11 @@ public class FingerprintService extends BiometricServiceBase {
    }

    @Override
    protected void updateActiveGroup(int userId, String clientPackage) {
    protected void updateActiveGroup(int userId) {
        IBiometricsFingerprint daemon = getFingerprintDaemon();

        if (daemon != null) {
            try {
                userId = getUserOrWorkProfileId(clientPackage, userId);
                if (userId != mCurrentUserId) {
                    int firstSdkInt = Build.VERSION.FIRST_SDK_INT;
                    if (firstSdkInt < Build.VERSION_CODES.BASE) {
@@ -694,7 +693,7 @@ public class FingerprintService extends BiometricServiceBase {
            if (halId != 0) {
                loadAuthenticatorIds();
                final int userId = ActivityManager.getCurrentUser();
                updateActiveGroup(userId, null);
                updateActiveGroup(userId);
                doTemplateCleanupForUser(userId);
            } else {
                Slog.w(TAG, "Failed to open Fingerprint HAL!");
+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public class IrisService extends BiometricServiceBase {
    }

    @Override
    protected void updateActiveGroup(int userId, String clientPackage) {
    protected void updateActiveGroup(int userId) {

    }

+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ public class BiometricServiceBaseTest {
        }

        @Override
        protected void updateActiveGroup(int userId, String clientPackage) {
        protected void updateActiveGroup(int userId) {
        }

        @Override