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

Commit 4b0e837a authored by David Duarte's avatar David Duarte
Browse files

Remove bluetooth native service

Bug: 263885771
Test: TreeHugger
Change-Id: I13f17a98c7679c01110a360467471ab7139d44dd
parent 1b1e1325
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -112,9 +112,6 @@
    {
      "name": "bluetooth_vc_test"
    },
    {
      "name": "bluetoothtbd_test"
    },
    {
      "name": "bt_host_test_bta"
    },
+0 −2
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ static_library("bluetooth-static") {
  complete_static_lib = true

  sources = [
    "//bt/system/service/hal/bluetooth_interface.cc",
    "//bt/system/service/logging_helpers.cc",
  ]

  configs += [

system/service/Android.bp

deleted100644 → 0
+0 −313
Original line number Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "system_bt_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["system_bt_license"],
}

subdirs = [
    "common",
]

cc_defaults {
    name: "fluoride_service_defaults",
    defaults: ["fluoride_defaults"],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
    ],
    header_libs: ["libbluetooth_headers"],
}

// Source variables
btserviceDaemonSrc = [
    "a2dp_sink.cc",
    "a2dp_source.cc",
    "adapter.cc",
    "avrcp_control.cc",
    "avrcp_target.cc",
    "daemon.cc",
    "gatt_client.cc",
    "gatt_server.cc",
    "gatt_server_old.cc",
    "hal/bluetooth_av_interface.cc",
    "hal/bluetooth_avrcp_interface.cc",
    "hal/bluetooth_gatt_interface.cc",
    "hal/bluetooth_interface.cc",
    "ipc/ipc_handler.cc",
    "ipc/ipc_manager.cc",
    "logging_helpers.cc",
    "low_energy_advertiser.cc",
    "low_energy_scanner.cc",
    "low_energy_client.cc",
    "settings.cc",
]

btserviceLinuxSrc = [
    "ipc/ipc_handler_linux.cc",
    "ipc/linux_ipc_host.cc",
]

btserviceBinderDaemonSrc = [
    "ipc/binder/bluetooth_a2dp_sink_binder_server.cc",
    "ipc/binder/bluetooth_a2dp_source_binder_server.cc",
    "ipc/binder/bluetooth_avrcp_control_binder_server.cc",
    "ipc/binder/bluetooth_avrcp_target_binder_server.cc",
    "ipc/binder/bluetooth_binder_server.cc",
    "ipc/binder/bluetooth_gatt_client_binder_server.cc",
    "ipc/binder/bluetooth_gatt_server_binder_server.cc",
    "ipc/binder/bluetooth_le_advertiser_binder_server.cc",
    "ipc/binder/bluetooth_le_scanner_binder_server.cc",
    "ipc/binder/bluetooth_low_energy_binder_server.cc",
    "ipc/binder/interface_with_instances_base.cc",
    "ipc/binder/ipc_handler_binder.cc",
]

// Main unit test sources. These get built for host and target.
btserviceBaseTestSrc = [
    "hal/fake_bluetooth_av_interface.cc",
    "hal/fake_bluetooth_gatt_interface.cc",
    "hal/fake_bluetooth_interface.cc",
    "test/a2dp_sink_unittest.cc",
    "test/a2dp_source_unittest.cc",
    "test/adapter_unittest.cc",
    "test/advertise_data_unittest.cc",
    "test/fake_hal_util.cc",
    "test/gatt_client_unittest.cc",
    "test/gatt_server_unittest.cc",
    "test/low_energy_advertiser_unittest.cc",
    "test/low_energy_client_unittest.cc",
    "test/low_energy_scanner_unittest.cc",
    "test/settings_unittest.cc",
]

