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

Commit 84b63afa authored by En-Shuo Hsu's avatar En-Shuo Hsu
Browse files

floss: Fork chromeos metrics from linux

ChromeOS uses the structured metrics that is not built for the Linux
build. Fork the code and fill the implementation for A2dpAudioOverrun.

BUG: 239978865
Tag: #floss
Test: ./build.py
Test: emerge-${BOARD} floss
Test: gd/cert/run
Change-Id: I2ee4bd6fe88ae8477861f538eae021586ad89598
parent 452c0114
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -12,6 +12,23 @@
#  See the License for the specific language governing permissions and
#  limitations under the License.

source_set("BluetoothOsSources_chromeos") {
  sources = [
    "chromeos/metrics.cc",
    "chromeos/parameter_provider.cc",
    "chromeos/system_properties.cc",
    "chromeos/wakelock_native.cc",
    "system_properties_common.cc",
    "syslog.cc",
  ]

  configs += [ "//bt/system/gd:gd_defaults" ]
  deps = [
    "//bt/system:libbt-platform-protos-lite",
    "//bt/system/gd/rust/shim:init_flags_bridge_header",
  ]
}

source_set("BluetoothOsSources_linux") {
  sources = [
    "linux/metrics.cc",
@@ -43,5 +60,11 @@ source_set("BluetoothOsSources_linux_generic") {
  ]

  configs += [ "//bt/system/gd:gd_defaults" ]
  deps = [ ":BluetoothOsSources_linux", "//bt/system/gd:gd_default_deps" ]
  deps = [ "//bt/system/gd:gd_default_deps" ]

  if (target_os == "chromeos") {
    deps += [ ":BluetoothOsSources_chromeos" ]
  } else {
    deps += [ ":BluetoothOsSources_linux" ]
  }
}
+162 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2021 Google, Inc.
 *
 *  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 "os/metrics.h"

#include <metrics/structured_events.h>

#include "gd/metrics/utils.h"
#include "os/log.h"

namespace bluetooth {
namespace os {

using bluetooth::hci::Address;

void LogMetricClassicPairingEvent(
    const Address& address,
    uint16_t handle,
    uint32_t hci_cmd,
    uint16_t hci_event,
    uint16_t cmd_status,
    uint16_t reason_code,
    int64_t event_value) {}

void LogMetricSocketConnectionState(
    const Address& address,
    int port,
    int type,
    android::bluetooth::SocketConnectionstateEnum connection_state,
    int64_t tx_bytes,
    int64_t rx_bytes,
    int uid,
    int server_port,
    android::bluetooth::SocketRoleEnum socket_role) {}

void LogMetricHciTimeoutEvent(uint32_t hci_cmd) {}

void LogMetricA2dpAudioUnderrunEvent(
    const Address& address, uint64_t encoding_interval_millis, int num_missing_pcm_bytes) {}

void LogMetricA2dpAudioOverrunEvent(
    const Address& address,
    uint64_t encoding_interval_millis,
    int num_dropped_buffers,
    int num_dropped_encoded_frames,
    int num_dropped_encoded_bytes) {
  std::string boot_id;
  std::string addr_string;

  if (!metrics::GetBootId(&boot_id)) return;

  addr_string = address.ToString();

  LOG_DEBUG(
      "A2dpAudioOverrun: %s, %s, %llu, %d, %d, %d",
      boot_id.c_str(),
      addr_string.c_str(),
      (long long unsigned)encoding_interval_millis,
      num_dropped_buffers,
      num_dropped_encoded_bytes,
      num_dropped_encoded_bytes);

  ::metrics::structured::events::bluetooth::BluetoothA2dpAudioOverrun()
      .SetBootId(boot_id)
      .SetDeviceId(addr_string)
      .SetEncodingInterval(encoding_interval_millis)
      .SetDroppedBuffers(num_dropped_buffers)
      .SetDroppedFrames(num_dropped_encoded_frames)
      .SetDroppedBytes(num_dropped_encoded_bytes)
      .Record();
}

void LogMetricReadRssiResult(
    const Address& address, uint16_t handle, uint32_t cmd_status, int8_t rssi) {}

void LogMetricReadFailedContactCounterResult(
    const Address& address, uint16_t handle, uint32_t cmd_status, int32_t failed_contact_counter) {}

void LogMetricReadTxPowerLevelResult(
    const Address& address, uint16_t handle, uint32_t cmd_status, int32_t transmit_power_level) {}

void LogMetricRemoteVersionInfo(
    uint16_t handle,
    uint8_t status,
    uint8_t version,
    uint16_t manufacturer_name,
    uint16_t subversion) {}

void LogMetricLinkLayerConnectionEvent(
    const Address* address,
    uint32_t connection_handle,
    android::bluetooth::DirectionEnum direction,
    uint16_t link_type,
    uint32_t hci_cmd,
    uint16_t hci_event,
    uint16_t hci_ble_event,
    uint16_t cmd_status,
    uint16_t reason_code) {}

void LogMetricManufacturerInfo(
    const Address& address,
    android::bluetooth::AddressTypeEnum address_type,
    android::bluetooth::DeviceInfoSrcEnum source_type,
    const std::string& source_name,
    const std::string& manufacturer,
    const std::string& model,
    const std::string& hardware_version,
    const std::string& software_version) {}

void LogMetricSdpAttribute(
    const Address& address,
    uint16_t protocol_uuid,
    uint16_t attribute_id,
    size_t attribute_size,
    const char* attribute_value) {}

void LogMetricSmpPairingEvent(
    const Address& address,
    uint16_t smp_cmd,
    android::bluetooth::DirectionEnum direction,
    uint16_t smp_fail_reason) {}

void LogMetricA2dpPlaybackEvent(const Address& address, int playback_state, int audio_coding_mode) {
}

void LogMetricBluetoothHalCrashReason(
    const Address& address, uint32_t error_code, uint32_t vendor_error_code) {}

void LogMetricBluetoothLocalSupportedFeatures(uint32_t page_num, uint64_t features) {}

void LogMetricBluetoothLocalVersions(
    uint32_t lmp_manufacturer_name,
    uint8_t lmp_version,
    uint32_t lmp_subversion,
    uint8_t hci_version,
    uint32_t hci_revision) {}

void LogMetricBluetoothDisconnectionReasonReported(
    uint32_t reason, const Address& address, uint32_t connection_handle) {}

void LogMetricBluetoothRemoteSupportedFeatures(
    const Address& address, uint32_t page, uint64_t features, uint32_t connection_handle) {}

void LogMetricBluetoothCodePathCounterMetrics(int32_t key, int64_t count) {}

}  // namespace os
}  // namespace bluetooth
+115 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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 "os/parameter_provider.h"

#include <unistd.h>

#include <cerrno>
#include <mutex>
#include <string>

#include "os/log.h"

namespace bluetooth {
namespace os {

namespace {
std::mutex parameter_mutex;
std::string config_file_path;
std::string snoop_log_file_path;
std::string snooz_log_file_path;
std::string sysprops_file_path;
}  // namespace

// Write to $PWD/bt_stack.conf if $PWD can be found, otherwise, write to $HOME/bt_stack.conf
std::string ParameterProvider::ConfigFilePath() {
  {
    std::lock_guard<std::mutex> lock(parameter_mutex);
    if (!config_file_path.empty()) {
      return config_file_path;
    }
  }
  return "/var/lib/bluetooth/bt_config.conf";
}

void ParameterProvider::OverrideConfigFilePath(const std::string& path) {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  config_file_path = path;
}

std::string ParameterProvider::SnoopLogFilePath() {
  {
    std::lock_guard<std::mutex> lock(parameter_mutex);
    if (!snoop_log_file_path.empty()) {
      return snoop_log_file_path;
    }
  }

  return "/var/log/bluetooth/btsnoop_hci.log";
}

void ParameterProvider::OverrideSnoopLogFilePath(const std::string& path) {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  snoop_log_file_path = path;
}

std::string ParameterProvider::SnoozLogFilePath() {
  {
    std::lock_guard<std::mutex> lock(parameter_mutex);
    if (!snooz_log_file_path.empty()) {
      return snooz_log_file_path;
    }
  }
  return "/var/log/bluetooth/btsnooz_hci.log";
}

std::string ParameterProvider::SyspropsFilePath() {
  {
    std::lock_guard<std::mutex> lock(parameter_mutex);
    if (!sysprops_file_path.empty()) {
      return sysprops_file_path;
    }
  }
  return "/var/lib/bluetooth/sysprops.conf";
}

void ParameterProvider::OverrideSyspropsFilePath(const std::string& path) {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  sysprops_file_path = path;
}

bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
  return nullptr;
}

void ParameterProvider::SetBtKeystoreInterface(
    bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore) {}

bool ParameterProvider::IsCommonCriteriaMode() {
  return false;
}

void ParameterProvider::SetCommonCriteriaMode(bool enable) {}

int ParameterProvider::GetCommonCriteriaConfigCompareResult() {
  return 0b11;
}

void ParameterProvider::SetCommonCriteriaConfigCompareResult(int result) {}

}  // namespace os
}  // namespace bluetooth
+65 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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 "os/system_properties.h"

