Fix RF field stuck on race condition.

If we deactivate a tag to sleep after an NDEF check,
we're waiting for a DEACTIVATE_NTF event from the core
stack to unblock us. However, there is a
code path where we can be unblocked even without a
DEACTIVATE_NTF event. If you'd happen to remove the tag
right after the deactivation, we'd be getting read/write
interface errors, which erroneously unblock the deactivate
before it has been completed.

Then, we send another deactive command to go back to discovery.
However, because the previous deactivate is still pending, the
deactivate to discovery command gets dropped, and we stay in
a situation where the RF field is stuck on, burning power.

For now fix by adding RW_INTF_ERROR_EVTs to the list of events
that do not unblock a thread waiting on deactivate. Ideally
no other event is allowed to unblock, but we'll need more time
to verify that is actually true.

Bug: 8616351
Change-Id: I381046f0320fd4b31c5ec65d54ef2e9530c3b13c
diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp
index b1199f9..ccee293 100755
--- a/nci/jni/NativeNfcManager.cpp
+++ b/nci/jni/NativeNfcManager.cpp
@@ -210,7 +210,13 @@
     tNFA_STATUS status = NFA_STATUS_FAILED;
     ALOGD("%s: event= %u", __FUNCTION__, connEvent);
 
-    if (gIsTagDeactivating && connEvent != NFA_DEACTIVATED_EVT && connEvent != NFA_PRESENCE_CHECK_EVT && connEvent != NFA_DATA_EVT)
+    // TODO this if can probably be completely removed. It's unclear why this
+    // was present in the initial code drop - either to work around NFCC,
+    // stack or certain NFC tags bugs. Until we verify removing it doesn't
+    // break things, leave it be.
+    if (gIsTagDeactivating && connEvent != NFA_DEACTIVATED_EVT &&
+            connEvent != NFA_PRESENCE_CHECK_EVT && connEvent != NFA_DATA_EVT &&
+            connEvent != NFA_RW_INTF_ERROR_EVT)
     {
         // special case to switching frame interface for ISO_DEP tags
         gIsTagDeactivating = false;