OSDN Git Service

L2cap privacy shim
authorHansong Zhang <hsz@google.com>
Mon, 1 Feb 2021 08:35:47 +0000 (00:35 -0800)
committerHansong Zhang <hsz@google.com>
Tue, 2 Feb 2021 00:47:16 +0000 (00:47 +0000)
Bug: 141555841
Tag: #gd-refactor
Test: cert/run
Change-Id: I62ac6986b9798638503cc3b2bf3e234234a0566b

gd/hci/le_address_manager.cc
main/shim/acl_api.cc
stack/btm/btm_ble_gap.cc

index fbafe06..83b3ebc 100644 (file)
@@ -150,7 +150,7 @@ void LeAddressManager::register_client(LeAddressManagerCallback* callback) {
   } else if (
       address_policy_ == AddressPolicy::USE_RESOLVABLE_ADDRESS ||
       address_policy_ == AddressPolicy::USE_NON_RESOLVABLE_ADDRESS) {
-    if (bluetooth::common::init_flags::gd_acl_is_enabled()) {
+    if (bluetooth::common::init_flags::gd_acl_is_enabled() || bluetooth::common::init_flags::gd_l2cap_is_enabled()) {
       if (registered_clients_.size() == 1) {
         schedule_rotate_random_address();
       }
index 38d3e0b..8455492 100644 (file)
@@ -17,6 +17,7 @@
 #include <cstddef>
 #include <cstdint>
 
+#include "gd/hci/acl_manager.h"
 #include "main/shim/acl_api.h"
 #include "main/shim/helpers.h"
 #include "main/shim/stack.h"
@@ -49,7 +50,22 @@ void bluetooth::shim::ACL_WriteData(uint16_t handle, const BT_HDR* p_buf) {
 }
 
 void bluetooth::shim::ACL_ConfigureLePrivacy(bool is_le_privacy_enabled) {
-  Stack::GetInstance()->GetAcl()->ConfigureLePrivacy(is_le_privacy_enabled);
+  hci::LeAddressManager::AddressPolicy address_policy =
+      is_le_privacy_enabled
+          ? hci::LeAddressManager::AddressPolicy::USE_RESOLVABLE_ADDRESS
+          : hci::LeAddressManager::AddressPolicy::USE_PUBLIC_ADDRESS;
+  hci::AddressWithType empty_address_with_type(
+      hci::Address{}, hci::AddressType::RANDOM_DEVICE_ADDRESS);
+  /* 7 minutes minimum, 15 minutes maximum for random address refreshing */
+  auto minimum_rotation_time = std::chrono::minutes(7);
+  auto maximum_rotation_time = std::chrono::minutes(15);
+
+  Stack::GetInstance()
+      ->GetStackManager()
+      ->GetInstance<bluetooth::hci::AclManager>()
+      ->SetPrivacyPolicyForInitiatorAddress(
+          address_policy, empty_address_with_type, minimum_rotation_time,
+          maximum_rotation_time);
 }
 
 void bluetooth::shim::ACL_Disconnect(uint16_t handle, bool is_classic,
index d5c6892..53c4fdb 100644 (file)
@@ -705,7 +705,8 @@ bool BTM_BleConfigPrivacy(bool privacy_mode) {
 
   GAP_BleAttrDBUpdate(GATT_UUID_GAP_CENTRAL_ADDR_RESOL, &gap_ble_attr_value);
 
-  if (bluetooth::shim::is_gd_acl_enabled()) {
+  if (bluetooth::shim::is_gd_acl_enabled() ||
+      bluetooth::shim::is_gd_l2cap_enabled()) {
     bluetooth::shim::ACL_ConfigureLePrivacy(privacy_mode);
   }
   return true;