From c03eaa6853ac082d6c460c4bbb2d4cc4f85f0a38 Mon Sep 17 00:00:00 2001 From: Yuka Anami Date: Mon, 15 May 2017 13:53:04 +0900 Subject: [PATCH] Add ID_LENGTH field for Empty type record If ID_LENGTH field is omitted from Empty Type record, it cannot be detected as Ndef since the data is strictly checked by e3fc7d9954. But it is not possible to create raw bytes of Empty Type record which can meet this condition by using NdefRecord/NdefMessage. To fix this issue, added ID_LENGTH field to Empty type record. Bug: 38299566 Test: Write and read NDEF tag with empty type record Change-Id: Idb58c80cf8562a8b314f4ddeccdc627dc0c6f5b4 (cherry picked from commit ef9d0a480ef72a4ff0de5b5afa3661cff81fd8b5) --- core/java/android/nfc/NdefRecord.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/nfc/NdefRecord.java b/core/java/android/nfc/NdefRecord.java index 2c9ce3f99285c..093a9b469cb82 100644 --- a/core/java/android/nfc/NdefRecord.java +++ b/core/java/android/nfc/NdefRecord.java @@ -938,7 +938,7 @@ public final class NdefRecord implements Parcelable { */ void writeToByteBuffer(ByteBuffer buffer, boolean mb, boolean me) { boolean sr = mPayload.length < 256; - boolean il = mId.length > 0; + boolean il = mTnf == TNF_EMPTY ? true : mId.length > 0; byte flags = (byte)((mb ? FLAG_MB : 0) | (me ? FLAG_ME : 0) | (sr ? FLAG_SR : 0) | (il ? FLAG_IL : 0) | mTnf); @@ -966,7 +966,7 @@ public final class NdefRecord implements Parcelable { int length = 3 + mType.length + mId.length + mPayload.length; boolean sr = mPayload.length < 256; - boolean il = mId.length > 0; + boolean il = mTnf == TNF_EMPTY ? true : mId.length > 0; if (!sr) length += 3; if (il) length += 1;