Use the device type from saved properties instead of assuming default

DUMO device can do both BLE and BREDR operations. It was wrong
to assign BLE or BREDR type to it.
Bug: 18275230

Change-Id: I8d6c17e5157ba29a1af459629de9e2d6f6dc5e99
diff --git a/btif/include/btif_config.h b/btif/include/btif_config.h
index 75a1ac3..2a23a9c 100644
--- a/btif/include/btif_config.h
+++ b/btif/include/btif_config.h
@@ -27,6 +27,9 @@
 #ifndef BTIF_CONFIG_H
 #define BTIF_CONFIG_H
 
+#include "data_types.h"
+#include "bt_types.h"
+
 #ifdef __cplusplus
 #include <stdint.h>
 extern "C" {
@@ -71,6 +74,9 @@
 int btif_config_save();
 void btif_config_flush();
 
+BOOLEAN btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
+BOOLEAN btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/btif/include/btif_gatt_util.h b/btif/include/btif_gatt_util.h
index 87c263b..1898317 100644
--- a/btif/include/btif_gatt_util.h
+++ b/btif/include/btif_gatt_util.h
@@ -37,7 +37,5 @@
 
 void btif_gatt_check_encrypted_link(BD_ADDR bd_addr);
 
-BOOLEAN btif_get_device_type(BD_ADDR bd_addr, int *addr_type, int *device_type);
-
 #endif
 
diff --git a/btif/src/btif_config.c b/btif/src/btif_config.c
index 7b5ab07..629f4c6 100644
--- a/btif/src/btif_config.c
+++ b/btif/src/btif_config.c
@@ -44,6 +44,8 @@
 #define LOG_TAG "btif_config"
 
 #include <hardware/bluetooth.h>
+#include "data_types.h"
+#include "bd.h"
 #include "btif_api.h"
 #include "btif_config.h"
 #include "btif_config_util.h"
@@ -362,6 +364,46 @@
         save_cfg();
     unlock_slot(&slot_lock);
 }
+
+/*******************************************************************************
+ * Device information
+ *******************************************************************************/
+BOOLEAN btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
+{
+    if (p_device_type == NULL)
+        return FALSE;
+
+    bt_bdaddr_t bda;
+    bdcpy(bda.address, bd_addr);
+
+    char bd_addr_str[18] = {0};
+    bd2str(&bda, &bd_addr_str);
+
+    if (!btif_config_get_int("Remote", bd_addr_str, "DevType", p_device_type))
+        return FALSE;
+
+    ALOGD("%s: Device [%s] type %d", __FUNCTION__, bd_addr_str, *p_device_type);
+    return TRUE;
+}
+
+BOOLEAN btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type)
+{
+    if (p_addr_type == NULL)
+        return FALSE;
+
+    bt_bdaddr_t bda;
+    bdcpy(bda.address, bd_addr);
+
+    char bd_addr_str[18] = {0};
+    bd2str(&bda, &bd_addr_str);
+
+    if (!btif_config_get_int("Remote", bd_addr_str, "AddrType", p_addr_type))
+        return FALSE;
+
+    ALOGD("%s: Device [%s] address type %d", __FUNCTION__, bd_addr_str, *p_addr_type);
+    return TRUE;
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////////
 static inline short alloc_node(cfg_node* p, short grow)
 {
@@ -944,4 +986,6 @@
     // debug("after removed, btif_config_get ret:%d, Remote devices, 00:22:5F:97:56:04 Class Delete:%s", ret, class);
     // debug("out");
 }
+
+
 #endif
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
index c76880c..2957847 100644
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -801,10 +801,15 @@
     bt_bdname_t bd_name;
     UINT32 cod;
     bt_pin_code_t pin_code;
+    int dev_type;
 
     /* Remote properties update */
+    if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
+    {
+        dev_type = BT_DEVICE_TYPE_BREDR;
+    }
     btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
-                                  p_pin_req->dev_class, BT_DEVICE_TYPE_BREDR);
+                                  p_pin_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
 
     bdcpy(bd_addr.address, p_pin_req->bd_addr);
     memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
@@ -881,12 +886,17 @@
     bt_bdname_t bd_name;
     UINT32 cod;
     BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING);
