Add metrics for RF and EE Errors.

Adds metrics for RF as well as EE Protocol, Transmission, Timeout and
Activation errors.

Bug: 62586734
Test: inject errors and check logcat
Change-Id: I89046515b482360cd84d4e0d1113c4c45ceee5a7
diff --git a/src/Android.bp b/src/Android.bp
index d1f1860..669d63c 100644
--- a/src/Android.bp
+++ b/src/Android.bp
@@ -10,6 +10,7 @@
         "liblog",
         "libdl",
         "libhardware",
+        "libmetricslogger",
         "libpower",
 
         // Treble configuration
@@ -50,6 +51,7 @@
         "nfc/nci/*.c",
         "nfc/ndef/*.c",
         "nfc/nfc/*.c",
+        "nfc/nfc/*.cc",
         "nfc/tags/*.c",
         "adaptation/*.c",
         "adaptation/*.cpp",
diff --git a/src/nfc/include/nfc_api.h b/src/nfc/include/nfc_api.h
index 4f47ab8..83c582f 100644
--- a/src/nfc/include/nfc_api.h
+++ b/src/nfc/include/nfc_api.h
@@ -370,7 +370,11 @@
 #define NFC_RF_TECHNOLOGY_V NCI_RF_TECHNOLOGY_V
 typedef uint8_t tNFC_RF_TECH;
 
+#ifdef __cplusplus
+extern "C" uint8_t NFC_GetNCIVersion();
+#else
 extern uint8_t NFC_GetNCIVersion();
+#endif
 
 /* Supported Protocols */
 #define NFC_PROTOCOL_UNKNOWN NCI_PROTOCOL_UNKNOWN /* Unknown */
diff --git a/src/nfc/nfc/nfc_ncif.c b/src/nfc/nfc/nfc_ncif.cc
similarity index 97%
rename from src/nfc/nfc/nfc_ncif.c
rename to src/nfc/nfc/nfc_ncif.cc
index 164773b..1fa59b0 100644
--- a/src/nfc/nfc/nfc_ncif.c
+++ b/src/nfc/nfc/nfc_ncif.cc
@@ -23,6 +23,7 @@
  *  (callback). On the transmit side, it manages the command transmission.
  *
  ******************************************************************************/
+#include <metricslogger/metrics_logger.h>
 #include <stdlib.h>
 #include <string.h>
 #include "nfc_target.h"
@@ -34,7 +35,6 @@
 #include "nfc_int.h"
 #include "rw_api.h"
 #include "rw_int.h"
-
 #if (NFC_RW_ONLY == FALSE)
 static const uint8_t nfc_mpl_code_to_size[] = {64, 128, 192, 254};
 
@@ -465,6 +465,8 @@
 *******************************************************************************/
 void nfc_ncif_event_status(tNFC_RESPONSE_EVT event, uint8_t status) {
   tNFC_RESPONSE evt_data;
+  if (event == NFC_NFCC_TIMEOUT_REVT && status == NFC_STATUS_HW_TIMEOUT)
+    android::metricslogger::LogCounter("nfc_hw_timeout_error", 1);
   if (nfc_cb.p_resp_cback) {
     evt_data.status = (tNFC_STATUS)status;
     (*nfc_cb.p_resp_cback)(event, &evt_data);
@@ -487,6 +489,22 @@
   if (p_cb && p_cb->p_cback) {
     (*p_cb->p_cback)(conn_id, NFC_ERROR_CEVT, (tNFC_CONN*)&status);
   }
+  if (status == NFC_STATUS_TIMEOUT)
+    android::metricslogger::LogCounter("nfc_rf_timeout_error", 1);
+  else if (status == NFC_STATUS_EE_TIMEOUT)
+    android::metricslogger::LogCounter("nfc_ee_timeout_error", 1);
+  else if (status == NFC_STATUS_ACTIVATION_FAILED)
+    android::metricslogger::LogCounter("nfc_rf_activation_failed", 1);
+  else if (status == NFC_STATUS_EE_INTF_ACTIVE_FAIL)
+    android::metricslogger::LogCounter("nfc_ee_activation_failed", 1);
+  else if (status == NFC_STATUS_RF_TRANSMISSION_ERR)
+    android::metricslogger::LogCounter("nfc_rf_transmission_error", 1);
+  else if (status == NFC_STATUS_EE_TRANSMISSION_ERR)
+    android::metricslogger::LogCounter("nfc_ee_transmission_error", 1);
+  else if (status == NFC_STATUS_RF_PROTOCOL_ERR)
+    android::metricslogger::LogCounter("nfc_rf_protocol_error", 1);
+  else if (status == NFC_STATUS_EE_PROTOCOL_ERR)
+    android::metricslogger::LogCounter("nfc_ee_protocol_error", 1);
 }
 
 /*******************************************************************************