Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21e9358d authored by Palash Ahuja's avatar Palash Ahuja
Browse files

BluetoothMetrics: Log ACL Completion

Test: m com.android.btservices
Flag: EXEMPT, metrics related changes
Bug: 345564021
Change-Id: I9ab3a06c2f9e4e66787de59ff50d148d88752c16
parent 69fe1730
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ package {
filegroup {
    name: "BluetoothMetricsSources",
    srcs: [
        "bluetooth_event.cc",
        "counter_metrics.cc",
        "metrics_state.cc",
        "utils.cc",
+2 −1
Original line number Diff line number Diff line
@@ -40,7 +40,8 @@ source_set("BluetoothMetricsSources") {
  sources = [
    "counter_metrics.cc",
    "utils.cc",
    "metrics_state.cc"
    "metrics_state.cc",
    "bluetooth_event.cc"
  ]

  configs += [
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "bluetooth_event.h"

#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>

#include "os/metrics.h"

namespace bluetooth {
namespace metrics {

using android::bluetooth::EventType;
using android::bluetooth::State;
using hci::ErrorCode;

State MapErrorCodeToState(ErrorCode reason) {
  // TODO - map the error codes to the state enum variants.
  switch (reason) {
    case ErrorCode::SUCCESS:
      return State::SUCCESS;
    default:
      return State::STATE_UNKNOWN;
  }
}

void LogAclCompletionEvent(const hci::Address& address, ErrorCode reason,
                           bool is_locally_initiated) {
  bluetooth::os::LogMetricBluetoothEvent(address,
                                         is_locally_initiated ? EventType::ACL_CONNECTION_INITIATOR
                                                              : EventType::ACL_CONNECTION_RESPONDER,
                                         MapErrorCodeToState(reason));
}
}  // namespace metrics
}  // namespace bluetooth
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "hci/address.h"
#include "hci/hci_packets.h"

namespace bluetooth {
namespace metrics {

void LogAclCompletionEvent(const hci::Address& address, hci::ErrorCode reason,
                           bool is_locally_initiated);

}  // namespace metrics
}  // namespace bluetooth
+3 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@
#include "main/shim/entry.h"
#include "main/shim/helpers.h"
#include "main/shim/stack.h"
#include "metrics/bluetooth_event.h"
#include "os/handler.h"
#include "osi/include/allocator.h"
#include "stack/acl/acl.h"
@@ -1499,6 +1500,7 @@ void shim::legacy::Acl::OnConnectSuccess(
                      locally_initiated);
  log::debug("Connection successful classic remote:{} handle:{} initiator:{}", remote_address,
             handle, (locally_initiated) ? "local" : "remote");
  metrics::LogAclCompletionEvent(remote_address, hci::ErrorCode::SUCCESS, locally_initiated);
  BTM_LogHistory(kBtmLogTag, ToRawAddress(remote_address), "Connection successful",
                 (locally_initiated) ? "classic Local initiated" : "classic Remote initiated");
}
@@ -1521,6 +1523,7 @@ void shim::legacy::Acl::OnConnectFail(hci::Address address, hci::ErrorCode reaso
  TRY_POSTING_ON_MAIN(acl_interface_.connection.classic.on_failed, bd_addr,
                      ToLegacyHciErrorCode(reason), locally_initiated);
  log::warn("Connection failed classic remote:{} reason:{}", address, hci::ErrorCodeText(reason));
  metrics::LogAclCompletionEvent(address, reason, locally_initiated);
  BTM_LogHistory(kBtmLogTag, ToRawAddress(address), "Connection failed",
                 base::StringPrintf("classic reason:%s", hci::ErrorCodeText(reason).c_str()));
}