#include <mutex>
#include <string>
#include <unordered_map>

namespace bluetooth {
namespace os {

namespace {
std::mutex properties_mutex;

// Properties set along with some default values for Floss.
std::unordered_map<std::string, std::string> properties = {
    {"bluetooth.profile.avrcp.target.enabled", "true"},
};
}  // namespace

std::optional<std::string> GetSystemProperty(const std::string& property) {
  std::lock_guard<std::mutex> lock(properties_mutex);
  auto iter = properties.find(property);
  if (iter == properties.end()) {
    return std::nullopt;
  }
  return iter->second;
}

bool SetSystemProperty(const std::string& property, const std::string& value) {
  std::lock_guard<std::mutex> lock(properties_mutex);
  properties.insert_or_assign(property, value);
  return true;
}

bool ClearSystemPropertiesForHost() {
  std::lock_guard<std::mutex> lock(properties_mutex);
  properties.clear();
  return true;
}

bool IsRootCanalEnabled() {
  return false;
}

int GetAndroidVendorReleaseVersion() {
  return 0;
}

}  // namespace os
}  // namespace bluetooth
+54 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2021 Google, Inc.
 *
 *  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.
 *
 ******************************************************************************/

#define LOG_TAG "BtGdWakelockNative"

#include "os/internal/wakelock_native.h"

#include "os/log.h"

namespace bluetooth {
namespace os {
namespace internal {

struct WakelockNative::Impl {};

void WakelockNative::Initialize() {
  LOG_INFO("Linux native wakelock is not implemented");
}

WakelockNative::StatusCode WakelockNative::Acquire(const std::string& lock_name) {
  LOG_INFO("Linux native wakelock is not implemented");
  return StatusCode::SUCCESS;
}

WakelockNative::StatusCode WakelockNative::Release(const std::string& lock_name) {
  LOG_INFO("Linux native wakelock is not implemented");
  return StatusCode::SUCCESS;
}
void WakelockNative::CleanUp() {
  LOG_INFO("Linux native wakelock is not implemented");
}

WakelockNative::WakelockNative() : pimpl_(std::make_unique<Impl>()) {}

WakelockNative::~WakelockNative() = default;

}  // namespace internal
}  // namespace os
}  // namespace bluetooth
 No newline at end of file