cancel
Showing results for 
Search instead for 
Did you mean: 

ST25NFCApplicationV3.7.0 Crashes on Android 13 (Pixel6a)

hagbard
Associate II

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 discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
Olivier L
ST Employee

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*/);
    }

View solution in original post

13 REPLIES 13
Olivier L
ST Employee

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

hagbard
Associate II

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

Olivier L
ST Employee

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

hagbard
Associate II

Hi Oliver,

this is what i get:

0693W00000aJXqXQAW.pngStacktrace is attached.

Best Regards,

Stephan

Olivier L
ST Employee

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

Olivier L
ST Employee

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 L
ST Employee

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*/);
    }

hagbard
Associate II

Hi Oliver,

thank you very much for your fast help.

Now it works as expected ;)

Best Regards,

Stephan

Olivier L
ST Employee

Perfect! Thank you Stephan for this feedback.

Best regards

Olivier