+    int dev_type;
 
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
 
     /* Remote properties update */
+    if (!btif_get_device_type(p_ssp_cfm_req->bd_addr, &dev_type))
+    {
+        dev_type = BT_DEVICE_TYPE_BREDR;
+    }
     btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
-                                  p_ssp_cfm_req->dev_class, BT_DEVICE_TYPE_BREDR);
+                                  p_ssp_cfm_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
 
     bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr);
     memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN);
@@ -944,12 +954,17 @@
     bt_bdaddr_t bd_addr;
     bt_bdname_t bd_name;
     UINT32 cod;
+    int dev_type;
 
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
 
     /* Remote properties update */
+    if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
+    {
+        dev_type = BT_DEVICE_TYPE_BREDR;
+    }
     btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
-                                  p_ssp_key_notif->dev_class, BT_DEVICE_TYPE_BREDR);
+                                  p_ssp_key_notif->dev_class, (tBT_DEVICE_TYPE) dev_type);
 
     bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
     memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
@@ -2753,12 +2768,17 @@
     bt_bdaddr_t bd_addr;
     bt_bdname_t bd_name;
     UINT32 cod;
+    int dev_type;
 
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
 
     /* Remote name update */
-    btif_update_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
-                                          NULL, BT_DEVICE_TYPE_BLE);
+    if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
+    {
+        dev_type = BT_DEVICE_TYPE_BLE;
+    }
+    btif_dm_update_ble_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
+                                         (tBT_DEVICE_TYPE) dev_type);
     bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
     memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
 
@@ -2948,6 +2968,8 @@
     bt_bdaddr_t bd_addr;
     bt_bdname_t bd_name;
     UINT32 cod;
+    int dev_type;
+
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
 
     if (pairing_cb.state == BT_BOND_STATE_BONDING)
@@ -2957,7 +2979,12 @@
     }
 
     /* Remote name update */
-    btif_update_remote_properties(p_ble_req->bd_addr,p_ble_req->bd_name,NULL,BT_DEVICE_TYPE_BLE);
+    if (!btif_get_device_type(p_ble_req->bd_addr, &dev_type))
+    {
+        dev_type = BT_DEVICE_TYPE_BLE;
+    }
+    btif_dm_update_ble_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name,
+                                         (tBT_DEVICE_TYPE) dev_type);
 
     bdcpy(bd_addr.address, p_ble_req->bd_addr);
     memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN);
@@ -2990,9 +3017,15 @@
     bt_bdaddr_t bd_addr;
     bt_bdname_t bd_name;
     UINT32 cod;
+    int dev_type;
 
     /* Remote name update */
-    btif_update_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,NULL,BT_DEVICE_TYPE_BLE);
+    if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
+    {
+        dev_type = BT_DEVICE_TYPE_BLE;
+    }
+    btif_dm_update_ble_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,
+                                         (tBT_DEVICE_TYPE) dev_type);
 
     bdcpy(bd_addr.address, p_pin_req->bd_addr);
     memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c
index 5699649..3e0107f 100644
--- a/btif/src/btif_gatt_client.c
+++ b/btif/src/btif_gatt_client.c
@@ -1113,9 +1113,12 @@
             int device_type = 0;
             tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
 
-            if (btif_get_device_type(p_cb->bd_addr.address, &addr_type, &device_type) == TRUE
-                  && device_type != BT_DEVICE_TYPE_BREDR)
+            if (btif_get_address_type(p_cb->bd_addr.address, &addr_type) &&
+                btif_get_device_type(p_cb->bd_addr.address, &device_type) &&
+                device_type != BT_DEVICE_TYPE_BREDR)
+            {
                 BTA_DmAddBleDevice(p_cb->bd_addr.address, addr_type, device_type);
+            }
 
             // Mark background connections
             if (!p_cb->is_direct)
diff --git a/btif/src/btif_gatt_server.c b/btif/src/btif_gatt_server.c
index 503b5a3..86275a8 100644
--- a/btif/src/btif_gatt_server.c
+++ b/btif/src/btif_gatt_server.c
@@ -45,6 +45,7 @@
 #include "bd.h"
 #include "btif_dm.h"
 #include "btif_storage.h"
