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

Commit 3300e4c3 authored by Martijn Coenen's avatar Martijn Coenen Committed by Jeff Hamilton
Browse files

Implemented isWritable() to indicate NDEF capability container r/w state.

Change-Id: Ie8bdf490c955e620f5e5029346fbe2e188ea4748
parent ae56a851
Loading
Loading
Loading
Loading
+21 −31
Original line number Original line Diff line number Diff line
@@ -38,11 +38,12 @@ import java.io.IOException;
 * permission.
 * permission.
 */
 */
public final class Ndef extends BasicTagTechnology {
public final class Ndef extends BasicTagTechnology {
    public static final int NDEF_MODE_READ_ONCE = 1;
    /** @hide */
    public static final int NDEF_MODE_READ_ONLY = 2;
    public static final int NDEF_MODE_READ_ONLY = 1;
    public static final int NDEF_MODE_WRITE_ONCE = 3;
    /** @hide */
    public static final int NDEF_MODE_WRITE_MANY = 4;
    public static final int NDEF_MODE_READ_WRITE = 2;
    public static final int NDEF_MODE_UNKNOWN = 5;
    /** @hide */
    public static final int NDEF_MODE_UNKNOWN = 3;


    /** @hide */
    /** @hide */
    public static final String EXTRA_NDEF_MSG = "ndefmsg";
    public static final String EXTRA_NDEF_MSG = "ndefmsg";
@@ -50,7 +51,11 @@ public final class Ndef extends BasicTagTechnology {
    /** @hide */
    /** @hide */
    public static final String EXTRA_NDEF_MAXLENGTH = "ndefmaxlength";
    public static final String EXTRA_NDEF_MAXLENGTH = "ndefmaxlength";


    private final int maxNdefSize;
    /** @hide */
    public static final String EXTRA_NDEF_CARDSTATE = "ndefcardstate";

    private final int mMaxNdefSize;
    private final int mCardState;


    /**
    /**
     * Internal constructor, to be used by NfcAdapter
     * Internal constructor, to be used by NfcAdapter
@@ -59,10 +64,12 @@ public final class Ndef extends BasicTagTechnology {
    public Ndef(NfcAdapter adapter, Tag tag, int tech, Bundle extras) throws RemoteException {
    public Ndef(NfcAdapter adapter, Tag tag, int tech, Bundle extras) throws RemoteException {
        super(adapter, tag, tech);
        super(adapter, tag, tech);
        if (extras != null) {
        if (extras != null) {
            maxNdefSize = extras.getInt(EXTRA_NDEF_MAXLENGTH);
            mMaxNdefSize = extras.getInt(EXTRA_NDEF_MAXLENGTH);
            mCardState = extras.getInt(EXTRA_NDEF_CARDSTATE);
        } else {
        } else {
            maxNdefSize = 0;  //TODO: throw exception
            throw new NullPointerException("NDEF tech extras are null.");
        }
        }

    }
    }


    /**
    /**
@@ -104,35 +111,18 @@ public final class Ndef extends BasicTagTechnology {
    /**
    /**
     * Get maximum NDEF message size in bytes
     * Get maximum NDEF message size in bytes
     */
     */
    public int getSize() {
    public int getMaxSize() {
        return maxNdefSize;
        return mMaxNdefSize;
    }
    }


    /**
    /**
     * Read/Write mode hint.
     * Provides a hint on whether writes are likely to succeed.
     * Provides a hint if further reads or writes are likely to succeed.
     * <p>Requires {@link android.Manifest.permission#NFC} permission.
     * <p>Requires {@link android.Manifest.permission#NFC} permission.
     * @return one of NDEF_MODE
     * @return true if write is likely to succeed
     * @throws IOException if the target is lost or connection closed
     * @throws IOException if the target is lost or connection closed
     */
     */
    public int getModeHint() throws IOException {
    public boolean isWritable() {
        try {
        return (mCardState == NDEF_MODE_READ_WRITE);
            int result = mTagService.getModeHint(mTag.getServiceHandle());
            if (ErrorCodes.isError(result)) {
                switch (result) {
                    case ErrorCodes.ERROR_IO:
                        throw new IOException();
                    default:
                        // Should not happen
                        throw new IOException();
                }
            }
            return result;

        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            return NDEF_MODE_UNKNOWN;
        }
    }
    }


    // Methods that require connect()
    // Methods that require connect()