// Native system service for target
cc_binary {
    name: "bluetoothtbd",
    defaults: ["fluoride_service_defaults"],
    srcs: btserviceBinderDaemonSrc +
        btserviceLinuxSrc +
        btserviceDaemonSrc +
        ["main.cc"],
    static_libs: [
        "avrcp-target-service",
        "libaudio-a2dp-hw-utils",
        "libbluetooth-binder-common",
        "libbluetooth-dumpsys",
        "libbluetooth-types",
        "libbt-audio-hal-interface",
        "libbt-bta",
        "libbt-bta-core",
        "libbt-common",
        "libbtcore",
        "libbtdevice",
        "libbte",
        "libbt-hci",
        "libbthalutils",
        "libbtif",
        "libbtif-core",
        "lib-bt-packets",
        "lib-bt-packets-avrcp",
        "lib-bt-packets-base",
        "libbt-protos-lite",
        "libbt-sbc-decoder",
        "libbt-sbc-encoder",
        "libbt-stack",
        "libbt-stack-core",
        "libbt-utils",
        "libc++fs",
        "libchrome",
        "libflatbuffers-cpp",
        "libFraunhoferAAC",
        "libg722codec",
        "liblc3",
        "libopus",
        "libosi",
        "libudrv-uipc",
    ],

    shared_libs: [
        "android.hardware.bluetooth@1.0",
        "android.hardware.bluetooth@1.1",
        "android.hardware.bluetooth.a2dp@1.0",
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth.audio@2.1",
        "android.system.suspend.control-V1-ndk",
        "android.system.suspend-V1-ndk",
        "libaaudio",
        "libbinder",
        "libbinder_ndk",
        "libcrypto",
        "libcutils",
        "libfmq",
        "liblog",
        "libprocessgroup",
        "libprotobuf-cpp-lite",
        "libutils",
    ],
    init_rc: ["bluetoothtbd.rc"],
    target: {
        android: {
            shared_libs: [
                "android.hardware.bluetooth.audio-V3-ndk",
                "libPlatformProperties",
            ],
        },
    },
}

// Native system service unit tests for target and host

cc_test {
    name: "bluetoothtbd_test",
    test_suites: ["device-tests"],
    defaults: [
        "fluoride_service_defaults",
        "mts_defaults",
    ],
    srcs: btserviceBaseTestSrc +
        btserviceDaemonSrc + [
            "test/main.cc",
        ],
    aidl: {
        include_dirs: [
            "packages/modules/Bluetooth/system/service/common",
            "frameworks/native/aidl/binder",
        ],
    },
    static_libs: [
        "android.hardware.bluetooth.a2dp@1.0",
        "avrcp-target-service",
        "libaudio-a2dp-hw-utils",
        "libbluetooth-common",
        "libbluetooth-dumpsys",
        "libbluetooth-types",
        "libbt-audio-hal-interface",
        "libbt-bta",
        "libbt-bta-core",
        "libbt-common",
        "libbtcore",
        "libbtdevice",
        "libbte",
        "libbt-hci",
        "libbtif",
        "libbtif-core",
        "lib-bt-packets",
        "lib-bt-packets-avrcp",
        "lib-bt-packets-base",
        "libbt-protos-lite",
        "libbt-sbc-decoder",
        "libbt-sbc-encoder",
        "libbt-stack",
        "libbt-stack-core",
        "libbt-utils",
        "libc++fs",
        "libchrome",
        "libgmock",
        "liblog",
        "libflatbuffers-cpp",
        "libFraunhoferAAC",
        "libg722codec",
        "liblc3",
        "libopus",
        "libosi",
        "libudrv-uipc",
    ],
    shared_libs: [
        "android.hardware.bluetooth@1.0",
        "android.hardware.bluetooth@1.1",
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth.audio@2.1",
        "libbinder_ndk",
        "libcrypto",
        "libfmq",
        "libprocessgroup",
        "libprotobuf-cpp-lite",
    ],

    // host_supported: true, // TODO (b/263324289)
    test_options: {
        unit_test: true,
    },
    target: {
        // This includes Binder related tests that can only be run
        // on target.
        android: {
            srcs: btserviceBinderDaemonSrc + [
                "test/parcelable_unittest.cc",
                "test/ParcelableTest.aidl",
            ],
            static_libs: [
                "android.system.suspend.control-V1-ndk",
                "libbluetooth-binder-common",
            ],
            shared_libs: [
                "android.hardware.bluetooth.audio-V3-ndk",
                "android.system.suspend-V1-ndk",
                "libbinder",
                "libvndksupport",
                "libPlatformProperties",
            ],
        },
        host: {
            srcs: [
                "test/stub_ipc_handler_binder.cc",
            ],
        },
        host_linux: {
            srcs: btserviceLinuxSrc + [
                // TODO(bcf): Fix this test.
                //"test/ipc_linux_unittest.cc",
            ],
        },
    },
    sanitize: {
        cfi: false,
    },
}

