Fix for unstable NFC connection on LineageOS (Android 13+)

In the last few months, I have debugged a quite interesting issue concerning Android smartphones running LineageOS and Android version 13+ : The NFC connection to a smartcard (or Apex chip) would just break even though the chip was still computing stuff.

I will spare you the gnarly details, in short the NFC driver used by LineageOS starting with Android 13 is the open-source one from the AOSP project, called NfcNci. Before, the (semi) closed source one was used (NQNfcNci), made by NXP and Qualcomm. Anyway, the open source driver has a “bug” in that it does not wait long enough for a chip to return a response, instead assuming it has been removed.

This issue is quite an easy fix if you have access to the app source code. Fidesmo, for example, has been already notified and will publish this fix very soon.

For all other apps, I present to you a LSPosed module written by me, which modifies any selected apps at runtime and injects the proper NFC driver configuration. This requires a rooted Android phone and some amount of setup, I am not liable for any damage to your smartphone.

Check it out at GitHub - StarGate01/NFCPresenceFix: LSPosed module to fix the NFC presence timeout of AOSP NfcNci .

Read more at:

12 Likes

After a few very annoying smartphone reinstalls, I have to add this warning:

Do NOT try to inject this module into any app targeted by Shamiko / Magisk denylist or your smartphone WILL BOOTLOOP.

I don’t know wether this is a problem with this module or with Magisk, but I don’t intend to find out. In general, if you mess with Magisk / LSPosed, make sure to have and know a backup and recovery strategy.

2 Likes

A better LSPosed module has been developed by rmnscnce · GitHub , which directly hooks into the Android NFC implementation instead of the individual apps. This solves all the issues with Shamiko etc. Source code can be found at GitHub - rmnscnce/NfcNci_Patience: Add a 1000ms delay to NFC presence check to accommodate longer NFC smart card operations in AOSP NfcNci implementation on certain devices , the module is also listed in the LSPosed module repository.

3 Likes

Has anyone opened an issue with the AOSP? Seems like an easy upstream fix

2 Likes

I have reported the issue in LineageOS: NfcNci breaks long-running NFC smartcard actions due to EXTRA_READER_PRESENCE_CHECK_DELAY being too short (#7268) · Issues · LineageOS / issues / android · GitLab , but I am not familiar enough with AOSP yet. Any help or advise is welcome.

1 Like