OSDN Git Service

Add in metrics calls
authorMartin Brabham <optedoblivion@google.com>
Tue, 8 Sep 2020 20:09:21 +0000 (13:09 -0700)
committerMartin Brabham <optedoblivion@google.com>
Tue, 8 Sep 2020 22:53:04 +0000 (15:53 -0700)
Bug: 162984360
Tag: #gd-refactor
Test: cert/run --host SecurityTest
Test: atest --host bluetooth_test_gd
Test: Manual testing with hybrid stack
Change-Id: I454fd60e8ff669a73407d65e601519b8bf0331e0

main/shim/btm_api.cc

index 8e478ef..4600431 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <mutex>
 
+#include "common/metric_id_allocator.h"
 #include "common/time_util.h"
 #include "device/include/controller.h"
 #include "gd/common/callback.h"
@@ -36,6 +37,8 @@
 #include "stack/btm/btm_int_types.h"
 #include "types/raw_address.h"
 
+using bluetooth::common::MetricIdAllocator;
+
 #define BTIF_DM_DEFAULT_INQ_MAX_RESULTS 0
 #define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10
 
@@ -429,12 +432,21 @@ class ShimBondListener : public bluetooth::security::ISecurityManagerListener {
             bluetooth::ToRawAddress(device.GetAddress()), 0, name, BTM_SUCCESS);
       }
     }
+    MetricIdAllocator::GetInstance().AllocateId(
+        bluetooth::ToRawAddress(device.GetAddress()));
+    if (!MetricIdAllocator::GetInstance().SaveDevice(
+            bluetooth::ToRawAddress(device.GetAddress()))) {
+      LOG(FATAL) << __func__ << ": Fail to save metric id for device "
+                 << bluetooth::ToRawAddress(device.GetAddress());
+    }
   }
 
   void OnDeviceUnbonded(bluetooth::hci::AddressWithType device) override {
     if (bta_callbacks_->p_bond_cancel_cmpl_callback) {
       (*bta_callbacks_->p_bond_cancel_cmpl_callback)(BTM_SUCCESS);
     }
+    MetricIdAllocator::GetInstance().ForgetDevice(
+        bluetooth::ToRawAddress(device.GetAddress()));
   }
 
   void OnDeviceBondFailed(bluetooth::hci::AddressWithType device) override {