指纹识别分析之enroll流程

1、调用时序图

指纹识别分析之enroll流程_第1张图片

2、app层

2.1 FingerprintEnrollEnrolling.java

文件路径:
/packages/apps/Settings/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java

    protected void onStart() {
        super.onStart();
        mSidecar = (FingerprintEnrollSidecar) getFragmentManager().findFragmentByTag(TAG_SIDECAR);
        if (mSidecar == null) {
            mSidecar = new FingerprintEnrollSidecar();
            getFragmentManager().beginTransaction().add(mSidecar, TAG_SIDECAR).commit();
        }
        mSidecar.setListener(this);//设置监听
        updateProgress(false /* animate */);
        updateDescription();
        if (mRestoring) {
            startIconAnimation();
        }
    }

此处会创建FingerprintEnrollSidecar类。

2.2 FingerprintEnrollSidecar.java

    public void onStart() {
        super.onStart();
        if (!mEnrolling) {
            startEnrollment();//启动录入
        }
    }

    private void startEnrollment() {
        mHandler.removeCallbacks(mTimeoutRunnable);
        mEnrollmentSteps = -1;
        mEnrollmentCancel = new CancellationSignal();
        getActivity().getSystemService(FingerprintManager.class).enroll(mToken, mEnrollmentCancel,0 /* flags */, mEnrollmentCallback);//调用FingerprintManager类中方法enroll
        mEnrolling = true;
    }

3、framwork层

3.1 FingerprintManager.java

    public void enroll(byte [] token, CancellationSignal cancel, int flags,
            EnrollmentCallback callback) {
        if (mService != null) try {
            mEnrollmentCallback = callback;
            mService.enroll(mToken, token, getCurrentUserId(), mServiceReceiver, flags);//通过aidl远程调用服务
        } catch (RemoteException e) {
            Log.w(TAG, "Remote exception in enroll: ", e);
        }
    }

3.2 FingerprintService.java

文件路径:
/frameworks/base/services/core/java/com/android/server/fingerprint/FingerprintService.java

    private final class FingerprintServiceWrapper extends IFingerprintService.Stub {
        // Binder call
        public void enroll(final IBinder token, final byte[] cryptoToken, final int groupId, final IFingerprintServiceReceiver receiver, final int flags) {
             ......
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    startEnrollment(token, cryptoClone, effectiveGroupId, receiver, flags, restricted);//启动注册
                }
            });
        }
   }

    private void startEnrollment(IBinder token, byte [] cryptoToken, int userId,IFingerprintServiceReceiver receiver, int flags, boolean restricted,
            String opPackageName) {
        updateActiveGroup(userId, opPackageName);

        final int groupId = userId; // default group for fingerprint enrollment
        //新建注册客户端类
       EnrollClient client = new EnrollClient(getContext(), mHalDeviceId, token, receiver, userId, groupId, cryptoToken, restricted, opPackageName) {

            @Override
           public IFingerprintDaemon getFingerprintDaemon() {
               return FingerprintService.this.getFingerprintDaemon();
            }

            @Override
           public void notifyUserActivity() {
                FingerprintService.this.userActivity();
           }
        };
       startClient(client, true /* initiatedByClient */);//启动客户端
   }

    private void startClient(ClientMonitor newClient, boolean initiatedByClient) {
              。。。。。。
              newClient.start();//启动客户端
    }

3.3 EnrollClient.java

    public int start() {
        IFingerprintDaemon daemon = getFingerprintDaemon();//获取fingerprintd服务
        final int result = daemon.enroll(mCryptoToken, getGroupId(), timeout);//通过binder调用fingerprintd
    }

4、hardware层

4.1 fingerprintd四个部分:

  1. fingerprintd.cpp “负责将fingerprintd加入到ServiceManager中,以便FingerprintService能够获取”
  2. IFingerprintDaemon.h/IFingerprintDaemon.cpp “负责java层到fingerprintd的Binder通信(我们指纹录入和识别都会调用里面的方法)”
  3. FingerprintDaemonProxy.h/FingerprintDaemonProxy.cpp “负责fingerprintd和Fignerprint hal层的通信”
  4. IFingerprintDaemonCallback.h/IFingerprintDaemonCallback.cpp “负责将指纹的回调结果传给java层”

4.2 IFingerprintDaemon.cpp

   status_t BnFingerprintDaemon::onTransact(uint32_t code, const Parcel& data, Parcel* reply,uint32_t flags) {
          。。。。。。
        case ENROLL: {
            CHECK_INTERFACE(IFingerprintDaemon, data, reply);
            if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) {
                return PERMISSION_DENIED;
            }
            const ssize_t tokenSize = data.readInt32();
            const uint8_t* token = static_cast(data.readInplace(tokenSize));
            const int32_t groupId = data.readInt32();
            const int32_t timeout = data.readInt32();
            const int32_t ret = enroll(token, tokenSize, groupId, timeout);
            reply->writeNoException();
            reply->writeInt32(ret);
            return NO_ERROR;
        }

4.2 FingerprintDaemonProxy.cpp

int32_t FingerprintDaemonProxy::enroll(const uint8_t* token, ssize_t tokenSize, int32_t groupId,
        int32_t timeout) {
    ALOG(LOG_VERBOSE, LOG_TAG, "enroll(gid=%d, timeout=%d)\n", groupId, timeout);
    if (tokenSize != sizeof(hw_auth_token_t) ) {
        ALOG(LOG_VERBOSE, LOG_TAG, "enroll() : invalid token size %zu\n", tokenSize);
        return -1;
    }
    const hw_auth_token_t* authToken = reinterpret_cast<const hw_auth_token_t*>(token);
    return mDevice->enroll(mDevice, authToken, groupId, timeout);//HAL层由指纹厂家实现
}

5、总结

  到此Android指纹框架之enroll流程分析完了,不足之处,欢迎交流;接下来将分析指纹之比对流程,未完待续。。。。。。

你可能感兴趣的:(Android,java)