diff options
author | Martijn Coenen <maco@google.com> | 2011-04-08 16:42:22 +0200 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-05-27 08:18:18 -0700 |
commit | 8bede1704717f594a0f924a57ff46f6300347e30 (patch) | |
tree | 13b2c6393c5556e28aee44b0d86a088a84c0e377 /core/java/android | |
parent | aa4fa2c5b704b60f025c34fec42db63ede9ebf35 (diff) | |
download | frameworks_base-8bede1704717f594a0f924a57ff46f6300347e30.zip frameworks_base-8bede1704717f594a0f924a57ff46f6300347e30.tar.gz frameworks_base-8bede1704717f594a0f924a57ff46f6300347e30.tar.bz2 |
Fix NdefRecord flags handling.
NdefMessages created from byte arrays set the wrong flags on
NdefRecord: every record had at least FLAG_MB|FLAG_ME set, instead of actually
setting the flags from the byte-stream itself. Fixed by creating an internal
constructor which can take the flags.
Public constructor remains the same, as we don't want to bother application
writers with these flags - they can be inferred from the context in which the
record is used. Getting the flags is not a public operation on an NdefRecord
either. However, applications can get the byte[] representation and it
is reasonable for them to expect the flags byte to be set correctly.
Change-Id: Ic32411688dd092c55b1aeccbba9635792e15a671
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/nfc/NdefRecord.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/core/java/android/nfc/NdefRecord.java b/core/java/android/nfc/NdefRecord.java index 746d3df..fe215fd 100644 --- a/core/java/android/nfc/NdefRecord.java +++ b/core/java/android/nfc/NdefRecord.java @@ -163,6 +163,18 @@ public final class NdefRecord implements Parcelable { * must not be null */ public NdefRecord(short tnf, byte[] type, byte[] id, byte[] payload) { + /* New NDEF records created by applications will have FLAG_MB|FLAG_ME + * set by default; when multiple records are stored in a + * {@link NdefMessage}, these flags will be corrected when the {@link NdefMessage} + * is serialized to bytes. + */ + this(tnf, type, id, payload, (byte)(FLAG_MB|FLAG_ME)); + } + + /** + * @hide + */ + /*package*/ NdefRecord(short tnf, byte[] type, byte[] id, byte[] payload, byte flags) { /* check arguments */ if ((type == null) || (id == null) || (payload == null)) { throw new IllegalArgumentException("Illegal null argument"); @@ -172,9 +184,6 @@ public final class NdefRecord implements Parcelable { throw new IllegalArgumentException("TNF out of range " + tnf); } - /* generate flag */ - byte flags = FLAG_MB | FLAG_ME; - /* Determine if it is a short record */ if(payload.length < 0xFF) { flags |= FLAG_SR; @@ -258,6 +267,7 @@ public final class NdefRecord implements Parcelable { } public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(mFlags); dest.writeInt(mTnf); dest.writeInt(mType.length); dest.writeByteArray(mType); @@ -270,6 +280,7 @@ public final class NdefRecord implements Parcelable { public static final Parcelable.Creator<NdefRecord> CREATOR = new Parcelable.Creator<NdefRecord>() { public NdefRecord createFromParcel(Parcel in) { + byte flags = (byte)in.readInt(); short tnf = (short)in.readInt(); int typeLength = in.readInt(); byte[] type = new byte[typeLength]; @@ -281,7 +292,7 @@ public final class NdefRecord implements Parcelable { byte[] payload = new byte[payloadLength]; in.readByteArray(payload); - return new NdefRecord(tnf, type, id, payload); + return new NdefRecord(tnf, type, id, payload, flags); } public NdefRecord[] newArray(int size) { return new NdefRecord[size]; @@ -290,4 +301,4 @@ public final class NdefRecord implements Parcelable { private native int parseNdefRecord(byte[] data); private native byte[] generate(short flags, short tnf, byte[] type, byte[] id, byte[] data); -}
\ No newline at end of file +} |