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

Commit 1f5badc1 authored by Nick Pelly's avatar Nick Pelly
Browse files

Add NdefMessage.getByteLength(), and more minor fixes:

Remove NdefMessage from dispatch(). It's already in the Tag.
/*package*/ cleanup
Fix sitemap after removal of NFCDemo

Change-Id: Ie1f6d9ea98144aa97f56bb709a33f5d0ef916e8b
parent 7e4ef617
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12621,6 +12621,7 @@ package android.nfc {
    ctor public NdefMessage(android.nfc.NdefRecord, android.nfc.NdefRecord...);
    ctor public NdefMessage(android.nfc.NdefRecord[]);
    method public int describeContents();
    method public int getByteLength();
    method public android.nfc.NdefRecord[] getRecords();
    method public byte[] toByteArray();
    method public void writeToParcel(android.os.Parcel, int);
+1 −1
Original line number Diff line number Diff line
@@ -44,5 +44,5 @@ interface INfcAdapter
            in IntentFilter[] filters, in TechListParcel techLists);
    void setForegroundNdefPush(in NdefMessage msg, in INdefPushCallback callback);

    void dispatch(in Tag tag, in NdefMessage message);
    void dispatch(in Tag tag);
}
+24 −6
Original line number Diff line number Diff line
@@ -158,7 +158,28 @@ public final class NdefMessage implements Parcelable {
    }

    /**
     * Return this NDEF MEssage as raw bytes.<p>
     * Return the length of this NDEF Message if it is written to a byte array
     * with {@link #toByteArray}.<p>
     * An NDEF Message can be formatted to bytes in different ways
     * depending on chunking, SR, and ID flags, so the length returned
     * by this method may not be equal to the length of the original
     * byte array used to construct this NDEF Message. However it will
     * always be equal to the length of the byte array produced by
     * {@link #toByteArray}.
     *
     * @return length of this NDEF Message when written to bytes with {@link toByteArray}
     * @see #toByteArray
     */
    public int getByteArrayLength() {
        int length = 0;
        for (NdefRecord r : mRecords) {
            length += r.getByteLength();
        }
        return length;
    }

    /**
     * Return this NDEF Message as raw bytes.<p>
     * The NDEF Message is formatted as per the NDEF 1.0 specification,
     * and the byte array is suitable for network transmission or storage
     * in an NFC Forum NDEF compatible tag.<p>
@@ -166,13 +187,10 @@ public final class NdefMessage implements Parcelable {
     * short record (SR) format and omit the identifier field when possible.
     *
     * @return NDEF Message in binary format
     * @see getByteArrayLength
     */
    public byte[] toByteArray() {
        int length = 0;
        for (NdefRecord r : mRecords) {
            length += r.getByteLength();
        }

        int length = getByteArrayLength();
        ByteBuffer buffer = ByteBuffer.allocate(length);

        for (int i=0; i<mRecords.length; i++) {
+2 −2
Original line number Diff line number Diff line
@@ -889,12 +889,12 @@ public final class NfcAdapter {
     * {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission.
     * @hide
     */
    public void dispatch(Tag tag, NdefMessage message) {
    public void dispatch(Tag tag) {
        if (tag == null) {
            throw new NullPointerException("tag cannot be null");
        }
        try {
            sService.dispatch(tag, message);
            sService.dispatch(tag);
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
        }
+8 −8
Original line number Diff line number Diff line
@@ -108,14 +108,14 @@ import java.util.Arrays;
 * <p>
 */
public final class Tag implements Parcelable {
    /*package*/ final byte[] mId;
    /*package*/ final int[] mTechList;
    /*package*/ final String[] mTechStringList;
    /*package*/ final Bundle[] mTechExtras;
    /*package*/ final int mServiceHandle;  // for use by NFC service, 0 indicates a mock
    /*package*/ final INfcTag mTagService; // interface to NFC service, will be null if mock tag

    /*package*/ int mConnectedTechnology;
    final byte[] mId;
    final int[] mTechList;
    final String[] mTechStringList;
    final Bundle[] mTechExtras;
    final int mServiceHandle;  // for use by NFC service, 0 indicates a mock
    final INfcTag mTagService; // interface to NFC service, will be null if mock tag

    int mConnectedTechnology;

    /**
     * Hidden constructor to be used by NFC service and internal classes.
Loading