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

Commit cd5bf1da authored by Joseph Vincent's avatar Joseph Vincent Committed by Android (Google) Code Review
Browse files

Merge "Remove private space biometrics on switching to device lock" into main

parents 2fcd4b48 ec273aca
Loading
Loading
Loading
Loading
+62 −0
Original line number Diff line number Diff line
@@ -54,7 +54,9 @@ import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.hardware.face.Face;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
@@ -1333,4 +1335,64 @@ public final class Utils extends com.android.settingslib.Utils {
        return dreamsSupported && (!dreamsOnlyEnabledForDockUser || canCurrentUserDream(context));
    }


    /**
     * Removes fingerprint templates enrolled for a given user.
     *
     * @param context application context.
     * @param userId the id of the relevant user
     */
    public static void removeEnrolledFingerprintForUser(Context context, int userId) {
        FingerprintManager fingerprintManager = getFingerprintManagerOrNull(context);
        if (fingerprintManager != null && fingerprintManager.hasEnrolledTemplates(userId)) {
            fingerprintManager.removeAll(userId,
                    fingerprintManagerRemovalCallback(userId));
        }
    }

    /**
     * Removes face templates enrolled for a given user.
     *
     * @param context application context.
     * @param userId the id of the relevant user
     */
    public static void removeEnrolledFaceForUser(Context context, int userId) {
        FaceManager faceManager  = getFaceManagerOrNull(context);
        if (faceManager != null && faceManager.hasEnrolledTemplates(userId)) {
            faceManager.removeAll(userId, faceManagerRemovalCallback(userId));
        }
    }

    private static FaceManager.RemovalCallback faceManagerRemovalCallback(int userId) {
        return new FaceManager.RemovalCallback() {
            @Override
            public void onRemovalError(@Nullable Face face, int errMsgId, CharSequence err) {
                Log.e(TAG, "Unable to remove face template for user " + userId + ", error: " + err);
            }

            @Override
            public void onRemovalSucceeded(Face face, int remaining) {
                if (remaining == 0) {
                    Log.d(TAG, "Enrolled face templates removed for user " + userId);
                }
            }
        };
    }

    private static FingerprintManager.RemovalCallback fingerprintManagerRemovalCallback(
            int userId) {
        return new FingerprintManager.RemovalCallback() {
            @Override
            public void onRemovalError(@Nullable Fingerprint fp, int errMsgId, CharSequence err) {
                Log.e(TAG, "Unable to remove fingerprint for user " + userId + " , error: " + err);
            }

            @Override
            public void onRemovalSucceeded(Fingerprint fp, int remaining) {
                if (remaining == 0) {
                    Log.d(TAG, "Enrolled fingerprints removed for user " + userId);
                }
            }
        };
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.util.Log;
import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.biometrics.combination.CombinedBiometricStatusPreferenceController;
import com.android.settings.privatespace.PrivateSpaceMaintainer;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -72,6 +73,8 @@ public class FaceFingerprintUnlockController extends CombinedBiometricStatusPref
            super.updateState(preference);
            preference.setEnabled(true);
        } else {
            Utils.removeEnrolledFaceForUser(mContext, getUserId());
            Utils.removeEnrolledFingerprintForUser(mContext, getUserId());
            preference.setSummary(
                    mContext.getString(R.string.lock_settings_profile_unified_summary));
            preference.setEnabled(false);
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public class PrivateSpaceFacePreferenceController extends BiometricFaceStatusPre
            super.updateState(preference);
            preference.setEnabled(true);
        } else {
            Utils.removeEnrolledFaceForUser(mContext, getUserId());
            preference.setSummary(
                    mContext.getString(R.string.lock_settings_profile_unified_summary));
            preference.setEnabled(false);
+1 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ public class PrivateSpaceFingerprintPreferenceController
            super.updateState(preference);
            preference.setEnabled(true);
        } else {
            Utils.removeEnrolledFingerprintForUser(mContext, getUserId());
            preference.setSummary(
                    mContext.getString(R.string.lock_settings_profile_unified_summary));
            preference.setEnabled(false);