Merge "Do not let NFCC manage RF configuration when in reader mode"
diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp
index 7dae86f..a4ca039 100644
--- a/nci/jni/NativeNfcManager.cpp
+++ b/nci/jni/NativeNfcManager.cpp
@@ -83,6 +83,7 @@
 SyncEvent gDeactivatedEvent;
 SyncEvent sNfaSetPowerSubState;
 bool legacy_mfc_reader = true;
+bool gNfccConfigControlStatus = false;
 
 namespace android {
 jmethodID gCachedNfcManagerNotifyNdefMessageListeners;
@@ -1162,6 +1163,25 @@
   NfcAdaptation& theInstance = NfcAdaptation::GetInstance();
   theInstance.DeviceShutdown();
 }
+
+static void nfcManager_configNfccConfigControl(bool flag) {
+    // configure NFCC_CONFIG_CONTROL- NFCC allowed to manage RF configuration.
+    if (NFC_GetNCIVersion() != NCI_VERSION_1_0) {
+        uint8_t nfa_set_config[] = { 0x00 };
+
+        nfa_set_config[0] = (flag == true ? 1 : 0);
+        gNfccConfigControlStatus = flag;
+
+        tNFA_STATUS status = NFA_SetConfig(NCI_PARAM_ID_NFCC_CONFIG_CONTROL,
+                                           sizeof(nfa_set_config),
+                                           &nfa_set_config[0]);
+        if (status != NFA_STATUS_OK) {
+            LOG(ERROR) << __func__
+            << ": Failed to configure NFCC_CONFIG_CONTROL";
+        }
+    }
+}
+
 /*******************************************************************************
 **
 ** Function:        nfcManager_enableDiscovery
@@ -1228,11 +1248,21 @@
       if (reader_mode && !sReaderModeEnabled) {
         sReaderModeEnabled = true;
         NFA_DisableListening();
+
+        // configure NFCC_CONFIG_CONTROL- NFCC not allowed to manage RF configuration.
+        nfcManager_configNfccConfigControl(false);
+
         NFA_SetRfDiscoveryDuration(READER_MODE_DISCOVERY_DURATION);
       } else if (!reader_mode && sReaderModeEnabled) {
         struct nfc_jni_native_data* nat = getNative(e, o);
         sReaderModeEnabled = false;
         NFA_EnableListening();
+
+        // configure NFCC_CONFIG_CONTROL- NFCC allowed to manage RF configuration.
+        if(gNfccConfigControlStatus == false){
+            nfcManager_configNfccConfigControl(true);
+        }
+
         NFA_SetRfDiscoveryDuration(nat->discovery_duration);
       }
     }
@@ -2110,13 +2140,8 @@
   }
 
   // configure NFCC_CONFIG_CONTROL- NFCC allowed to manage RF configuration.
-  if (NFC_GetNCIVersion() != NCI_VERSION_1_0) {
-    uint8_t nfa_set_config[] = {0x01};
-    tNFA_STATUS status = NFA_SetConfig(NCI_PARAM_ID_NFCC_CONFIG_CONTROL,
-        sizeof(nfa_set_config), &nfa_set_config[0]);
-    if (status != NFA_STATUS_OK) {
-      LOG(ERROR) << __func__ << ": Failed to configure NFCC_CONFIG_CONTROL";
-    }
+  if(gNfccConfigControlStatus == false){
+      nfcManager_configNfccConfigControl(true);
   }
 }