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

Commit c57b6622 authored by Andy Mast's avatar Andy Mast
Browse files

Fingerprint: Add getNumEnrollmentSteps [1/2]

Add ability to query hal for num enrollment steps

Projects:
  frameworks/base
  libhardware
  vendor specific implementation

Change-Id: Id65ec257583f7fdcc18ee2bee25c7db76e982ffd
parent 27d76501
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -294,6 +294,19 @@ public class FingerprintManager {
        return Collections.emptyList();
    }

    public int getNumEnrollmentSteps() {
        if (mService != null) {
            try {
                return mService.getNumEnrollmentSteps(mToken);
            } catch (RemoteException e) {
                Log.v(TAG, "Remote exception in getNumEnrollmentSteps(): ", e);
            }
        } else {
            Log.w(TAG, "getNumEnrollmentSteps(): Service not connected!");
        }
        return -1;
    }

    private void sendError(int msg, int arg1, int arg2) {
        mHandler.obtainMessage(msg, arg1, arg2);
    }
+3 −0
Original line number Diff line number Diff line
@@ -47,4 +47,7 @@ interface IFingerprintService {

    // Rename fingerprint
    boolean setFingerprintName(IBinder token, int fingerprintId, String name, int userId);

    // Get num of fingerprints samples required to enroll
    int getNumEnrollmentSteps(IBinder token);
}
+7 −1
Original line number Diff line number Diff line
@@ -176,6 +176,11 @@ static jobject nativeGetEnrollments(JNIEnv* env) {
    return jFingerprintObjArray;
}

static jint nativeGetNumEnrollmentSteps(JNIEnv* env) {
    ALOG(LOG_VERBOSE, LOG_TAG, "nativeGetNumEnrollMents()\n");
    return reinterpret_cast<jint>(gContext.device->get_num_enrollment_steps(gContext.device));
}

static jint nativeOpenHal(JNIEnv* env, jobject clazz) {
    ALOG(LOG_VERBOSE, LOG_TAG, "nativeOpenHal()\n");
    int err;
@@ -239,7 +244,8 @@ static const JNINativeMethod g_methods[] = {
    { "nativeOpenHal", "()I", (void*)nativeOpenHal },
    { "nativeCloseHal", "()I", (void*)nativeCloseHal },
    { "nativeInit", "(Lcom/android/server/fingerprint/FingerprintService;)V", (void*)nativeInit },
    { "nativeGetEnrollments", "()[Landroid/hardware/fingerprint/Fingerprint;", (void*)nativeGetEnrollments }
    { "nativeGetEnrollments", "()[Landroid/hardware/fingerprint/Fingerprint;", (void*)nativeGetEnrollments },
    { "nativeGetNumEnrollmentSteps", "()I", (void*)nativeGetNumEnrollmentSteps }
};

int register_android_server_fingerprint_FingerprintService(JNIEnv* env) {
+27 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ public class FingerprintService extends SystemService {
    native int nativeCloseHal();
    native void nativeInit(FingerprintService service);
    native Fingerprint[] nativeGetEnrollments();
    native int nativeGetNumEnrollmentSteps();

    // JNI methods for communicating from HAL to clients
    void notify(int msg, int arg1, int arg2) {
@@ -439,6 +440,10 @@ public class FingerprintService extends SystemService {
        return true;
    }

    public int getNumEnrollmentSteps() {
        return nativeGetNumEnrollmentSteps();
    }

    private void enforceCrossUserPermission(int userId, String errorMessage) {
        if (userId != UserHandle.getCallingUserId()
                && Binder.getCallingUid() != Process.myUid()
@@ -462,6 +467,7 @@ public class FingerprintService extends SystemService {
        private final static String DUMP_CMD_REMOVE_FINGER = "removeFinger";
        private final static String DUMP_CMD_PRINT_ENROLLMENTS = "printEnrollments";
        private final static String DUMP_CMD_SET_FINGER_NAME = "setFingerName";
        private final static String DUMP_CMD_GET_NUM_ENROLLMENT_STEPS = "getNumEnrollmentSteps";

        @Override // Binder call
        public void authenticate(IBinder token, int userId) {
@@ -514,6 +520,14 @@ public class FingerprintService extends SystemService {
            return FingerprintService.this.setFingerprintName(token, fingerprintId, name, userId);
        }

        @Override
        public int getNumEnrollmentSteps(IBinder token)
                throws RemoteException {
            checkPermission();
            throwIfNoFingerprint();
            return FingerprintService.this.getNumEnrollmentSteps();
        }

        /**
         * "adb shell dumpsys fingerprint [cmd]
         */
@@ -533,6 +547,8 @@ public class FingerprintService extends SystemService {
                dumpSetFingerprintName(pw, args);
            } else if (args.length > 1 && DUMP_CMD_REMOVE_FINGER.equals(args[0])) {
                dumpRemoveFinger(pw, args);
            } else if (args.length >= 1 && DUMP_CMD_GET_NUM_ENROLLMENT_STEPS.equals(args[0])) {
                dumpGetNumEnrollmentSteps(pw, args);
            } else {
                dumpCommandList(pw);
            }
@@ -582,11 +598,22 @@ public class FingerprintService extends SystemService {
            }
        }

        private void dumpGetNumEnrollmentSteps(PrintWriter pw, String[] args) {
            try {
                int steps = FingerprintService.this.getNumEnrollmentSteps();
                pw.println("Number of enrollment steps: " + steps);
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

        private void dumpCommandList(PrintWriter pw) {
            pw.println("Valid Fingerprint Commands:");
            pw.println(DUMP_CMD_PRINT_ENROLLMENTS + " - Print Fingerprint Enrollments");
            pw.println(DUMP_CMD_REMOVE_FINGER + " <id> - Remove fingerprint");
            pw.println(DUMP_CMD_SET_FINGER_NAME + " <id> <name> - Rename a finger");
            pw.println(DUMP_CMD_GET_NUM_ENROLLMENT_STEPS + " - Returns num of steps the vendor" +
                    " requires to enroll a finger.");
        }
    }