// Native system service CLI for target
cc_binary {
    name: "bluetooth-cli",
    defaults: ["fluoride_defaults"],
    srcs: ["client/main.cc"],
    static_libs: [
        "libbluetooth-binder-common",
    ],
    shared_libs: [
        "libbinder",
        "libutils",
    ],
}

// Heart Rate GATT service example for target
cc_binary {
    name: "bt-example-hr-server",
    defaults: ["fluoride_defaults"],
    local_include_dirs: ["example/heart_rate"],
    srcs: [
        "example/heart_rate/heart_rate_server.cc",
        "example/heart_rate/server_main.cc",
    ],
    static_libs: [
        "libbluetooth-binder-common",
    ],
    shared_libs: [
        "libbinder",
        "libutils",
    ],
}

cc_library_static {
    name: "libbluetoothtbd_hal",
    defaults: ["fluoride_defaults"],
    include_dirs: ["packages/modules/Bluetooth/system"],
    header_libs: ["libbluetooth_headers"],
    srcs: [
        "hal/bluetooth_gatt_interface.cc",
        "hal/bluetooth_interface.cc",
        "logging_helpers.cc",
    ],
}

system/service/BUILD.gn

deleted100644 → 0
+0 −171
Original line number Diff line number Diff line
#
#  Copyright 2015 Google
#
#  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.
#

config("service_config") {
  include_dirs = [
    "//bt/system/",
    "//bt/system/linux_include",
    "//bt/system/include",
    "//bt/system/service",
    "//bt/system/service/common",
  ]

  configs = [ "//bt/system:target_defaults" ]
}

source_set("service_daemon_src") {
  sources = [
    "a2dp_sink.cc",
    "a2dp_source.cc",
    "adapter.cc",
    "avrcp_control.cc",
    "avrcp_target.cc",
    "daemon.cc",
    "gatt_client.cc",
    "gatt_server.cc",
    "gatt_server_old.cc",
    "hal/bluetooth_av_interface.cc",
    "hal/bluetooth_avrcp_interface.cc",
    "hal/bluetooth_gatt_interface.cc",
    "hal/bluetooth_interface.cc",
    "ipc/ipc_handler.cc",
    "ipc/ipc_manager.cc",
    "logging_helpers.cc",
    "low_energy_advertiser.cc",
    "low_energy_client.cc",
    "low_energy_scanner.cc",
    "settings.cc",
  ]

  deps = [
    "//bt/system/gd/rust/shim:init_flags_bridge_header",
    "//bt/system/osi",
    "//bt/system/types",
  ]

  configs += [ ":service_config" ]
}

source_set("service_linux_src") {
  sources = [
    "ipc/ipc_handler_linux.cc",
    "ipc/linux_ipc_host.cc",
    "ipc/dbus/ipc_handler_dbus.cc",
    "ipc/dbus/bluetooth_adapter.cc",
  ]

  deps = [
    "//bt/system/gd/rust/shim:init_flags_bridge_header",
    "//bt/system/osi",
    "//bt/system/types",
  ]

  configs += [ ":service_config" ]
}

