revtel / react-native-nfc-manager

React Native NFC module for Android & iOS
MIT License
1.35k stars 317 forks source link

Android 13 App Launch - java.lang.SecurityException (Tag is out of date) #629

Closed n-kulic closed 1 year ago

n-kulic commented 1 year ago

Quick Information

--

What Happened?

On NDEF_DISCOVERED app launch activity app crashes with the following exception:

Exception java.lang.SecurityException:
  at android.nfc.Tag.getTagService (Tag.java:381)
  at android.nfc.tech.Ndef.canMakeReadOnly (Ndef.java:344)
  at community.revteltech.nfc.Util.ndefToJSON (Util.java:42)
  ...

Exception on Util.java line 42:

Related issues:

--

Expected result

App starts without crash/exception

--

Steps to reproduce

  1. Clone https://github.com/revtel/react-native-nfc-rewriter and start app
  2. Terminate app (swipe out) and scan nfc tag with URI record https://washow.netlify.app

--

Stacktrace

Exception java.lang.SecurityException:
  at android.nfc.Tag.getTagService (Tag.java:381)
  at android.nfc.tech.Ndef.canMakeReadOnly (Ndef.java:344)
  at community.revteltech.nfc.Util.ndefToJSON (Util.java:42)
  at community.revteltech.nfc.NfcManager.buildNdefJSON (NfcManager.java:1389)
  at community.revteltech.nfc.NfcManager.ndef2React (NfcManager.java:1381)
  at community.revteltech.nfc.NfcManager.parseNfcIntent (NfcManager.java:1351)
  at community.revteltech.nfc.NfcManager.start (NfcManager.java:995)
  at java.lang.reflect.Method.invoke
  at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
  at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:188)
  at com.facebook.jni.NativeRunnable.run
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27)
  at android.os.Looper.loopOnce (Looper.java:201)
  at android.os.Looper.loop (Looper.java:288)
  at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:228)
  at java.lang.Thread.run (Thread.java:1012)
rpopovych commented 1 year ago

Ran into the same issue after setting up an intent-filter:

<intent-filter>
  <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
  <data android:scheme="https" android:host="myapp.com"/>
  <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 5 days with no activity.

hkaras19 commented 10 months ago

@rpopovych @n-kulic were you able to find a solution for this? I am currently running into it as well.

hkaras19 commented 10 months ago

@whitedogg13 I noticed that you reopened this issue in August. Was a fix for this released?

rpopovych commented 10 months ago

@hkaras19 I have not found a solution unfortunately. We've put the implementation on pause for other reasons.

n-kulic commented 10 months ago

@rpopovych @n-kulic were you able to find a solution for this? I am currently running into it as well.

@hkaras19 @rpopovych SecurityException is thrown when trying to check whether a tag can be made read-only. Since our app did not required this data we've commented out that part and patched a package.

If your app does not need this data you can as well patch this package:

  1. Install and set-up https://www.npmjs.com/package/patch-package

  2. Go to node_modules/react-native-nfc-manager/android/src/main/java/community/revteltech/nfc/Util.java and comment out lines 41 to 45:

    image
  3. Execute the npx patch-package react-native-nfc-manager command after removing the code that causes an exception (or if using yarn, yarn patch-package react-native-nfc-manager).