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

Commit 69183e5a authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Check AppOps in BiometricService

Fixes: 116340012

Test: manual
Change-Id: Id8e3ec341c4d20dfd77bdb4c554d0f99cbf84aa5
parent b3c05aaa
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ public class BiometricManager {
    @RequiresPermission(USE_BIOMETRIC)
    public boolean hasEnrolledBiometrics() {
        try {
            return mService.hasEnrolledBiometrics();
            return mService.hasEnrolledBiometrics(mContext.getOpPackageName());
        } catch (RemoteException e) {
            return false;
        }
+1 −1
Original line number Diff line number Diff line
@@ -38,5 +38,5 @@ interface IBiometricService {
    void cancelAuthentication(IBinder token, String opPackageName);

    // Returns true if the user has at least one enrolled biometric.
    boolean hasEnrolledBiometrics();
    boolean hasEnrolledBiometrics(String opPackageName);
}
 No newline at end of file
+13 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.biometrics;
import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_FINGERPRINT;

import android.app.AppOpsManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.biometrics.BiometricAuthenticator;
@@ -80,6 +81,7 @@ public class BiometricService extends SystemService {
            BIOMETRIC_FACE
    };

    private final AppOpsManager mAppOps;
    private final Handler mHandler;
    private final boolean mHasFeatureFingerprint;
    private final boolean mHasFeatureIris;
@@ -200,14 +202,20 @@ public class BiometricService extends SystemService {
        }

        @Override // Binder call
        public boolean hasEnrolledBiometrics() {
        public boolean hasEnrolledBiometrics(String opPackageName) {
            checkPermission();

            boolean hasEnrolled = false;
            if (mAppOps.noteOp(AppOpsManager.OP_USE_BIOMETRIC, Binder.getCallingUid(),
                    opPackageName) != AppOpsManager.MODE_ALLOWED) {
                Slog.w(TAG, "Rejecting " + opPackageName + "; permission denied");
                throw new SecurityException("Permission denied");
            }

            final long ident = Binder.clearCallingIdentity();
            boolean hasEnrolled = false;
            try {
                // Note: On devices with multi-modal authentication, the selection logic will need to
                // be updated.
                // Note: On devices with multi-modal authentication, the selection logic will need
                // to be updated.
                for (int i = 0; i < mAuthenticators.size(); i++) {
                    if (mAuthenticators.get(i).getAuthenticator().hasEnrolledTemplates()) {
                        hasEnrolled = true;
@@ -241,6 +249,7 @@ public class BiometricService extends SystemService {
    public BiometricService(Context context) {
        super(context);

        mAppOps = context.getSystemService(AppOpsManager.class);
        mHandler = new Handler(Looper.getMainLooper());

        final PackageManager pm = context.getPackageManager();