DO NOT MERGE Bluetooth: Cleanup bt_config.xml during BLE Scan

BLE Scan needs to clean up the bt_config.xml periodically so that
new entries could be added to bt_config.xml. Also, there is no
need to add BLE Random bd_addr to the bt_config.xml

Change-Id: I00ba2e50dd39a021099052cb569786f6cb2cc8b9

b/12912008
(cherry picked from commit 377cb1407ee6ee1ff91b15bfa7052abed1023d18)

Change-Id: I3fa0286c96782822a8fdac14b05bbb6f98636e50
diff --git a/btif/include/btif_storage.h b/btif/include/btif_storage.h
index 41507fb..951b376 100644
--- a/btif/include/btif_storage.h
+++ b/btif/include/btif_storage.h
@@ -30,6 +30,7 @@
 #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \
          (p_prop)->type = t;(p_prop)->len = l; (p_prop)->val = (p_v);
 
+#define  BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE 512
 
 /*******************************************************************************
 **  Functions
diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c
index ce51ce2..d9d0e3a 100644
--- a/btif/src/btif_gatt_client.c
+++ b/btif/src/btif_gatt_client.c
@@ -463,10 +463,31 @@
         case BTIF_GATT_OBSERVE_EVT:
         {
             btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t*)p_param;
-            if (!btif_gattc_find_bdaddr(p_btif_cb->bd_addr.address))
+            uint8_t remote_name_len;
+            uint8_t *p_eir_remote_name=NULL;
+
+            p_eir_remote_name = BTA_CheckEirData(p_btif_cb->value,
+                                         BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
+
+            if(p_eir_remote_name == NULL)
             {
-                btif_gattc_add_remote_bdaddr(p_btif_cb->bd_addr.address, p_btif_cb->addr_type);
-                btif_gattc_update_properties(p_btif_cb);
+                p_eir_remote_name = BTA_CheckEirData(p_btif_cb->value,
+                                BT_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
+            }
+
+            if ((p_btif_cb->addr_type != BLE_ADDR_RANDOM) || (p_eir_remote_name))
+            {
+               if (!btif_gattc_find_bdaddr(p_btif_cb->bd_addr.address))
+               {
+                  static const char* exclude_filter[] =
+                        {"LinkKey", "LE_KEY_PENC", "LE_KEY_PID", "LE_KEY_PCSRK", "LE_KEY_LENC", "LE_KEY_LCSRK"};
+
+                  btif_gattc_add_remote_bdaddr(p_btif_cb->bd_addr.address, p_btif_cb->addr_type);
+                  btif_gattc_update_properties(p_btif_cb);
+                  btif_config_filter_remove("Remote", exclude_filter, sizeof(exclude_filter)/sizeof(char*),
+                  BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE);
+               }
+
             }
             HAL_CBACK(bt_gatt_callbacks, client->scan_result_cb,
                       &p_btif_cb->bd_addr, p_btif_cb->rssi, p_btif_cb->value);
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index 86b1521..284488d 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -38,7 +38,7 @@
 #define LOG_TAG "BTIF_STORAGE"
 
 #include "btif_api.h"
-
+#include "btif_storage.h"
 #include "btif_util.h"
 #include "bd.h"
 #include "gki.h"
@@ -150,7 +150,6 @@
 #define BTIF_STORAGE_HL_APP_DATA     "hl_app_data_"
 #define BTIF_STORAGE_HL_APP_MDL_DATA "hl_app_mdl_data_"
 
-#define  BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE 512
 /************************************************************************************
 **  Local type definitions
 ************************************************************************************/