Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ebd59bb authored by Jason parks's avatar Jason parks
Browse files

Return a zero length byte from toByteArray instead of null.

Change-Id: I67b388099c72a0d2ec6b429caea8f29bf8f7a75a
parent 38e561dd
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


package android.nfc;
package android.nfc;


import android.nfc.NdefRecord;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;


@@ -69,11 +68,10 @@ public final class NdefMessage implements Parcelable {
     * Returns a byte array representation of this entire NDEF message.
     * Returns a byte array representation of this entire NDEF message.
     */
     */
    public byte[] toByteArray() {
    public byte[] toByteArray() {
        //TODO: do not return null
        //TODO: allocate the byte array once, copy each record once
        //TODO: allocate the byte array once, copy each record once
        //TODO: process MB and ME flags outside loop
        //TODO: process MB and ME flags outside loop
        if ((mRecords == null) || (mRecords.length == 0))
        if ((mRecords == null) || (mRecords.length == 0))
            return null;
            return new byte[0];


        byte[] msg = {};
        byte[] msg = {};


@@ -104,10 +102,12 @@ public final class NdefMessage implements Parcelable {
        return msg;
        return msg;
    }
    }


    @Override
    public int describeContents() {
    public int describeContents() {
        return 0;
        return 0;
    }
    }


    @Override
    public void writeToParcel(Parcel dest, int flags) {
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mRecords.length);
        dest.writeInt(mRecords.length);
        dest.writeTypedArray(mRecords, flags);
        dest.writeTypedArray(mRecords, flags);
@@ -115,12 +115,14 @@ public final class NdefMessage implements Parcelable {


    public static final Parcelable.Creator<NdefMessage> CREATOR =
    public static final Parcelable.Creator<NdefMessage> CREATOR =
            new Parcelable.Creator<NdefMessage>() {
            new Parcelable.Creator<NdefMessage>() {
        @Override
        public NdefMessage createFromParcel(Parcel in) {
        public NdefMessage createFromParcel(Parcel in) {
            int recordsLength = in.readInt();
            int recordsLength = in.readInt();
            NdefRecord[] records = new NdefRecord[recordsLength];
            NdefRecord[] records = new NdefRecord[recordsLength];
            in.readTypedArray(records, NdefRecord.CREATOR);
            in.readTypedArray(records, NdefRecord.CREATOR);
            return new NdefMessage(records);
            return new NdefMessage(records);
        }
        }
        @Override
        public NdefMessage[] newArray(int size) {
        public NdefMessage[] newArray(int size) {
            return new NdefMessage[size];
            return new NdefMessage[size];
        }
        }