Android NFC架構(gòu)分析
Android中對NFC的實現(xiàn)代碼分布在如下幾個地方:
本文引用地址:http://m.butianyuan.cn/article/155091.htm./frameworks/base/core/java/android/nfc/
./frameworks/base/core/java/android/nfc/tech
./frameworks/base/core/java/com/android/internal/nfc/
./external/libnfc-nxp
./packages/apps/nfc
其中
./external/libnfc-nxp是用C語言編寫的函數(shù)庫,編譯生成libnfc和libnfc_ndef兩個函數(shù)庫。libnfc是一個主要的庫,實現(xiàn)了NFC Stack的大部分功能,主要供NFC的服務(wù)進程調(diào)用。
libnfc_ndef是一個很小的函數(shù)庫,主要是實現(xiàn)NDEF消息的解析,供Framework調(diào)用。
./packages/apps/nfc是一個類似于電話本的應(yīng)用程序,但這個程序在手機開機后自動啟動,一直運行,是作為NFC的服務(wù)進程存在的。是NFC架構(gòu)中的核心。
./frameworks/base/core/java/android/nfc/,./frameworks/base/core/java/android/nfc/tech和./frameworks/base/core/java/com/android/internal/nfc/這三個目錄
實現(xiàn)了NFC的應(yīng)用接口,其中./frameworks/base/core/java/com/android/internal/nfc/是一些內(nèi)部類或結(jié)構(gòu),不對外開放,僅供./frameworks/base/core/java/android/nfc/和
./frameworks/base/core/java/android/nfc/tech中的類調(diào)用。
./frameworks/base/core/java/android/nfc實現(xiàn)了接口包com.android.nfc,./frameworks/base/core/java/android/nfc/tech實現(xiàn)了接口包com.android.nfc.tech.
圖示如下:
附錄:
NFC Service的說明
NFC: Move NFC service implementation out of system_server.
NFC service is now an application service in packages/apps/Nfc.
NFC service is registered through ServiceManager.addService(), and the proxy object NfcAdapter obtains a handle to it through
ServiceManager.getService().
**Important** Had to add new symbols AID_NFC / NFC_UID / android.uid.nfc and modify service_manager.c, Process.java and PackageManagerService.java
in order to force the com.android.nfc process to take a fixed uid, so that it can use ServiceManager.addService().
Most of the JNI has moved to packages/apps/Nfc/jni. However NdefRecord and NdefMessage require some in-process native code, so
android_com_NdefMessage.cpp and android_com_NdefRecord.cpp stay in frameworks/base/core/jni. They link to a very small library libnfc_ndef.so
that implements NDEF message parsing. This has been added to core.mk so all devices (even without NFC hardware) can work with NDEF data.
評論