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

Commit 23fc93a7 authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Fix NPE on mock NDEF tech operations.

Change-Id: Ib67bd03b6275fdb86a5d6dedc6c7e4fed07ef8b0
parent da7923ac
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ public final class Tag implements Parcelable {
    /*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;
    /*package*/ final INfcTag mTagService; // interface to NFC service, will be null if mock tag

    /*package*/ int mConnectedTechnology;

@@ -148,7 +148,7 @@ public final class Tag implements Parcelable {
     * @hide
     */
    public static Tag createMockTag(byte[] id, int[] techList, Bundle[] techListExtras) {
        // set serviceHandle to 0 to indicate mock tag
        // set serviceHandle to 0 and tagService to null to indicate mock tag
        return new Tag(id, techList, techListExtras, 0, null);
    }

@@ -266,6 +266,9 @@ public final class Tag implements Parcelable {
            throw new IllegalStateException("Close connection to the technology first!");
        }

        if (mTagService == null) {
            throw new IOException("Mock tags don't support this operation.");
        }
        try {
            Tag newTag = mTagService.rediscover(getServiceHandle());
            if (newTag != null) {
+12 −0
Original line number Diff line number Diff line
@@ -259,6 +259,9 @@ public final class Ndef extends BasicTagTechnology {

        try {
            INfcTag tagService = mTag.getTagService();
            if (tagService == null) {
                throw new IOException("Mock tags don't support this operation.");
            }
            int serviceHandle = mTag.getServiceHandle();
            if (tagService.isNdef(serviceHandle)) {
                NdefMessage msg = tagService.ndefRead(serviceHandle);
@@ -303,6 +306,9 @@ public final class Ndef extends BasicTagTechnology {

        try {
            INfcTag tagService = mTag.getTagService();
            if (tagService == null) {
                throw new IOException("Mock tags don't support this operation.");
            }
            int serviceHandle = mTag.getServiceHandle();
            if (tagService.isNdef(serviceHandle)) {
                int errorCode = tagService.ndefWrite(serviceHandle, msg);
@@ -335,6 +341,9 @@ public final class Ndef extends BasicTagTechnology {
     */
    public boolean canMakeReadOnly() {
        INfcTag tagService = mTag.getTagService();
        if (tagService == null) {
            return false;
        }
        try {
            return tagService.canMakeReadOnly(mNdefType);
        } catch (RemoteException e) {
@@ -366,6 +375,9 @@ public final class Ndef extends BasicTagTechnology {

        try {
            INfcTag tagService = mTag.getTagService();
            if (tagService == null) {
                return false;
            }
            if (tagService.isNdef(mTag.getServiceHandle())) {
                int errorCode = tagService.ndefMakeReadOnly(mTag.getServiceHandle());
                switch (errorCode) {