static_library("service") {
  sources = [
    "common/bluetooth/a2dp_codec_config.cc",
    "common/bluetooth/adapter_state.cc",
    "common/bluetooth/advertise_data.cc",
    "common/bluetooth/advertise_settings.cc",
    "common/bluetooth/avrcp_int_value.cc",
    "common/bluetooth/avrcp_media_attr.cc",
    "common/bluetooth/avrcp_register_notification_response.cc",
    "common/bluetooth/characteristic.cc",
    "common/bluetooth/descriptor.cc",
    "common/bluetooth/remote_device_props.cc",
    "common/bluetooth/scan_filter.cc",
    "common/bluetooth/scan_result.cc",
    "common/bluetooth/scan_settings.cc",
    "common/bluetooth/service.cc",
    "common/bluetooth/util/atomic_string.cc",
  ]

  deps = [
    ":service_daemon_src",
    ":service_linux_src",
    "//bt/system/gd/rust/shim:init_flags_bridge_header",
    "//bt/system/osi",
    "//bt/system/types",
  ]

  configs += [ ":service_config" ]
}

executable("bluetoothtbd") {
  sources = [ "main.cc" ]

  deps = [
    ":service",
    "//bt/system/btcore",
    "//bt/system/main:bluetooth",
  ]

  configs += [ ":service_config" ]

  libs = [
    "dl",
    "pthread",
    "rt",
    "bt_shim_ffi",
    "ssl",
    "crypto",
  ]

  lib_dirs = [
    "${root_out_dir}/rust"
  ]
}

if (use.test) {
  source_set("service_base_test_src") {
    sources = [
      "hal/fake_bluetooth_av_interface.cc",
      "hal/fake_bluetooth_gatt_interface.cc",
      "hal/fake_bluetooth_interface.cc",
      "test/a2dp_sink_unittest.cc",
      "test/a2dp_source_unittest.cc",
      "test/adapter_unittest.cc",
      "test/advertise_data_unittest.cc",
      "test/fake_hal_util.cc",
      "test/gatt_client_unittest.cc",
      "test/gatt_server_unittest.cc",
      "test/low_energy_advertiser_unittest.cc",
      "test/low_energy_client_unittest.cc",
      "test/low_energy_scanner_unittest.cc",
      "test/settings_unittest.cc",
    ]

    configs += [ ":service_config" ]
  }

  executable("bluetoothtbd_test") {
    sources = [ "test/main.cc" ]

    deps = [
      ":service_base_test_src",
      ":service_daemon_src",
      ":service_linux_src",
      "//bt/system/service/common:libbluetooth_common",
    ]

    configs += [
      "//bt/system:external_gmock_main",
      ":service_config",
    ]
  }
}

system/service/a2dp_sink.cc

deleted100644 → 0
+0 −154
Original line number Diff line number Diff line
//
//  Copyright 2017 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 "service/a2dp_sink.h"

#include <base/logging.h>
#include <base/memory/ptr_util.h>

#include "service/logging_helpers.h"
#include "types/raw_address.h"

using bluetooth::hal::BluetoothAvInterface;

