Loading core/java/android/nfc/NfcAdapter.java +27 −2 Original line number Diff line number Diff line Loading @@ -195,6 +195,7 @@ public final class NfcAdapter { // attemptDeadServiceRecovery() when NFC crashes - we accept a best effort // recovery private static INfcAdapter sService; private static INfcTag sTagService; private final Context mContext; Loading Loading @@ -233,6 +234,12 @@ public final class NfcAdapter { Log.e(TAG, "could not retrieve NFC service"); return null; } try { sTagService = sService.getNfcTagInterface(); } catch (RemoteException e) { Log.e(TAG, "could not retrieve NFC Tag service"); return null; } } return sService; } Loading Loading @@ -298,6 +305,14 @@ public final class NfcAdapter { return sService; } /** * Returns the binder interface to the tag service. * @hide */ public INfcTag getTagService() { return sTagService; } /** * NFC service dead - attempt best effort recovery * @hide Loading @@ -307,11 +322,21 @@ public final class NfcAdapter { INfcAdapter service = getServiceInterface(); if (service == null) { Log.e(TAG, "could not retrieve NFC service during service recovery"); // nothing more can be done now, sService is still stale, we'll hit // this recovery path again later return; } /* assigning to sService is not thread-safe, but this is best-effort code * and on a well-behaved system should never happen */ // assigning to sService is not thread-safe, but this is best-effort code // and on a well-behaved system should never happen sService = service; try { sTagService = service.getNfcTagInterface(); } catch (RemoteException ee) { Log.e(TAG, "could not retrieve NFC tag service during service recovery"); // nothing more can be done now, sService is still stale, we'll hit // this recovery path again later } return; } Loading core/java/android/nfc/technology/BasicTagTechnology.java +19 −41 Original line number Diff line number Diff line Loading @@ -30,19 +30,14 @@ import android.util.Log; * A base class for tag technologies that are built on top of transceive(). */ /* package */ abstract class BasicTagTechnology implements TagTechnology { private static final String TAG = "NFC"; /*package*/ final Tag mTag; /*package*/ boolean mIsConnected; /*package*/ int mSelectedTechnology; private final NfcAdapter mAdapter; // Following fields are final after construction, except for // during attemptDeadServiceRecovery() when NFC crashes. // Not locked - we accept a best effort attempt when NFC crashes. /*package*/ INfcAdapter mService; /*package*/ INfcTag mTagService; private static final String TAG = "NFC"; /*package*/ final INfcAdapter mService; /*package*/ final INfcTag mTagService; /** * @hide Loading @@ -64,11 +59,7 @@ import android.util.Log; mAdapter = adapter; mService = mAdapter.getService(); try { mTagService = mService.getNfcTagInterface(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); } mTagService = mAdapter.getTagService(); mTag = tag; mSelectedTechnology = tech; } Loading @@ -80,19 +71,6 @@ import android.util.Log; this(adapter, tag, tag.getTechnologyList()[0]); } /** NFC service dead - attempt best effort recovery */ /*package*/ void attemptDeadServiceRecovery(Exception e) { mAdapter.attemptDeadServiceRecovery(e); /* assigning to mService is not thread-safe, but this is best-effort code * and on a well-behaved system should never happen */ mService = mAdapter.getService(); try { mTagService = mService.getNfcTagInterface(); } catch (RemoteException e2) { Log.e(TAG, "second RemoteException trying to recover from dead NFC service", e2); } } /** * Get the {@link Tag} this connection is associated with. * <p>Requires {@link android.Manifest.permission#NFC} permission. Loading Loading @@ -135,7 +113,7 @@ import android.util.Log; try { return mTagService.isPresent(mTag.getServiceHandle()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); return false; } } Loading Loading @@ -163,7 +141,7 @@ import android.util.Log; throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); throw new IOException("NFC service died"); } } Loading @@ -183,7 +161,8 @@ import android.util.Log; public void reconnect() throws IOException { if (!mIsConnected) { throw new IllegalStateException("Technology not connected yet"); } else { } try { int errorCode = mTagService.reconnect(mTag.getServiceHandle()); Loading @@ -195,11 +174,10 @@ import android.util.Log; } catch (RemoteException e) { mIsConnected = false; mTag.setTechnologyDisconnected(); attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); throw new IOException("NFC service died"); } } } /** * Close this connection. Loading @@ -219,7 +197,7 @@ import android.util.Log; */ mTagService.reconnect(mTag.getServiceHandle()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); } finally { mIsConnected = false; mTag.setTechnologyDisconnected(); Loading @@ -237,7 +215,7 @@ import android.util.Log; } return response; } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); throw new IOException("NFC service died"); } } Loading core/java/android/nfc/technology/IsoDep.java +6 −2 Original line number Diff line number Diff line Loading @@ -58,10 +58,14 @@ public final class IsoDep extends BasicTagTechnology { /** * 3A only */ public byte[] getHistoricalBytes() { return mHistBytes; } public byte[] getHistoricalBytes() { return mHistBytes; } /** * 3B only */ public byte[] getHiLayerResponse() { return mHiLayerResponse; } public byte[] getHiLayerResponse() { return mHiLayerResponse; } } core/java/android/nfc/technology/Ndef.java +6 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.nfc.NfcAdapter; import android.nfc.Tag; import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import java.io.IOException; Loading @@ -38,6 +39,8 @@ import java.io.IOException; * permission. */ public final class Ndef extends BasicTagTechnology { private static final String TAG = "NFC"; /** @hide */ public static final int NDEF_MODE_READ_ONLY = 1; /** @hide */ Loading Loading @@ -168,7 +171,7 @@ public final class Ndef extends BasicTagTechnology { return null; } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); return null; } } Loading Loading @@ -200,7 +203,7 @@ public final class Ndef extends BasicTagTechnology { throw new IOException("Tag is not ndef"); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); } } Loading Loading @@ -241,7 +244,7 @@ public final class Ndef extends BasicTagTechnology { throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); return false; } } Loading core/java/android/nfc/technology/NdefFormatable.java +4 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.nfc.NfcAdapter; import android.nfc.Tag; import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import java.io.IOException; Loading @@ -36,6 +37,8 @@ import java.io.IOException; * permission. */ public final class NdefFormatable extends BasicTagTechnology { private static final String TAG = "NFC"; /** * Internal constructor, to be used by NfcAdapter * @hide Loading Loading @@ -85,7 +88,7 @@ public final class NdefFormatable extends BasicTagTechnology { throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); } } Loading Loading
core/java/android/nfc/NfcAdapter.java +27 −2 Original line number Diff line number Diff line Loading @@ -195,6 +195,7 @@ public final class NfcAdapter { // attemptDeadServiceRecovery() when NFC crashes - we accept a best effort // recovery private static INfcAdapter sService; private static INfcTag sTagService; private final Context mContext; Loading Loading @@ -233,6 +234,12 @@ public final class NfcAdapter { Log.e(TAG, "could not retrieve NFC service"); return null; } try { sTagService = sService.getNfcTagInterface(); } catch (RemoteException e) { Log.e(TAG, "could not retrieve NFC Tag service"); return null; } } return sService; } Loading Loading @@ -298,6 +305,14 @@ public final class NfcAdapter { return sService; } /** * Returns the binder interface to the tag service. * @hide */ public INfcTag getTagService() { return sTagService; } /** * NFC service dead - attempt best effort recovery * @hide Loading @@ -307,11 +322,21 @@ public final class NfcAdapter { INfcAdapter service = getServiceInterface(); if (service == null) { Log.e(TAG, "could not retrieve NFC service during service recovery"); // nothing more can be done now, sService is still stale, we'll hit // this recovery path again later return; } /* assigning to sService is not thread-safe, but this is best-effort code * and on a well-behaved system should never happen */ // assigning to sService is not thread-safe, but this is best-effort code // and on a well-behaved system should never happen sService = service; try { sTagService = service.getNfcTagInterface(); } catch (RemoteException ee) { Log.e(TAG, "could not retrieve NFC tag service during service recovery"); // nothing more can be done now, sService is still stale, we'll hit // this recovery path again later } return; } Loading
core/java/android/nfc/technology/BasicTagTechnology.java +19 −41 Original line number Diff line number Diff line Loading @@ -30,19 +30,14 @@ import android.util.Log; * A base class for tag technologies that are built on top of transceive(). */ /* package */ abstract class BasicTagTechnology implements TagTechnology { private static final String TAG = "NFC"; /*package*/ final Tag mTag; /*package*/ boolean mIsConnected; /*package*/ int mSelectedTechnology; private final NfcAdapter mAdapter; // Following fields are final after construction, except for // during attemptDeadServiceRecovery() when NFC crashes. // Not locked - we accept a best effort attempt when NFC crashes. /*package*/ INfcAdapter mService; /*package*/ INfcTag mTagService; private static final String TAG = "NFC"; /*package*/ final INfcAdapter mService; /*package*/ final INfcTag mTagService; /** * @hide Loading @@ -64,11 +59,7 @@ import android.util.Log; mAdapter = adapter; mService = mAdapter.getService(); try { mTagService = mService.getNfcTagInterface(); } catch (RemoteException e) { attemptDeadServiceRecovery(e); } mTagService = mAdapter.getTagService(); mTag = tag; mSelectedTechnology = tech; } Loading @@ -80,19 +71,6 @@ import android.util.Log; this(adapter, tag, tag.getTechnologyList()[0]); } /** NFC service dead - attempt best effort recovery */ /*package*/ void attemptDeadServiceRecovery(Exception e) { mAdapter.attemptDeadServiceRecovery(e); /* assigning to mService is not thread-safe, but this is best-effort code * and on a well-behaved system should never happen */ mService = mAdapter.getService(); try { mTagService = mService.getNfcTagInterface(); } catch (RemoteException e2) { Log.e(TAG, "second RemoteException trying to recover from dead NFC service", e2); } } /** * Get the {@link Tag} this connection is associated with. * <p>Requires {@link android.Manifest.permission#NFC} permission. Loading Loading @@ -135,7 +113,7 @@ import android.util.Log; try { return mTagService.isPresent(mTag.getServiceHandle()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); return false; } } Loading Loading @@ -163,7 +141,7 @@ import android.util.Log; throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); throw new IOException("NFC service died"); } } Loading @@ -183,7 +161,8 @@ import android.util.Log; public void reconnect() throws IOException { if (!mIsConnected) { throw new IllegalStateException("Technology not connected yet"); } else { } try { int errorCode = mTagService.reconnect(mTag.getServiceHandle()); Loading @@ -195,11 +174,10 @@ import android.util.Log; } catch (RemoteException e) { mIsConnected = false; mTag.setTechnologyDisconnected(); attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); throw new IOException("NFC service died"); } } } /** * Close this connection. Loading @@ -219,7 +197,7 @@ import android.util.Log; */ mTagService.reconnect(mTag.getServiceHandle()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); } finally { mIsConnected = false; mTag.setTechnologyDisconnected(); Loading @@ -237,7 +215,7 @@ import android.util.Log; } return response; } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); throw new IOException("NFC service died"); } } Loading
core/java/android/nfc/technology/IsoDep.java +6 −2 Original line number Diff line number Diff line Loading @@ -58,10 +58,14 @@ public final class IsoDep extends BasicTagTechnology { /** * 3A only */ public byte[] getHistoricalBytes() { return mHistBytes; } public byte[] getHistoricalBytes() { return mHistBytes; } /** * 3B only */ public byte[] getHiLayerResponse() { return mHiLayerResponse; } public byte[] getHiLayerResponse() { return mHiLayerResponse; } }
core/java/android/nfc/technology/Ndef.java +6 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.nfc.NfcAdapter; import android.nfc.Tag; import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import java.io.IOException; Loading @@ -38,6 +39,8 @@ import java.io.IOException; * permission. */ public final class Ndef extends BasicTagTechnology { private static final String TAG = "NFC"; /** @hide */ public static final int NDEF_MODE_READ_ONLY = 1; /** @hide */ Loading Loading @@ -168,7 +171,7 @@ public final class Ndef extends BasicTagTechnology { return null; } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); return null; } } Loading Loading @@ -200,7 +203,7 @@ public final class Ndef extends BasicTagTechnology { throw new IOException("Tag is not ndef"); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); } } Loading Loading @@ -241,7 +244,7 @@ public final class Ndef extends BasicTagTechnology { throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); return false; } } Loading
core/java/android/nfc/technology/NdefFormatable.java +4 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.nfc.NfcAdapter; import android.nfc.Tag; import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import java.io.IOException; Loading @@ -36,6 +37,8 @@ import java.io.IOException; * permission. */ public final class NdefFormatable extends BasicTagTechnology { private static final String TAG = "NFC"; /** * Internal constructor, to be used by NfcAdapter * @hide Loading Loading @@ -85,7 +88,7 @@ public final class NdefFormatable extends BasicTagTechnology { throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); Log.e(TAG, "NFC service dead", e); } } Loading