Android中对NFC的实现代码分布在如下几个地方:
./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语言编写的函数库,编译生成libnfc和libnfc_ndef两个函数库。libnfc是一个主要的库,实现了NFC Stack的大部分功能,主要供NFC的服务进程调用。
libnfc_ndef是一个很小的函数库,主要是实现NDEF消息的解析,供Framework调用。
./packages/apps/nfc是一个类似于电话本的应用程序,但这个程序在手机开机后自动启动,一直运行,是作为NFC的服务进程存在的。是NFC架构中的核心。
./frameworks/base/core/java/android/nfc/,./frameworks/base/core/java/android/nfc/tech和./frameworks/base/core/java/com/android/internal/nfc/这三个目录
实现了NFC的应用接口,其中./frameworks/base/core/java/com/android/internal/nfc/是一些内部类或结构,不对外开放,仅供./frameworks/base/core/java/android/nfc/和
./frameworks/base/core/java/android/nfc/tech中的类调用。
./frameworks/base/core/java/android/nfc实现了接口包com.android.nfc,./frameworks/base/core/java/android/nfc/tech实现了接口包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.