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

Commit bc70b85f authored by suryaprakash.konduru's avatar suryaprakash.konduru Committed by Roshan Pius
Browse files

Addressed T4T Ndef Nfcee improvements

- Documented that fragmentation/defragmentation is handled by the NFC stack.
- removed unwanted info from cc file info
- "return" & "Throw" device busy state
- updated read/write api documentation

Bug: 380867580
Test: Manual test, read, write, read cc T4T Ndef Nfcee Api's
Change-Id: I33b70e91cfde10855c7b275fda2999cf1844329c
parent 31317e8c
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -200,9 +200,11 @@ package android.nfc {
    method @Nullable @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) @WorkerThread public android.nfc.T4tNdefNfceeCcFileInfo readCcfile();
    method @NonNull @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) @WorkerThread public byte[] readData(@IntRange(from=0, to=65535) int);
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) @WorkerThread public int writeData(@IntRange(from=0, to=65535) int, @NonNull byte[]);
    field public static final int CLEAR_DATA_FAILED_DEVICE_BUSY = -1; // 0xffffffff
    field public static final int CLEAR_DATA_FAILED_INTERNAL = 0; // 0x0
    field public static final int CLEAR_DATA_SUCCESS = 1; // 0x1
    field public static final int WRITE_DATA_ERROR_CONNECTION_FAILED = -6; // 0xfffffffa
    field public static final int WRITE_DATA_ERROR_DEVICE_BUSY = -9; // 0xfffffff7
    field public static final int WRITE_DATA_ERROR_EMPTY_PAYLOAD = -7; // 0xfffffff9
    field public static final int WRITE_DATA_ERROR_INTERNAL = -1; // 0xffffffff
    field public static final int WRITE_DATA_ERROR_INVALID_FILE_ID = -4; // 0xfffffffc
