diff options
| -rw-r--r-- | api/current.xml | 30 | ||||
| -rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 40 | ||||
| -rw-r--r-- | core/java/android/nfc/Tag.java | 9 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/BasicTagTechnology.java | 60 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/IsoDep.java | 10 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/MifareClassic.java | 2 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/MifareUltralight.java | 2 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/Ndef.java | 11 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/NdefFormatable.java | 7 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/NfcA.java | 2 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/NfcB.java | 2 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/NfcF.java | 2 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/NfcV.java | 2 |
13 files changed, 100 insertions, 79 deletions
diff --git a/api/current.xml b/api/current.xml index 85b367d6543c..34d0ee5ac028 100644 --- a/api/current.xml +++ b/api/current.xml @@ -100252,6 +100252,21 @@ visibility="public" > </method> +<method name="getTechnology" + return="android.nfc.technology.TagTechnology" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="tag" type="android.nfc.Tag"> +</parameter> +<parameter name="tech" type="int"> +</parameter> +</method> <method name="isEnabled" return="boolean" abstract="false" @@ -100399,21 +100414,6 @@ visibility="public" > </method> -<method name="getTechnology" - return="android.nfc.technology.TagTechnology" - abstract="false" - native="false" - synchronized="false" - static="false" - final="false" - deprecated="not deprecated" - visibility="public" -> -<parameter name="adapter" type="android.nfc.NfcAdapter"> -</parameter> -<parameter name="tech" type="int"> -</parameter> -</method> <method name="getTechnologyList" return="int[]" abstract="false" diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 2ea510552dd4..cfbe581d5518 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -22,6 +22,7 @@ import android.app.ActivityThread; import android.content.Context; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; +import android.nfc.technology.TagTechnology; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; @@ -194,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; @@ -232,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; } @@ -298,6 +306,14 @@ public final class NfcAdapter { } /** + * Returns the binder interface to the tag service. + * @hide + */ + public INfcTag getTagService() { + return sTagService; + } + + /** * NFC service dead - attempt best effort recovery * @hide */ @@ -306,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; } @@ -371,6 +397,16 @@ public final class NfcAdapter { } /** + * Retrieve a TagTechnology object used to interact with a Tag that is + * in field. + * <p> + * @return TagTechnology object, or null if not present + */ + public TagTechnology getTechnology(Tag tag, int tech) { + return tag.getTechnology(NfcAdapter.this, tech); + } + + /** * Set the NDEF Message that this NFC adapter should appear as to Tag * readers. * <p> diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java index 6cdd9f130497..7bd22891b7d5 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -45,7 +45,7 @@ import java.util.Arrays; * in {@link NfcAdapter#ACTION_TAG_DISCOVERED} intents. A {@link Tag} object is immutable * and represents the state of the tag at the time of discovery. It can be * directly queried for its UID and Type, or used to create a {@link TagTechnology} - * (with {@link Tag#getTechnology}). + * (with {@link NfcAdapter#getTechnology}). * <p> * A {@link Tag} can be used to create a {@link TagTechnology} only while the tag is in * range. If it is removed and then returned to range, then the most recent @@ -84,7 +84,7 @@ public class Tag implements Parcelable { /** * Construct a mock Tag. * <p>This is an application constructed tag, so NfcAdapter methods on this - * Tag such as {@link #getTechnology} may fail with + * Tag such as {@link NfcAdapter#getTechnology} may fail with * {@link IllegalArgumentException} since it does not represent a physical Tag. * <p>This constructor might be useful for mock testing. * @param id The tag identifier, can be null @@ -127,10 +127,7 @@ public class Tag implements Parcelable { return Arrays.copyOf(mTechList, mTechList.length); } - /** - * Returns the technology, or null if not present - */ - public TagTechnology getTechnology(NfcAdapter adapter, int tech) { + /*package*/ TagTechnology getTechnology(NfcAdapter adapter, int tech) { int pos = -1; for (int idx = 0; idx < mTechList.length; idx++) { if (mTechList[idx] == tech) { diff --git a/core/java/android/nfc/technology/BasicTagTechnology.java b/core/java/android/nfc/technology/BasicTagTechnology.java index bd0bc1e50f05..f529ee554ef9 100644 --- a/core/java/android/nfc/technology/BasicTagTechnology.java +++ b/core/java/android/nfc/technology/BasicTagTechnology.java @@ -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 @@ -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; } @@ -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. @@ -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; } } @@ -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"); } } @@ -183,21 +161,21 @@ 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()); + } + + try { + int errorCode = mTagService.reconnect(mTag.getServiceHandle()); - if (errorCode != ErrorCodes.SUCCESS) { - mIsConnected = false; - mTag.setTechnologyDisconnected(); - throw new IOException(); - } - } catch (RemoteException e) { + if (errorCode != ErrorCodes.SUCCESS) { mIsConnected = false; mTag.setTechnologyDisconnected(); - attemptDeadServiceRecovery(e); - throw new IOException("NFC service died"); + throw new IOException(); } + } catch (RemoteException e) { + mIsConnected = false; + mTag.setTechnologyDisconnected(); + Log.e(TAG, "NFC service dead", e); + throw new IOException("NFC service died"); } } @@ -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(); @@ -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"); } } diff --git a/core/java/android/nfc/technology/IsoDep.java b/core/java/android/nfc/technology/IsoDep.java index ff11eb2ec4a3..03c518e72a24 100644 --- a/core/java/android/nfc/technology/IsoDep.java +++ b/core/java/android/nfc/technology/IsoDep.java @@ -27,7 +27,7 @@ import java.io.IOException; * A low-level connection to a {@link Tag} using the ISO-DEP technology, also known as * ISO1443-4. * - * <p>You can acquire this kind of connection with {@link Tag#getTechnology}. + * <p>You can acquire this kind of connection with {@link NfcAdapter#getTechnology}. * Use this class to send and receive data with {@link #transceive transceive()}. * * <p>Applications must implement their own protocol stack on top of @@ -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; + } } diff --git a/core/java/android/nfc/technology/MifareClassic.java b/core/java/android/nfc/technology/MifareClassic.java index c5fb361a2ef2..3be38fe81860 100644 --- a/core/java/android/nfc/technology/MifareClassic.java +++ b/core/java/android/nfc/technology/MifareClassic.java @@ -74,7 +74,7 @@ public final class MifareClassic extends BasicTagTechnology { super(adapter, tag, TagTechnology.MIFARE_CLASSIC); // Check if this could actually be a Mifare - NfcA a = (NfcA) tag.getTechnology(adapter, TagTechnology.NFC_A); + NfcA a = (NfcA) adapter.getTechnology(tag, TagTechnology.NFC_A); //short[] ATQA = getATQA(tag); mIsEmulated = false; diff --git a/core/java/android/nfc/technology/MifareUltralight.java b/core/java/android/nfc/technology/MifareUltralight.java index e53061faf682..525b85bb8fca 100644 --- a/core/java/android/nfc/technology/MifareUltralight.java +++ b/core/java/android/nfc/technology/MifareUltralight.java @@ -47,7 +47,7 @@ public final class MifareUltralight extends BasicTagTechnology { super(adapter, tag, TagTechnology.MIFARE_ULTRALIGHT); // Check if this could actually be a Mifare - NfcA a = (NfcA) tag.getTechnology(adapter, TagTechnology.NFC_A); + NfcA a = (NfcA) adapter.getTechnology(tag, TagTechnology.NFC_A); mType = TYPE_UNKNOWN; diff --git a/core/java/android/nfc/technology/Ndef.java b/core/java/android/nfc/technology/Ndef.java index 3c08c84c85f2..457920f8e53d 100644 --- a/core/java/android/nfc/technology/Ndef.java +++ b/core/java/android/nfc/technology/Ndef.java @@ -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; @@ -31,13 +32,15 @@ import java.io.IOException; * to interact with NDEF data. MiFare Classic cards that present NDEF data may also be used * via this class. To determine the exact technology being used call {@link #getTechnologyId()} * - * <p>You can acquire this kind of connection with {@link Tag#getTechnology}. + * <p>You can acquire this kind of connection with {@link NfcAdapter#getTechnology}. * * <p class="note"><strong>Note:</strong> * Use of this class requires the {@link android.Manifest.permission#NFC} * permission. */ public final class Ndef extends BasicTagTechnology { + private static final String TAG = "NFC"; + /** @hide */ public static final int NDEF_MODE_READ_ONLY = 1; /** @hide */ @@ -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; } } @@ -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); } } @@ -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; } } diff --git a/core/java/android/nfc/technology/NdefFormatable.java b/core/java/android/nfc/technology/NdefFormatable.java index 7fa624fc3534..0901607ad1e8 100644 --- a/core/java/android/nfc/technology/NdefFormatable.java +++ b/core/java/android/nfc/technology/NdefFormatable.java @@ -23,19 +23,22 @@ import android.nfc.NfcAdapter; import android.nfc.Tag; import android.os.Bundle; import android.os.RemoteException; +import android.util.Log; import java.io.IOException; /** * An interface to a {@link Tag} allowing to format the tag as NDEF. * - * <p>You can acquire this kind of interface with {@link Tag#getTechnology}. + * <p>You can acquire this kind of interface with {@link NfcAdapter#getTechnology}. * * <p class="note"><strong>Note:</strong> * Use of this class requires the {@link android.Manifest.permission#NFC} * permission. */ public final class NdefFormatable extends BasicTagTechnology { + private static final String TAG = "NFC"; + /** * Internal constructor, to be used by NfcAdapter * @hide @@ -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); } } diff --git a/core/java/android/nfc/technology/NfcA.java b/core/java/android/nfc/technology/NfcA.java index 5cb8190b4fde..20fe09eb5187 100644 --- a/core/java/android/nfc/technology/NfcA.java +++ b/core/java/android/nfc/technology/NfcA.java @@ -25,7 +25,7 @@ import android.os.RemoteException; * A low-level connection to a {@link Tag} using the NFC-A technology, also known as * ISO1443-3A. * - * <p>You can acquire this kind of connection with {@link Tag#getTechnology}. + * <p>You can acquire this kind of connection with {@link NfcAdapter#getTechnology}. * Use this class to send and receive data with {@link #transceive transceive()}. * * <p>Applications must implement their own protocol stack on top of diff --git a/core/java/android/nfc/technology/NfcB.java b/core/java/android/nfc/technology/NfcB.java index dc9dd7a3d84f..767558ebf8a4 100644 --- a/core/java/android/nfc/technology/NfcB.java +++ b/core/java/android/nfc/technology/NfcB.java @@ -25,7 +25,7 @@ import android.os.RemoteException; * A low-level connection to a {@link Tag} using the NFC-B technology, also known as * ISO1443-3B. * - * <p>You can acquire this kind of connection with {@link Tag#getTechnology}. + * <p>You can acquire this kind of connection with {@link NfcAdapter#getTechnology}. * Use this class to send and receive data with {@link #transceive transceive()}. * * <p>Applications must implement their own protocol stack on top of diff --git a/core/java/android/nfc/technology/NfcF.java b/core/java/android/nfc/technology/NfcF.java index dd0e2f94fda2..f7f1fd3a9db7 100644 --- a/core/java/android/nfc/technology/NfcF.java +++ b/core/java/android/nfc/technology/NfcF.java @@ -25,7 +25,7 @@ import android.os.RemoteException; * A low-level connection to a {@link Tag} using the NFC-F technology, also known as * JIS6319-4. * - * <p>You can acquire this kind of connection with {@link Tag#getTechnology}. + * <p>You can acquire this kind of connection with {@link NfcAdapter#getTechnology}. * Use this class to send and receive data with {@link #transceive transceive()}. * * <p>Applications must implement their own protocol stack on top of diff --git a/core/java/android/nfc/technology/NfcV.java b/core/java/android/nfc/technology/NfcV.java index da73f5d01b17..4b51119b13e8 100644 --- a/core/java/android/nfc/technology/NfcV.java +++ b/core/java/android/nfc/technology/NfcV.java @@ -25,7 +25,7 @@ import android.os.RemoteException; * A low-level connection to a {@link Tag} using the NFC-V technology, also known as * ISO15693. * - * <p>You can acquire this kind of connection with {@link Tag#getTechnology}. + * <p>You can acquire this kind of connection with {@link NfcAdapter#getTechnology}. * Use this class to send and receive data with {@link #transceive transceive()}. * * <p>Applications must implement their own protocol stack on top of |