I have created an Android app which uses Host Card Emulation to emulate a contactless smartcard. Now, in a situation where both the real smartcard and the app are close to a reader, I would like to shadow completely the smartcard tag with my HCE app in a way that only the app answers to the reader while the smartcard won't be detected even if the distance is equal and right for detecting both tags.
Is there a way to achieve this? If not, is there a way to at least make the app always answer first instead of the smartcard?
No, that's not possible.
In general, tags can't directly influence the singulation and selection procedure on the reader side. It's up to the reader (software) to enumerate all tags and select a particular tag/contactless smartcard for communication. Consequently, the HCE app has no control over this mechanism.
In practice reader applications handle the case of multiple tags in different ways:
- A reader might simply enumerate and select only a single tag. For NFC-A, this could, for instance, be the tag with the lowest (or highest) UID. In that case, a tag might (to some extend) be able to influence the outcome of enumeration by using a UID that has a better chance of being selected. However, Android HCE does not allow you to influence the UID (anti-collision identifier), so this trick won't work for you.
- A reader might enumerate all tags and, if multiple tags were discovered, stop communication with all of them. For instance, this is mandated by the EMV specifications for contactless payment systems in order to prevent accidental payment with the wrong card.
- A reader might enumerate all tags and start communication with all of them. The reader (software) might then choose the best tag based on exchanged protocol parameters. If that's the case, your HCE app could indeed influence the outcome of the reader's selection process by providing the proper parameters to "win" selection. However, this is rarely used in practice. Still this would be an option if you control/develop the reader side yourself.