+#include "btif_config.h"
 
 #include "btif_gatt.h"
 #include "btif_gatt_util.h"
@@ -384,9 +385,12 @@
             int device_type = 0;
             tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
 
-            if (btif_get_device_type(p_cb->bd_addr.address, &addr_type, &device_type) == TRUE
-                  && device_type != BT_DEVICE_TYPE_BREDR)
+            if (btif_get_address_type(p_cb->bd_addr.address, &addr_type) &&
+                btif_get_device_type(p_cb->bd_addr.address, &device_type) &&
+                device_type != BT_DEVICE_TYPE_BREDR)
+            {
                 BTA_DmAddBleDevice(p_cb->bd_addr.address, addr_type, device_type);
+            }
 
             // Mark background connections
             if (!p_cb->is_direct)
diff --git a/btif/src/btif_gatt_util.c b/btif/src/btif_gatt_util.c
index 348bcea..001fb0b 100644
--- a/btif/src/btif_gatt_util.c
+++ b/btif/src/btif_gatt_util.c
@@ -30,13 +30,13 @@
 #include "bta_jv_api.h"
 #include "bd.h"
 #include "btif_storage.h"
+#include "btif_config.h"
 
 #include "btif_common.h"
 #include "btif_dm.h"
 #include "btif_util.h"
 #include "btif_gatt.h"
 #include "btif_gatt_util.h"
-#include "btif_config.h"
 
 #if BTA_GATT_INCLUDED == TRUE
 
@@ -311,7 +311,6 @@
     bt_bdaddr_t bda;
     bdcpy(bda.address, bd_addr);
     int device_type = 0;
-    int addr_type = 0;
 
 #if (!defined(BLE_DELAY_REQUEST_ENC) || (BLE_DELAY_REQUEST_ENC == FALSE))
     if ((btif_storage_get_ble_bonding_key(&bda, BTIF_DM_LE_KEY_PENC,
@@ -320,7 +319,7 @@
     {
         tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
 
-        btif_get_device_type(bd_addr, &addr_type, &device_type);
+        btif_get_device_type(bd_addr, &device_type);
         switch(device_type)
         {
             case BT_DEVICE_TYPE_BREDR:
@@ -345,29 +344,4 @@
 #endif
 }
 
-/*******************************************************************************
- * Device information
- *******************************************************************************/
-
-BOOLEAN btif_get_device_type(BD_ADDR bd_addr, int *addr_type, int *device_type)
-{
-    if (device_type == NULL || addr_type == NULL)
-        return FALSE;
-
-    bt_bdaddr_t bda;
-    bdcpy(bda.address, bd_addr);
-
-    char bd_addr_str[18] = {0};
-    bd2str(&bda, &bd_addr_str);
-
-    if (!btif_config_get_int("Remote", bd_addr_str, "DevType", device_type))
-        return FALSE;
-
-    if (!btif_config_get_int("Remote", bd_addr_str, "AddrType", addr_type))
-        return FALSE;
-
-    ALOGD("%s: Device [%s] type %d, addr. type %d", __FUNCTION__, bd_addr_str, *device_type, *addr_type);
-    return TRUE;
-}
-
 #endif
diff --git a/btif/src/btif_sock_util.c b/btif/src/btif_sock_util.c
index 42089ed..8e016e2 100644
--- a/btif/src/btif_sock_util.c
+++ b/btif/src/btif_sock_util.c
@@ -49,8 +49,6 @@
 #include "btif_common.h"
 #include "btif_util.h"
 
-#include "bd.h"
-
 #include "bta_api.h"
 #include "btif_sock_thread.h"
 #include "btif_sock_sdp.h"
diff --git a/btif/src/btif_util.c b/btif/src/btif_util.c
index bd376a6..b86c51a 100644
--- a/btif/src/btif_util.c
+++ b/btif/src/btif_util.c
@@ -51,8 +51,6 @@
 #include "bta_hf_client_api.h"
 #include "avrc_defs.h"
 
-
-
 /************************************************************************************
 **  Constants & Macros
 ************************************************************************************/
@@ -556,5 +554,3 @@
             return "Unknown PDU";
     }
 }
-
-