From 1253ebc74a8453a88dc47a2b698145098d201681 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 24 Nov 2010 11:13:57 +0100 Subject: [PATCH] Fixed NfcAdapter init and getTechnology(). - GetTechnology() used a binary search, but the array was linked to another array (extras) which was not sorted. So made it linear. - The tag technologies were instantiated with a null NfcAdapter. Change-Id: Iae15169a89155c3a5c9f81824f809d6010ebac01 --- core/java/android/nfc/Tag.java | 13 +++++++++---- .../android/nfc/technology/BasicTagTechnology.java | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java index c3f0893c19af6..938e6a7d3cc66 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -71,7 +71,6 @@ public class Tag implements Parcelable { } mId = id; mTechList = Arrays.copyOf(techList, techList.length); - Arrays.sort(mTechList); // Ensure mTechExtras is as long as mTechList mTechExtras = Arrays.copyOf(techListExtras, techList.length); mServiceHandle = serviceHandle; @@ -122,13 +121,19 @@ public class Tag implements Parcelable { * Returns the technology, or null if not present */ public TagTechnology getTechnology(int tech) { - int pos = Arrays.binarySearch(mTechList, tech); + int pos = -1; + for (int idx = 0; idx < mTechList.length; idx++) { + if (mTechList[idx] == tech) { + pos = idx; + break; + } + } if (pos < 0) { return null; } Bundle extras = mTechExtras[pos]; - NfcAdapter adapter = null; + NfcAdapter adapter = NfcAdapter.getDefaultAdapter(); try { switch (tech) { case TagTechnology.NFC_A: { @@ -230,4 +235,4 @@ public class Tag implements Parcelable { return new Tag[size]; } }; -} \ No newline at end of file +} diff --git a/core/java/android/nfc/technology/BasicTagTechnology.java b/core/java/android/nfc/technology/BasicTagTechnology.java index cb586d50a74e9..6b281b9898a4b 100644 --- a/core/java/android/nfc/technology/BasicTagTechnology.java +++ b/core/java/android/nfc/technology/BasicTagTechnology.java @@ -63,7 +63,11 @@ import android.util.Log; mAdapter = adapter; mService = mAdapter.getService(); - mTagService = mService.getNfcTagInterface(); + try { + mTagService = mService.getNfcTagInterface(); + } catch (RemoteException e) { + attemptDeadServiceRecovery(e); + } mTag = tag; mSelectedTechnology = tech; }