public synchronized int connectWithStatus(int technology) { if (mWatchdog != null) { mWatchdog.pause(); } int status = -1; for (int i = 0; i < mTechList.length; i++) { if (mTechList[i] == technology) { // Get the handle and connect, if not already connected if (mConnectedHandle != mTechHandles[i]) { // We're not yet connected to this handle, there are // a few scenario's here: // 1) We are not connected to anything yet - allow // 2) We are connected to a technology which has // a different handle (multi-protocol tag); we support // switching to that. if (mConnectedHandle == -1) { // Not connected yet status = doConnect(mTechHandles[i]); } else { // Connect to a tech with a different handle status = reconnectWithStatus(mTechHandles[i]); } if (status == 0) { mConnectedHandle = mTechHandles[i]; mConnectedTechIndex = i; } } else { // 1) We are connected to a technology which has the same // handle; we do not support connecting at a different // level (libnfc auto-activates to the max level on // any handle). // 2) We are connecting to the ndef technology - always // allowed. if ((technology == TagTechnology.NDEF) || (technology == TagTechnology.NDEF_FORMATABLE)) { status = 0; } else { if ((technology != TagTechnology.ISO_DEP) && (hasTechOnHandle(TagTechnology.ISO_DEP, mTechHandles[i]))) { // Don't allow to connect a -4 tag at a different level // than IsoDep, as this is not supported by // libNFC. status = -1; } else { status = 0; } } if (status == 0) { mConnectedTechIndex = i; // Handle was already identical } } break; } } if (mWatchdog != null) { mWatchdog.doResume(); } return status; }
private synchronized int checkNdefWithStatus(int[] ndefinfo) { if (mWatchdog != null) { mWatchdog.pause(); } int status = doCheckNdef(ndefinfo); if (mWatchdog != null) { mWatchdog.doResume(); } return status; }
public synchronized int reconnectWithStatus(int handle) { if (mWatchdog != null) { mWatchdog.pause(); } int status = doHandleReconnect(handle); if (mWatchdog != null) { mWatchdog.doResume(); } return status; }
@Override public synchronized boolean makeReadOnly() { if (mWatchdog != null) { mWatchdog.pause(); } boolean result = doMakeReadonly(); if (mWatchdog != null) { mWatchdog.doResume(); } return result; }
@Override public synchronized boolean formatNdef(byte[] key) { if (mWatchdog != null) { mWatchdog.pause(); } boolean result = doNdefFormat(key); if (mWatchdog != null) { mWatchdog.doResume(); } return result; }
@Override public synchronized boolean presenceCheck() { if (mWatchdog != null) { mWatchdog.pause(); } boolean result = doPresenceCheck(); if (mWatchdog != null) { mWatchdog.doResume(); } return result; }
@Override public synchronized boolean writeNdef(byte[] buf) { if (mWatchdog != null) { mWatchdog.pause(); } boolean result = doWrite(buf); if (mWatchdog != null) { mWatchdog.doResume(); } return result; }
@Override public synchronized byte[] readNdef() { if (mWatchdog != null) { mWatchdog.pause(); } byte[] result = doRead(); if (mWatchdog != null) { mWatchdog.doResume(); } return result; }
@Override public synchronized byte[] transceive(byte[] data, boolean raw, int[] returnCode) { if (mWatchdog != null) { mWatchdog.pause(); } byte[] result = doTransceive(data, raw, returnCode); if (mWatchdog != null) { mWatchdog.doResume(); } return result; }
@Override public synchronized void startPresenceChecking() { // Once we start presence checking, we allow the upper layers // to know the tag is in the field. mIsPresent = true; if (mWatchdog == null) { mWatchdog = new PresenceCheckWatchdog(); mWatchdog.start(); } }
@Override public synchronized boolean disconnect() { boolean result = false; mIsPresent = false; if (mWatchdog != null) { // Watchdog has already disconnected or will do it mWatchdog.end(); try { mWatchdog.join(); } catch (InterruptedException e) { // Should never happen. } mWatchdog = null; result = true; } else { result = doDisconnect(); } mConnectedTechIndex = -1; mConnectedHandle = -1; return result; }