namespace bluetooth {

// static
const int A2dpSink::kSingletonInstanceId = 0;

A2dpSink::A2dpSink(const Uuid& uuid) : app_identifier_(uuid) {
  hal::BluetoothAvInterface::Get()->AddA2dpSinkObserver(this);
}

A2dpSink::~A2dpSink() {
  hal::BluetoothAvInterface::Get()->RemoveA2dpSinkObserver(this);
}

const Uuid& A2dpSink::GetAppIdentifier() const { return app_identifier_; }

int A2dpSink::GetInstanceId() const { return kSingletonInstanceId; }

void A2dpSink::SetDelegate(Delegate* delegate) {
  std::lock_guard<std::mutex> lock(delegate_mutex_);
  delegate_ = delegate;
}

bool A2dpSink::Enable() {
  std::lock_guard<std::mutex> lock(mutex_);
  return hal::BluetoothAvInterface::Get()->A2dpSinkEnable();
}

void A2dpSink::Disable() {
  std::lock_guard<std::mutex> lock(mutex_);
  hal::BluetoothAvInterface::Get()->A2dpSinkDisable();
}

bool A2dpSink::Connect(const std::string& device_address) {
  std::lock_guard<std::mutex> lock(mutex_);
  RawAddress addr;
  if (!RawAddress::FromString(device_address, addr)) {
    LOG(ERROR) << "Invalid device address given: " << device_address;
    return false;
  }

  bt_status_t status =
      hal::BluetoothAvInterface::Get()->GetA2dpSinkHALInterface()->connect(
          addr);
  if (status != BT_STATUS_SUCCESS) {
    LOG(ERROR) << "Failed to connect";
    return false;
  }

  return true;
}

bool A2dpSink::Disconnect(const std::string& device_address) {
  std::lock_guard<std::mutex> lock(mutex_);
  RawAddress addr;
  if (!RawAddress::FromString(device_address, addr)) {
    LOG(ERROR) << "Invalid device address given: " << device_address;
    return false;
  }

  bt_status_t status =
      hal::BluetoothAvInterface::Get()->GetA2dpSinkHALInterface()->disconnect(
          addr);
  if (status != BT_STATUS_SUCCESS) {
    LOG(ERROR) << "Failed to disconnect";
    return false;
  }

  return true;
}

void A2dpSink::SetAudioFocusState(int focus_state) {
  std::lock_guard<std::mutex> lock(mutex_);
  hal::BluetoothAvInterface::Get()
      ->GetA2dpSinkHALInterface()
      ->set_audio_focus_state(focus_state);
}

void A2dpSink::SetAudioTrackGain(float gain) {
  std::lock_guard<std::mutex> lock(mutex_);
  hal::BluetoothAvInterface::Get()
      ->GetA2dpSinkHALInterface()
      ->set_audio_track_gain(gain);
}

void A2dpSink::ConnectionStateCallback(BluetoothAvInterface* iface,
                                       const RawAddress& bd_addr,
                                       btav_connection_state_t state) {
  std::string device_address = BtAddrString(&bd_addr);
  std::lock_guard<std::mutex> lock(delegate_mutex_);

  if (delegate_)
    delegate_->OnConnectionState(device_address, static_cast<int>(state));
}

void A2dpSink::AudioStateCallback(BluetoothAvInterface* iface,
                                  const RawAddress& bd_addr,
                                  btav_audio_state_t state) {
  std::string device_address = BtAddrString(&bd_addr);
  std::lock_guard<std::mutex> lock(delegate_mutex_);

  if (delegate_)
    delegate_->OnAudioState(device_address, static_cast<int>(state));
}

void A2dpSink::AudioConfigCallback(BluetoothAvInterface* iface,
                                   const RawAddress& bd_addr,
                                   uint32_t sample_rate,
                                   uint8_t channel_count) {
  std::string device_address = BtAddrString(&bd_addr);
  std::lock_guard<std::mutex> lock(delegate_mutex_);
  if (delegate_)
    delegate_->OnAudioConfig(device_address, sample_rate, channel_count);
}

// A2dpSinkFactory implementation
A2dpSinkFactory::A2dpSinkFactory() = default;
A2dpSinkFactory::~A2dpSinkFactory() = default;

bool A2dpSinkFactory::RegisterInstance(const Uuid& uuid,
                                       const RegisterCallback& callback) {
  VLOG(1) << __func__ << " - Uuid: " << uuid.ToString();

  auto a2dp_sink = base::WrapUnique(new A2dpSink(uuid));
  callback(BLE_STATUS_SUCCESS, uuid, std::move(a2dp_sink));
  return true;
}

}  // namespace bluetooth
Loading