Skip to main content
Visitor II
March 22, 2023
Solved

ST25NFCApplicationV3.7.0 Crashes on Android 13 (Pixel6a)

  • March 22, 2023
  • 11 replies
  • 6022 views

Hello,

st25nfcApplication_V3.7.0 is crashing on my Pixel6A (Android13) caused by the following source:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1

   Process: com.st.st25nfc.dbg, PID: 1098

   java.lang.RuntimeException: An error occurred while executing doInBackground()

       at android.os.AsyncTask$4.done(AsyncTask.java:415)

       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381)

       at java.util.concurrent.FutureTask.setException(FutureTask.java:250)

       at java.util.concurrent.FutureTask.run(FutureTask.java:269)

       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)

       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)

       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)

       at java.lang.Thread.run(Thread.java:1012)

    Caused by: java.lang.SecurityException: Permission Denial: Tag ( ID: 2E D4 4E 50 00 27 02 E0 ) is out of date

       at android.nfc.Tag.getTagService(Tag.java:381)

Could this be the the reasion: ???

Catch a SecurityException that was introduced in AOSP commit 113f3a4. It is thrown when an NFC tag is removed.

https://github.com/open-keychain/open-keychain/pull/2804

Does anyone have a solution ?

    This topic has been closed for replies.
    Best answer by Olivier L

    Hi,

    To fix this issue, you will need the latest "Android Reader Interface" (version >= 1.0.9). It can be downloaded from ST25SDK package. This is the file named "st25_android_reader_interface.aar".

    Then, in your application, you should find the code processing the Android Intent indicating a new Tag Handle (NfcAdapter.EXTRA_TAG) and you should update the NFCTag object that you are using. This is the lines 35 to 45:

    public void onResume() {
     super.onResume();
     
     NFCTag currentTag = (NFCTag) MainActivity.getTag();
     mIsActive = true;
     
     boolean tagChanged = tagChanged(this, currentTag);
     
     if (mTagTapedListener != null) {
     mTagTapedListener.tagTaped(tagChanged);
     }
     
     if (tagChanged) {
     Log.d(TAG, "=== Tag has changed : Restart MainActivity ===");
     
     // Tag has changed. We want to do the following actions;
     // - Go back to the MainActivity and flush the activity stack history (MainActivity will be seen as the sole activity launched)
     // - The intent should contain the NFC Intent details so that MainActivity can process it and do the right actions.
     
     // Get current NFC intent and retrieve the NFC information (NfcAdapter.EXTRA_TAG)
     Intent nfcIntent = getIntent();
     Tag androidTag = nfcIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
     
     // Create an intent to start the MainActivity
     Intent intent = new Intent(this, MainActivity.class);
     
     // Attach the NFC information to this intent
     intent.putExtra(NfcAdapter.EXTRA_TAG, androidTag);
     
     // Set the flags to flush the activity stack history
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
     
     startActivity(intent);
     } else {
     // The same tag has been tapped
     // If a new androidTag handle is available we should update the AndroidReaderInterface of the currentTag
     Intent intent = getIntent();
     Tag newAndroidTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
     if (newAndroidTag != null) {
     if (currentTag != null) {
     AndroidReaderInterface androidReaderInterface = (AndroidReaderInterface) currentTag.getReaderInterface();
     Tag currentAndroidTag = androidReaderInterface.getAndroidTag();
     if (newAndroidTag != currentAndroidTag) {
     Log.w(TAG, "Update of androidTag handle: " + newAndroidTag);
     androidReaderInterface.setAndroidTag(newAndroidTag);
     }
     }
     }
     }
     
     Log.v(TAG, "enableForegroundDispatch");
     mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, null /*nfcFiltersArray*/, null /*nfcTechLists*/);
     }

    11 replies

    ST Employee
    March 22, 2023

    Hi,

    Thank you for pointing this issue. We are starting working on a new release of ST25 NFC Tap application. It will be available by end of next week (31th of March).

    In which activity and with which tag did you see this exception? Would you have instructions to replicate the issue?

    Best regards

    Olivier

    hagbardAuthor
    Visitor II
    March 22, 2023

    Hi Oliver,

    the following steps let me reproduce the issue:

    1. open the ST25NFCTap V3.7.0 APP on my Pixel6A (Android13)
    2. move the phone to a ANT7-T-ST25DV04K Board
    3. "TAG INFO" shows all information as it should, everything works as expected
    4. move phone away from ANT7-T-ST25DV04K.
    5. move phone onto ANT7-T-ST25DV04K again
    6. application crashes (Caused by: java.lang.SecurityException: Permission Denial: Tag ( ID: 2E D4 4E 50 00 27 02 E0 ) is out of date)

    I´m not an android expert, but i think they changed something in Android 13:

    https://issuetracker.google.com/issues/238257723

    This seems the same issue:

    https://github.com/android-password-store/Android-Password-Store/issues/2294

    We were not able to reproduce this on a OnePlus9 running Android12.

    Let me know if you need any further information.

    Best Regards,

    Stephan

    ST Employee
    March 22, 2023

    Thank you Stephan.

    I do have a Google Pixel 6 running Android 13 (this is not a 6A). For the moment I have seen the exception "java.lang.SecurityException: Permission Denial: Tag ( ID: 77 13 7A 02 00 51 02 E0 ) is out of date" but it leads to an error and not to a crash. I need to do more tests.

    For my information, in the backtrace displayed during the exception, would you have the file name and the line number where the problem occured? The file should be in the package com.st.st25nfc.

    If you can copy paste the full stack trace, that would hep.

    Thank you, regards

    Olivier

    hagbardAuthor
    Visitor II
    March 23, 2023

    Hi Oliver,

    this is what i get:

    0693W00000aJXqXQAW.pngStacktrace is attached.

    Best Regards,

    Stephan

    ST Employee
    March 23, 2023

    Hi Stephan,

    Thank you. I'm going to find a solution.

    Till now, it was not a problem if the NFC Tag was moved out of the phone's RF field.

    When the tag gets back in the field, we had a Beep, our application was notified and was checking the tag UID. It was seeing that it was still the same tag and we were able to keep using the same object to handle this tag.

    It seems that it is no more the case with Android 13. I need to search what should be changed to avoid a re-instanciation of the Tag object.

    Regards

    Olivier

    ST Employee
    March 24, 2023

    Hi Stephan,

    I have implemented a fix. It will be available on Google Play and st.com by end of next week.

    Best regards

    Olivier

    Olivier LAnswer
    ST Employee
    March 29, 2023

    Hi,

    To fix this issue, you will need the latest "Android Reader Interface" (version >= 1.0.9). It can be downloaded from ST25SDK package. This is the file named "st25_android_reader_interface.aar".

    Then, in your application, you should find the code processing the Android Intent indicating a new Tag Handle (NfcAdapter.EXTRA_TAG) and you should update the NFCTag object that you are using. This is the lines 35 to 45:

    public void onResume() {
     super.onResume();
     
     NFCTag currentTag = (NFCTag) MainActivity.getTag();
     mIsActive = true;
     
     boolean tagChanged = tagChanged(this, currentTag);
     
     if (mTagTapedListener != null) {
     mTagTapedListener.tagTaped(tagChanged);
     }
     
     if (tagChanged) {
     Log.d(TAG, "=== Tag has changed : Restart MainActivity ===");
     
     // Tag has changed. We want to do the following actions;
     // - Go back to the MainActivity and flush the activity stack history (MainActivity will be seen as the sole activity launched)
     // - The intent should contain the NFC Intent details so that MainActivity can process it and do the right actions.
     
     // Get current NFC intent and retrieve the NFC information (NfcAdapter.EXTRA_TAG)
     Intent nfcIntent = getIntent();
     Tag androidTag = nfcIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
     
     // Create an intent to start the MainActivity
     Intent intent = new Intent(this, MainActivity.class);
     
     // Attach the NFC information to this intent
     intent.putExtra(NfcAdapter.EXTRA_TAG, androidTag);
     
     // Set the flags to flush the activity stack history
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
     
     startActivity(intent);
     } else {
     // The same tag has been tapped
     // If a new androidTag handle is available we should update the AndroidReaderInterface of the currentTag
     Intent intent = getIntent();
     Tag newAndroidTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
     if (newAndroidTag != null) {
     if (currentTag != null) {
     AndroidReaderInterface androidReaderInterface = (AndroidReaderInterface) currentTag.getReaderInterface();
     Tag currentAndroidTag = androidReaderInterface.getAndroidTag();
     if (newAndroidTag != currentAndroidTag) {
     Log.w(TAG, "Update of androidTag handle: " + newAndroidTag);
     androidReaderInterface.setAndroidTag(newAndroidTag);
     }
     }
     }
     }
     
     Log.v(TAG, "enableForegroundDispatch");
     mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, null /*nfcFiltersArray*/, null /*nfcTechLists*/);
     }

    Explorer
    April 16, 2024

    Hi Oliver,

    We have same problem on Android 13... Can you help me please with this error: cannot find symbol
    androidReaderInterface.setAndroidTag(newAndroidTag);

     

    setAndroidTag is not defined in AndroidReaderInterface class??

    hagbardAuthor
    Visitor II
    March 29, 2023

    Hi Oliver,

    thank you very much for your fast help.

    Now it works as expected ;)

    Best Regards,

    Stephan

    ST Employee
    March 29, 2023

    Perfect! Thank you Stephan for this feedback.

    Best regards

    Olivier

    ST Employee
    April 16, 2024

    Hi Entony,

    I will need more information about the versions that you are using. ST25NFCTap Android application is made of 3 layers:

    • At the low level, there is the AndroidReaderInterface which creates a generic interface to access to NFC Tag on Android phones.
    • Above, there is the ST25SDK library. This is a java library implementing commands for all our ST25 portfolio of NFC Tags. On Android, it relies on the AndroidReaderInterface to communicate with the NFC controler.
    • Then above the ST25SDK, there is the android ST25NFCTap application. 

    The current version of ST25NFCTap application is 3.9.0.

    The current version of ST25SDK is 1.10.0.

    The current version of AndroidReaderInterface is 1.0.10.

    setAndroidTag() is defined in AndroidReaderInterface. Did you successfully add the AndroidReaderInterface's AAR file to your Android Studio project?

     

    Explorer
    April 17, 2024

    Hi Oliver,

    thank you for your answer. You are right, it was a problem with the AndroidReaderInterface AAR file, I had an older version 1.0.8