Fixed connect() failure from technology->ndef->technology.

Suppose you have a MifareClassic tag with NDEF; the following scenario failed
MifareClassic.connect()/close() -> Ndef.connect()/close() -> MifareClassic.connect() .

This last connect fails because the service refuses to connect any technology
on the same handle, except for NDEF. This check was too strict - it was only
intended to catch connecting to a NfcA technology on an IsoDep tag, as libNFC does not
support this. This change always allows connecting a tech on the same handle, except
when you want to connect a non-IsoDep technology on a tag that does have the IsoDep
technology on the same handle - in which case it refuses. This
matches exactly what libnfc supports.

Change-Id: I64d552b3cd51beb36712676492f36d182c605748
diff --git a/src/com/android/nfc/NativeNfcTag.java b/src/com/android/nfc/NativeNfcTag.java
index 002791e..1d05f25 100755
--- a/src/com/android/nfc/NativeNfcTag.java
+++ b/src/com/android/nfc/NativeNfcTag.java
@@ -151,9 +151,15 @@
                                 (technology == TagTechnology.NDEF_FORMATABLE)) {
                             isSuccess = true;
                         } else {
-                            // Don't allow to connect at a different level
-                            // on the same handle, not supported by libnfc!
-                            isSuccess = false;
+                            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.
+                                isSuccess = false;
+                            } else {
+                                isSuccess = true;
+                            }
                         }
                     }
                     if (isSuccess) {
@@ -454,6 +460,18 @@
       return hasTech;
     }
 
+    private boolean hasTechOnHandle(int tech, int handle) {
+      boolean hasTech = false;
+      for (int i = 0; i < mTechList.length; i++) {
+          if (mTechList[i] == tech && mTechHandles[i] == handle) {
+              hasTech = true;
+              break;
+          }
+      }
+      return hasTech;
+
+    }
+
     public Bundle[] getTechExtras() {
         synchronized (this) {
             if (mTechExtras != null) return mTechExtras;