sService是一个static INfcAdapter的对象,INfcAdapter是AIDL定义的接口,用于调用NfcService的方法。可以看出它执行了Service的enable()方法。代码位于Lineageos/packages/apps/Nfc/NfcService.java,相关aidl也定义在这个目录。实现如下:
@Override public boolean enable() throws RemoteException { NfcPermissions.enforceAdminPermissions(mContext); saveNfcOnSetting(true); new EnableDisableTask().execute(TASK_ENABLE); return true; }
NfcService作为系统服务,由NfcNci.apk提供,并在开机时启动由NfcApplication启动。下面我们来看看NfcService在这个异步任务里面又做了些什么。
class EnableDisableTask extends AsyncTask{ @Override protected Void doInBackground(Integer... params) { ...... switch (params[0].intValue()) { case TASK_ENABLE: enableInternal(); break; case TASK_DISABLE: disableInternal(); break; case TASK_BOOT: Log.d(TAG, "checking on firmware download"); if (mPrefs.getBoolean(PREF_NFC_ON, NFC_ON_DEFAULT)) { Log.d(TAG, "NFC is on. Doing normal stuff"); enableInternal(); } else if (!isSecHal()) { Log.d(TAG, "NFC is off. Checking firmware version"); mDeviceHost.checkFirmware(); } ...... } ...... } /