@@ -217,21 +219,14 @@ package android.nfc {
    method public int describeContents();
    method @IntRange(from=15, to=32767) public int getCcFileLength();
    method @IntRange(from=0xffffffff, to=65535) public int getFileId();
    method @IntRange(from=15, to=65535) public int getMaxReadLength();
    method @IntRange(from=5, to=32767) public int getMaxSize();
    method @IntRange(from=13, to=65535) public int getMaxWriteLength();
    method public int getReadAccess();
    method public int getVersion();
    method public int getWriteAccess();
    method public boolean isReadAllowed();
    method public boolean isWriteAllowed();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.nfc.T4tNdefNfceeCcFileInfo> CREATOR;
    field public static final int READ_ACCESS_GRANTED_RESTRICTED = 128; // 0x80
    field public static final int READ_ACCESS_GRANTED_UNRESTRICTED = 0; // 0x0
    field public static final int VERSION_2_0 = 32; // 0x20
    field public static final int VERSION_3_0 = 48; // 0x30
    field public static final int WRITE_ACCESS_GRANTED_RESTRICTED = 128; // 0x80
    field public static final int WRITE_ACCESS_GRANTED_UNRESTRICTED = 0; // 0x0
    field public static final int WRITE_ACCESS_NOT_GRANTED = 255; // 0xff
  }

}
+21 −3
Original line number Diff line number Diff line
@@ -100,9 +100,14 @@ public final class T4tNdefNfcee {
    public static final int WRITE_DATA_ERROR_EMPTY_PAYLOAD = -7;
    /**
     * Returns flag for {@link #writeData(int, byte[])}.
     * It idicates write data fail due to invalid ndef format.
     * It indicates write data fail due to invalid ndef format.
     */
    public static final int WRITE_DATA_ERROR_NDEF_VALIDATION_FAILED = -8;
    /**
     * Returns flag for {@link #writeData(int, byte[])}.
     * It indicates write data fail if a concurrent NDEF NFCEE operation is ongoing.
     */
    public static final int WRITE_DATA_ERROR_DEVICE_BUSY = -9;

    /**
     * Possible return values for {@link #writeData(int, byte[])}.
@@ -119,6 +124,7 @@ public final class T4tNdefNfcee {
        WRITE_DATA_ERROR_CONNECTION_FAILED,
        WRITE_DATA_ERROR_EMPTY_PAYLOAD,
        WRITE_DATA_ERROR_NDEF_VALIDATION_FAILED,
        WRITE_DATA_ERROR_DEVICE_BUSY,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface WriteDataStatus{}
@@ -128,6 +134,9 @@ public final class T4tNdefNfcee {
     *
     * <p>This is an I/O operation and will block until complete. It must
     * not be called from the main application thread.</p>
     * <p>Applications must send complete Ndef Message payload, do not need to fragment
     * the payload, it will be automatically fragmented and defragmented by
     * {@link #writeData} if it exceeds max message length limits</p>
     *
     * @param fileId File id (Refer NFC Forum Type 4 Tag Specification
     *               Section 4.2 File Identifiers and Access Conditions
@@ -155,9 +164,10 @@ public final class T4tNdefNfcee {
     * @param fileId File Id (Refer
     *               Section 4.2 File Identifiers and Access Conditions
     *               for more information) from which to read.
     * @return - Returns Ndef message if success
     * @return - Returns complete Ndef message if success
     *           Refer to Nfc forum NDEF specification NDEF Message section
     * @throws IllegalStateException if read fails because the fileId is invalid.
     * @throws IllegalStateException if read fails because the fileId is invalid
     *         or if a concurrent operation is in progress.
     * @hide
     */
    @SystemApi
@@ -179,6 +189,12 @@ public final class T4tNdefNfcee {
     * It indicates clear data failed due to internal error while processing the clear.
     */
    public static final int CLEAR_DATA_FAILED_INTERNAL = 0;
    /**
     * Return flag for {@link #clearNdefData()}.
     * It indicates clear data failed  if a concurrent NDEF NFCEE operation is ongoing.
     */
    public static final int CLEAR_DATA_FAILED_DEVICE_BUSY = -1;


    /**
     * Possible return values for {@link #clearNdefData()}.
@@ -188,6 +204,7 @@ public final class T4tNdefNfcee {
    @IntDef(prefix = { "CLEAR_DATA_" }, value = {
        CLEAR_DATA_SUCCESS,
        CLEAR_DATA_FAILED_INTERNAL,
        CLEAR_DATA_FAILED_DEVICE_BUSY,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ClearDataStatus{}
@@ -245,6 +262,7 @@ public final class T4tNdefNfcee {
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.4" for more details.
     *
     * @return Returns CC file content if success or null if failed to read.
     * @throws IllegalStateException if the device is busy.
     * @hide
     */
    @SystemApi
+18 −109
Original line number Diff line number Diff line
@@ -46,14 +46,6 @@ public final class T4tNdefNfceeCcFileInfo implements Parcelable {
     * Indicates the mapping specification version<p>
     */
    private int mVersion;
    /**
     * Indicates the max data size by a single ReadBinary<p>
     */
    private int mMaxReadLength;
    /**
     * Indicates the max data size by a single UpdateBinary<p>
     */
    private int mMaxWriteLength;
    /**
     * Indicates the NDEF File Identifier<p>
     */
@@ -65,40 +57,35 @@ public final class T4tNdefNfceeCcFileInfo implements Parcelable {
    /**
     * Indicates the read access condition<p>
     */
    private int mReadAccess;
    private boolean mIsReadAllowed;
    /**
     * Indicates the write access condition<p>
     */
    private int mWriteAccess;
    private boolean mIsWriteAllowed;

    /**
     * Constructor to be used by NFC service and internal classes.
     * @hide
     */
    public T4tNdefNfceeCcFileInfo(int cclen, int version, int maxLe, int maxLc,
    public T4tNdefNfceeCcFileInfo(int cclen, int version,
                      int ndefFileId, int ndefMaxSize,
                      int ndefReadAccess, int ndefWriteAccess) {
                      boolean isReadAllowed, boolean isWriteAllowed) {
        mCcLength = cclen;
        mVersion = version;
        mMaxWriteLength = maxLc;
        mMaxReadLength = maxLe;
        mFileId = ndefFileId;
        mMaxSize = ndefMaxSize;
        mReadAccess = ndefReadAccess;
        mWriteAccess = ndefWriteAccess;
        mIsReadAllowed = isReadAllowed;
        mIsWriteAllowed = isWriteAllowed;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {

        dest.writeInt(mCcLength);
        dest.writeInt(mVersion);
        dest.writeInt(mMaxWriteLength);
        dest.writeInt(mMaxReadLength);
        dest.writeInt(mFileId);
        dest.writeInt(mMaxSize);
        dest.writeInt(mReadAccess);
        dest.writeInt(mWriteAccess);
        dest.writeBoolean(mIsReadAllowed);
        dest.writeBoolean(mIsWriteAllowed);
    }

    /**
@@ -145,30 +132,6 @@ public final class T4tNdefNfceeCcFileInfo implements Parcelable {
        return mVersion;
    }

    /**
     * Indicates the max data size that can be read by a single invocation of
     * {@link T4tNdefNfcee#readData(int)}.
     *
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.4" MLe.
     * @return max size of read (in bytes).
     */
    @IntRange(from = 0xf, to = 0xffff)
    public int getMaxReadLength() {
        return mMaxReadLength;
    }

    /**
     * Indicates the max data size that can be written by a single invocation of
     * {@link T4tNdefNfcee#writeData(int, byte[])}
     *
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.4" MLc.
     * @return max size of write (in bytes).
     */
    @IntRange(from = 0xd, to = 0xffff)
    public int getMaxWriteLength() {
        return mMaxWriteLength;
    }

    /**
     * Indicates the NDEF File Identifier. This is the identifier used in the last invocation of
     * {@link T4tNdefNfcee#writeData(int, byte[])}
@@ -190,74 +153,22 @@ public final class T4tNdefNfceeCcFileInfo implements Parcelable {
        return mMaxSize;
    }

    /**
     * T4T tag read access granted without any security.
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details.
     */
    public static final int READ_ACCESS_GRANTED_UNRESTRICTED = 0x0;
    /**
     * T4T tag read access granted with limited proprietary access only.
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details.
     */
    public static final int READ_ACCESS_GRANTED_RESTRICTED = 0x80;

    /**
     * Possible return values for {@link #getVersion()}.
     * @hide
     */
    @IntDef(prefix = { "READ_ACCESS_GRANTED_" }, value = {
            READ_ACCESS_GRANTED_RESTRICTED,
            READ_ACCESS_GRANTED_UNRESTRICTED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ReadAccess {}

    /**
     * Indicates the read access condition.
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details.
     * @return read access restriction
     * @return boolean true if read access is allowed, otherwise false.
     */
    @ReadAccess
    public int getReadAccess() {
        return mReadAccess;
    public boolean isReadAllowed() {
        return mIsReadAllowed;
    }

    /**
     * T4T tag write access granted without any security.
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details.
     */
    public static final int WRITE_ACCESS_GRANTED_UNRESTRICTED = 0x0;
    /**
     * T4T tag write access granted with limited proprietary access only.
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details.
     */
    public static final int WRITE_ACCESS_GRANTED_RESTRICTED = 0x80;
    /**
     * T4T tag write access not granted.
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details.
     */
    public static final int WRITE_ACCESS_NOT_GRANTED = 0xFF;

    /**
     * Possible return values for {@link #getVersion()}.
     * @hide
     */
    @IntDef(prefix = { "READ_ACCESS_GRANTED_" }, value = {
            WRITE_ACCESS_GRANTED_RESTRICTED,
            WRITE_ACCESS_GRANTED_UNRESTRICTED,
            WRITE_ACCESS_NOT_GRANTED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface WriteAccess {}

    /**
     * Indicates the write access condition.
     * Refer to the NFC forum specification "NFCForum-TS-T4T-1.1 section 4.2" for more details.
     * @return write access restriction
     * @return boolean if write access is allowed, otherwise false.
     */
    @WriteAccess
    public int getWriteAccess() {
        return mWriteAccess;
    public boolean isWriteAllowed() {
        return mIsWriteAllowed;
    }

    @Override
@@ -273,16 +184,14 @@ public final class T4tNdefNfceeCcFileInfo implements Parcelable {
                    // NdefNfceeCcFileInfo fields
                    int cclen = in.readInt();
                    int version = in.readInt();
                    int maxLe = in.readInt();
                    int maxLc = in.readInt();
                    int ndefFileId = in.readInt();
                    int ndefMaxSize = in.readInt();
                    int ndefReadAccess = in.readInt();
                    int ndefWriteAccess = in.readInt();
                    boolean isReadAllowed = in.readBoolean();
                    boolean isWriteAllowed = in.readBoolean();

                    return new T4tNdefNfceeCcFileInfo(cclen, version, maxLe, maxLc,
                    return new T4tNdefNfceeCcFileInfo(cclen, version,
                            ndefFileId, ndefMaxSize,
                            ndefReadAccess, ndefWriteAccess);
                            isReadAllowed, isWriteAllowed);
                }

                @Override