Commit 4dc1bcbc authored by Leon Han's avatar Leon Han Committed by Commit Bot

[webnfc] Handle the case of android.nfc.tech.Ndef.getNdefMessage() returning null

android.nfc.tech.Ndef.getNdefMessage() may return null when the tag is
formatted but is empty, we need to handle the case well.
See
https://developer.android.com/reference/android/nfc/tech/Ndef.html#getNdefMessage().

BUG=520391

Change-Id: I49cdf40978ad837546dcb050ce8e7d2cac4662ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736167
Auto-Submit: Leon Han <leon.han@intel.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Leon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#684220}
parent 3a99193d
...@@ -557,17 +557,20 @@ public class NfcImpl implements Nfc { ...@@ -557,17 +557,20 @@ public class NfcImpl implements Nfc {
try { try {
mTagHandler.connect(); mTagHandler.connect();
message = mTagHandler.read(); message = mTagHandler.read();
if (message == null) {
Log.w(TAG, "Cannot read data from NFC tag. Tag is empty.");
return;
}
if (message.getByteArrayLength() > NdefMessage.MAX_SIZE) { if (message.getByteArrayLength() > NdefMessage.MAX_SIZE) {
Log.w(TAG, "Cannot read data from NFC tag. NdefMessage exceeds allowed size."); Log.w(TAG, "Cannot read data from NFC tag. NdefMessage exceeds allowed size.");
return; return;
} }
notifyMatchingWatchers(message, mTagHandler.compatibility());
} catch (TagLostException e) { } catch (TagLostException e) {
Log.w(TAG, "Cannot read data from NFC tag. Tag is lost."); Log.w(TAG, "Cannot read data from NFC tag. Tag is lost.");
} catch (FormatException | IllegalStateException | IOException e) { } catch (FormatException | IllegalStateException | IOException e) {
Log.w(TAG, "Cannot read data from NFC tag. IO_ERROR."); Log.w(TAG, "Cannot read data from NFC tag. IO_ERROR.");
} }
if (message != null) notifyMatchingWatchers(message, mTagHandler.compatibility());
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment