From ad8fba09accd6909e6678b8c9820732f36588401 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Fri, 31 Jul 2020 19:44:27 -0700 Subject: Check whether local device is an ATV device to determine whether to show the consent dialog for BLE pairing in JUSTWORKS and ENCRYPTION_ONLY mode Tag: #feature Bug: 157038281 Test: Manual Merged-In: I6d06f5996da71e5a1407e544b0023d82924aa56f Change-Id: I6d06f5996da71e5a1407e544b0023d82924aa56f --- btif/include/btif_api.h | 12 ++++++++++++ btif/src/bluetooth.cc | 6 +++++- include/hardware/bluetooth.h | 3 ++- service/hal/bluetooth_interface.cc | 2 +- stack/smp/smp_act.cc | 11 +++++++---- test/suite/adapter/adapter_unittest.cc | 2 +- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/btif/include/btif_api.h b/btif/include/btif_api.h index 519fc9cda..1f04d7cd3 100644 --- a/btif/include/btif_api.h +++ b/btif/include/btif_api.h @@ -103,6 +103,18 @@ bt_status_t btif_cleanup_bluetooth(void); ******************************************************************************/ bool is_restricted_mode(void); +/******************************************************************************* + * + * Function is_atv_device + * + * Description Returns true if the local device is an Android TV + * device, false if it is not. + * + * Returns bool + * + ******************************************************************************/ +bool is_atv_device(void); + /******************************************************************************* * * Function btif_get_adapter_properties diff --git a/btif/src/bluetooth.cc b/btif/src/bluetooth.cc index 6e86ce780..6fc418bdb 100644 --- a/btif/src/bluetooth.cc +++ b/btif/src/bluetooth.cc @@ -82,6 +82,7 @@ using bluetooth::hearing_aid::HearingAidInterface; bt_callbacks_t* bt_hal_cbacks = NULL; bool restricted_mode = false; +bool is_local_device_atv = false; /******************************************************************************* * Externs @@ -138,7 +139,7 @@ static bool is_profile(const char* p1, const char* p2) { * ****************************************************************************/ -static int init(bt_callbacks_t* callbacks) { +static int init(bt_callbacks_t* callbacks, bool is_atv) { LOG_INFO(LOG_TAG, "%s", __func__); if (interface_ready()) return BT_STATUS_DONE; @@ -148,6 +149,7 @@ static int init(bt_callbacks_t* callbacks) { #endif bt_hal_cbacks = callbacks; + is_local_device_atv = is_atv; stack_manager_get_interface()->init_stack(); btif_debug_init(); return BT_STATUS_SUCCESS; @@ -175,6 +177,8 @@ static void cleanup(void) { stack_manager_get_interface()->clean_up_stack(); } bool is_restricted_mode() { return restricted_mode; } +bool is_atv_device() { return is_local_device_atv; } + static int get_adapter_properties(void) { /* sanity check */ if (!interface_ready()) return BT_STATUS_NOT_READY; diff --git a/include/hardware/bluetooth.h b/include/hardware/bluetooth.h index 36680bf9a..f6a273124 100644 --- a/include/hardware/bluetooth.h +++ b/include/hardware/bluetooth.h @@ -444,8 +444,9 @@ typedef struct { /** * Opens the interface and provides the callback routines * to the implemenation of this interface. + * The |is_atv| flag indicates whether the local device is an Android TV */ - int (*init)(bt_callbacks_t* callbacks); + int (*init)(bt_callbacks_t* callbacks, bool is_atv); /** Enable Bluetooth. */ int (*enable)(bool guest_mode); diff --git a/service/hal/bluetooth_interface.cc b/service/hal/bluetooth_interface.cc index 9296966d4..d2824d702 100644 --- a/service/hal/bluetooth_interface.cc +++ b/service/hal/bluetooth_interface.cc @@ -247,7 +247,7 @@ class BluetoothInterfaceImpl : public BluetoothInterface { // Initialize the Bluetooth interface. Set up the adapter (Bluetooth DM) API // callbacks. - status = hal_iface_->init(&bt_callbacks); + status = hal_iface_->init(&bt_callbacks, false); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "Failed to initialize Bluetooth stack"; return false; diff --git a/stack/smp/smp_act.cc b/stack/smp/smp_act.cc index 073e3f82e..fe9d54600 100644 --- a/stack/smp/smp_act.cc +++ b/stack/smp/smp_act.cc @@ -17,6 +17,7 @@ ******************************************************************************/ #include +#include "btif_api.h" #include "btif_common.h" #include "device/include/interop.h" #include "internal_include/bt_target.h" @@ -1272,8 +1273,9 @@ void smp_decide_association_model(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { smp_int_data.status = SMP_PAIR_AUTH_FAIL; int_evt = SMP_AUTH_CMPL_EVT; } else { - if (p_cb->local_io_capability != SMP_IO_CAP_NONE && - p_cb->local_io_capability != SMP_IO_CAP_IN) { + if (!is_atv_device() && + (p_cb->local_io_capability == SMP_IO_CAP_IO || + p_cb->local_io_capability == SMP_IO_CAP_KBDISP)) { /* display consent dialog if this device has a display */ SMP_TRACE_DEBUG("ENCRYPTION_ONLY showing Consent Dialog"); p_cb->cb_evt = SMP_CONSENT_REQ_EVT; @@ -1639,8 +1641,9 @@ void smp_process_peer_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { } if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) { - if (p_cb->local_io_capability != SMP_IO_CAP_NONE && - p_cb->local_io_capability != SMP_IO_CAP_IN) { + if (!is_atv_device() && + (p_cb->local_io_capability == SMP_IO_CAP_IO || + p_cb->local_io_capability == SMP_IO_CAP_KBDISP)) { /* display consent dialog */ SMP_TRACE_DEBUG("JUST WORKS showing Consent Dialog"); p_cb->cb_evt = SMP_CONSENT_REQ_EVT; diff --git a/test/suite/adapter/adapter_unittest.cc b/test/suite/adapter/adapter_unittest.cc index 24ca3e5aa..c9fe6062c 100644 --- a/test/suite/adapter/adapter_unittest.cc +++ b/test/suite/adapter/adapter_unittest.cc @@ -179,7 +179,7 @@ TEST_F(BluetoothTest, AdapterCleanupDuringDiscovery) { ASSERT_TRUE(bt_callbacks != nullptr); for (int i = 0; i < kTestRepeatCount; ++i) { - bt_interface()->init(bt_callbacks); + bt_interface()->init(bt_callbacks, false); EXPECT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); EXPECT_EQ(GetState(), BT_STATE_ON) << "Adapter did not turn on."; -- cgit v1.2.3