Question

I'm searching the Android source code because I want to understand when the AndroidManifest.xml of an app gets parsed.

I.e. if an app registeres an NFC service

<service
        android:name=".demo.service.ApduService"
        android:exported="true"
        android:permission="android.permission.BIND_NFC_SERVICE">

        <intent-filter>
            <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
        </intent-filter>

        <meta-data
            android:name="android.nfc.cardemulation.host_apdu_service"
            android:resource="@xml/apduservice" />
    </service>

with following apduservice.xml

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/servicedesc"
android:requireDeviceUnlock="false" >

<aid-group
    android:category="other"
    android:description="@string/aiddescription" >
    <aid-filter android:name="23498234098234098" />
</aid-group>

When and where does the Android OS read the aid-filter and registeres the ID?

(I know where it will be stored, and how, but I can't find the event where the actual ID gets extracted and forwarded to the NFC stack)

Was it helpful?

Solution

When is the list of host and off-host CE services updated?

The information about host and off-host APDU service (HCE and SE-based CE) is collected and updated whenever application packages are added, changed, updated, removed, etc. This is handled by a broadcast receiver in com.android.nfc.cardemulation.RegisteredServicesCache. The broadcast receiver is sensitive for the following events:

  • ACTION_PACKAGE_ADDED
  • ACTION_PACKAGE_CHANGED
  • ACTION_PACKAGE_REMOVED
  • ACTION_PACKAGE_REPLACED
  • ACTION_PACKAGE_FIRST_LAUNCH
  • ACTION_PACKAGE_RESTARTED
  • ACTION_EXTERNAL_APPLICATIONS_AVAILABLE
  • ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE

In addition, the AIDs are updated every time the NFC service is enabled.

How and where is the list of services generated?

During an update, the system is queried for a list of services that filter for the intent actions android.nfc.cardemulation.action.HOST_APDU_SERVICE and android.nfc.cardemulation.action.OFF_HOST_APDU_SERVICE. For each service it is checked if the app holds the permission to use NFC and if the service requires the BIND_NFC_SERVICE permission. If that's the case, the services are considered for card emulation.

How and where is the AID list extracted?

The host and off-host APDU services are then stored in a list of andoid.nfc.cardemulation.ApduServiceInfo objects. The constructor of that class processes the meta data specified in the <service> tag and extracts the list of AIDs.

How and where is the card emulation system updated with the new list?

After the list has been compiled, it is passed to the com.android.nfc.cardemulation.RegisteredAidCache. There, the list of services and AIDs is used to compile the routing tables for on-host and off-host AID routing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top