Do not disconnect P2P target if connect failed.

If the P2P target connect failed, the P2P target disconnect cannot be done.
However the polling loop must be restarted. This is already done in JNI layer
by the failing connect itself.

Change-Id: I1c3323e4c038c8133e7b6e16b3a238c050427cfc
diff --git a/jni/com_android_nfc_NativeP2pDevice.cpp b/jni/com_android_nfc_NativeP2pDevice.cpp
index fc2692b..fd9af3e 100644
--- a/jni/com_android_nfc_NativeP2pDevice.cpp
+++ b/jni/com_android_nfc_NativeP2pDevice.cpp
@@ -145,7 +145,6 @@
     if(status != NFCSTATUS_PENDING)
     {
       LOGE("phLibNfc_RemoteDev_Connect(P2P) returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
-      nfc_jni_restart_discovery_locked(nfc_jni_get_nat_ext(e));
       goto clean_and_return;
     }
     TRACE("phLibNfc_RemoteDev_Connect(P2P) returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
@@ -185,6 +184,11 @@
     result = JNI_TRUE;
 
 clean_and_return:
+    if (result != JNI_TRUE)
+    {
+       /* Restart the polling loop if the connection failed */
+       nfc_jni_restart_discovery_locked(nfc_jni_get_nat_ext(e));
+    }
     nfc_cb_data_deinit(&cb_data);
     CONCURRENCY_UNLOCK();
     return result;
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index 9dd8436..d91c41c 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -2377,8 +2377,8 @@
                            device.doDisconnect();
                        }
                    } else {
-                       if (DBG) Log.d(TAG, "Cannot connect remote Target. Restart polling loop.");
-                       device.doDisconnect();
+                       if (DBG) Log.d(TAG, "Cannot connect remote Target. Polling loop restarted...");
+                       /* The polling loop should have been restarted in failing doConnect */
                    }
 
                } else if (device.getMode() == NativeP2pDevice.MODE_P2P_INITIATOR) {