OSDN Git Service

Check whether local device is an ATV device to determine whether to show
authorRahul Sabnis <rahulsabnis@google.com>
Sat, 1 Aug 2020 02:44:27 +0000 (19:44 -0700)
committerRahul Sabnis <rahulsabnis@google.com>
Tue, 4 Aug 2020 18:25:12 +0000 (18:25 +0000)
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
btif/src/bluetooth.cc
include/hardware/bluetooth.h
service/hal/bluetooth_interface.cc
stack/smp/smp_act.cc
test/suite/adapter/adapter_unittest.cc

index bb8e690..50d833f 100644 (file)
@@ -118,6 +118,18 @@ bool is_niap_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
  *
  * Description      Fetches all local adapter properties
index 1599311..158a739 100644 (file)
@@ -82,6 +82,7 @@ using bluetooth::hearing_aid::HearingAidInterface;
 bt_callbacks_t* bt_hal_cbacks = NULL;
 bool restricted_mode = false;
 bool niap_mode = false;
+bool is_local_device_atv = false;
 
 /*******************************************************************************
  *  Externs
@@ -134,7 +135,7 @@ static bool is_profile(const char* p1, const char* p2) {
  ****************************************************************************/
 
 static int init(bt_callbacks_t* callbacks, bool start_restricted,
-                bool is_niap_mode) {
+                bool is_niap_mode, bool is_atv) {
   LOG_INFO(LOG_TAG, "%s: start restricted = %d ; niap = %d", __func__,
            start_restricted, is_niap_mode);
 
@@ -147,6 +148,7 @@ static int init(bt_callbacks_t* callbacks, bool start_restricted,
   bt_hal_cbacks = callbacks;
   restricted_mode = start_restricted;
   niap_mode = is_niap_mode;
+  is_local_device_atv = is_atv;
   stack_manager_get_interface()->init_stack();
   btif_debug_init();
   return BT_STATUS_SUCCESS;
@@ -171,6 +173,8 @@ static void cleanup(void) { stack_manager_get_interface()->clean_up_stack(); }
 bool is_restricted_mode() { return restricted_mode; }
 bool is_niap_mode() { return niap_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;
index 604ec4c..ae58ac2 100644 (file)
@@ -470,8 +470,9 @@ typedef struct {
    * restricted mode, bonds that are created are marked as restricted in the
    * config file. These devices are deleted upon leaving restricted mode.
    * The |is_niap_mode| flag inits the adapter in NIAP mode.
+   * The |is_atv| flag indicates whether the local device is an Android TV
    */
-  int (*init)(bt_callbacks_t* callbacks, bool guest_mode, bool is_niap_mode);
+  int (*init)(bt_callbacks_t* callbacks, bool guest_mode, bool is_niap_mode, bool is_atv);
 
   /** Enable Bluetooth. */
   int (*enable)();
index 5ca220c..b87ee8c 100644 (file)
@@ -254,7 +254,7 @@ class BluetoothInterfaceImpl : public BluetoothInterface {
 
     // Initialize the Bluetooth interface. Set up the adapter (Bluetooth DM) API
     // callbacks.
-    status = hal_iface_->init(&bt_callbacks, false, false);
+    status = hal_iface_->init(&bt_callbacks, false, false, false);
     if (status != BT_STATUS_SUCCESS) {
       LOG(ERROR) << "Failed to initialize Bluetooth stack";
       return false;
index 1239542..22d9958 100644 (file)
@@ -19,6 +19,7 @@
 #include <cutils/log.h>
 #include <log/log.h>
 #include <string.h>
+#include "btif_api.h"
 #include "btif_common.h"
 #include "btif_storage.h"
 #include "device/include/interop.h"
@@ -1301,8 +1302,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;
@@ -1656,8 +1658,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;
index 7a26e28..5079835 100644 (file)
@@ -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, false, false);
+    bt_interface()->init(bt_callbacks, false, false, false);
     EXPECT_EQ(bt_interface()->enable(), BT_STATUS_SUCCESS);
     semaphore_wait(adapter_state_changed_callback_sem_);
     EXPECT_EQ(GetState(), BT_STATE_ON) << "Adapter did not turn on.";