LE Audio: Improve LE Audio device detection.

When user enters "pair new device" screen in settings, stack would
restart inquiry session every 10 seconds.
On each restart, we forget the device types in BTM layer for devices
without security record.
For LE Audio devices, this meant that if user clicked on it after
inquiry was restarted, but before some advertisement was received,
wrong transport would be used.
This patch fixes that, by using device type from BTIF layer, which is
persistent between inquiry restarts.

Bug: 317284831
Bug: 319511584
Test: Put LE Audio capable device into discoverable mode, then power it
off. Wait more than 10 seconds and click on it in Android settings.
Observe which transport was selected for connection attempt.

Change-Id: I2689ab373db33bd477ac2a096d478437979035fb
diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc
index 1edb465..9ba5f40 100644
--- a/system/btif/src/btif_dm.cc
+++ b/system/btif/src/btif_dm.cc
@@ -51,6 +51,7 @@
 #include <optional>
 
 #include "advertise_data_parser.h"
+#include "android_bluetooth_flags.h"
 #include "bta/dm/bta_dm_disc.h"
 #include "bta/include/bta_api.h"
 #include "btif/include/stack_manager_t.h"
@@ -748,6 +749,18 @@
     return false;
   }
 
+  /* First try reading device type from BTIF - it persists over multiple
+   * inquiry sessions */
+  int dev_type = 0;
+  if (IS_FLAG_ENABLED(le_audio_dev_type_detection_fix) &&
+      (btif_get_device_type(bd_addr, &dev_type) &&
+       (dev_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE)) {
+    /* LE Audio capable device is discoverable over both LE and Classic using
+     * same address. Prefer to use LE transport, as we don't know if it can do
+     * CTKD from Classic to LE */
+    return true;
+  }
+
   tBT_DEVICE_TYPE tmp_dev_type;
   tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
   BTM_ReadDevInfo(bd_addr, &tmp_dev_type, &addr_type);