1

I am working on application that joins functionalities from SecureElement and HCE (HostCardEmulation) and processes APDU commands from external source.

Based on the availability of SecureElement I would like to decide if all APDUs are processed from NfcController to SecureElement (default option if SecureElement present) and if not present I would like HCE to take care of the APDU processing.

And here is my question, is such case possible ?

According to https://developer.android.com/guide/topics/connectivity/nfc/hce.html I assume that it is possible only if aids for SecureElement and HCE are different. Otherwise if screen is on I will have to choose myself which service use (HostApduService or OffHostApduService) or android will use the foreground service to handle the APDUs if screen is off.

What in case if I have the same AID for both channels ? Anyone had such case ?

wsl
  • 8,875
  • 1
  • 20
  • 24

1 Answers1

1

I ended up using dynamic aid registration -> https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.html#registerAidsForService(android.content.ComponentName,%20java.lang.String,%20java.util.List)

So I am able to decide which Controller to use in a runtime.

wsl
  • 8,875
  • 1
  • 20
  • 24
  • How did you manage that? I have a similar problem and want to dynamically regsiter or remove AIDs either on the SE oder for HCE. But calls to CardEmulation.registerAidsForService always return false. Logcat says something about "ApduServiceInfo: Not adding with empty or invalid AIDs". The AID ias valid though. – Sebastian Götz May 05 '21 at 08:31