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

Commit b8fd030f authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I186c18bf,I0e976e14,Ied7c1325,I7d4987b0,Ib0138f38, ... am: 446688fa

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1838395

Change-Id: I78705d50bc4a41cdaf805d85a6f728a1702295de
parents 49dabc12 446688fa
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -1155,7 +1155,8 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
      /* inquiry result */
      bt_bdname_t bdname;
      uint8_t remote_name_len;
      tBTA_SERVICE_MASK services = 0;
      uint8_t num_uuids = 0, max_num_uuid = 32;
      uint8_t uuid_list[32 * Uuid::kNumBytes16];

      p_search_data->inq_res.remt_name_not_required =
          check_eir_remote_name(p_search_data, NULL, NULL);
@@ -1169,14 +1170,11 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
      if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
        check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);

      /* Check EIR for remote name and services */
      /* Check EIR for services */
      if (p_search_data->inq_res.p_eir) {
        BTA_GetEirService(p_search_data->inq_res.p_eir,
                          p_search_data->inq_res.eir_len, &services);
        BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __func__,
                         (uint32_t)services);
        /* TODO:  Get the service list and check to see which uuids we got and
         * send it back to the client. */
        BTM_GetEirUuidList(p_search_data->inq_res.p_eir,
                           p_search_data->inq_res.eir_len, Uuid::kNumBytes16,
                           &num_uuids, uuid_list, max_num_uuid);
      }

      {
@@ -1244,6 +1242,21 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
                                   &(p_search_data->inq_res.include_rsi));
        num_properties++;

        /* EIR queried services */
        if (num_uuids > 0) {
          uint16_t* p_uuid16 = (uint16_t*)uuid_list;
          std::vector<Uuid> uuid128_list;
          for (int i = 0; i < num_uuids; ++i) {
            Uuid uuid = Uuid::From16Bit(p_uuid16[i]);
            uuid128_list.push_back(uuid);
          }

          BTIF_STORAGE_FILL_PROPERTY(
              &properties[num_properties], BT_PROPERTY_UUIDS,
              num_uuids * Uuid::kNumBytes128, uuid128_list.data());
          num_properties++;
        }

        status =
            btif_storage_add_remote_device(&bdaddr, num_properties, properties);
        ASSERTC(status == BT_STATUS_SUCCESS,
+88 −1
Original line number Diff line number Diff line
use std::collections::HashMap;
use std::fmt::{Display, Formatter, Result};
use std::sync::{Arc, Mutex};

use num_traits::cast::FromPrimitive;
@@ -6,6 +7,7 @@ use num_traits::cast::FromPrimitive;
use crate::callbacks::BtGattCallback;
use crate::ClientContext;
use crate::{console_red, console_yellow, print_error, print_info};
use bt_topshim::btif::Uuid128Bit;
use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth};
use btstack::bluetooth_gatt::IBluetoothGatt;
use manager_service::iface_bluetooth_manager::IBluetoothManager;
@@ -34,6 +36,33 @@ pub(crate) struct CommandHandler {
    command_options: HashMap<String, CommandOption>,
}

struct DisplayList<T>(Vec<T>);

impl<T: Display> Display for DisplayList<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        let _ = write!(f, "[\n");
        for item in self.0.iter() {
            let _ = write!(f, "  {}\n", item);
        }

        write!(f, "]")
    }
}

struct DisplayUuid128Bit(Uuid128Bit);

// UUID128Bit should have a standard output display format
impl Display for DisplayUuid128Bit {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        write!(f, "{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}",
            self.0[0], self.0[1], self.0[2], self.0[3],
            self.0[4], self.0[5],
            self.0[6], self.0[7],
            self.0[8], self.0[9],
            self.0[10], self.0[11], self.0[12], self.0[13], self.0[14], self.0[15])
    }
}

fn enforce_arg_len<F>(args: &Vec<String>, min_len: usize, msg: &str, mut action: F)
where
    F: FnMut(),
@@ -83,6 +112,13 @@ fn build_commands() -> HashMap<String, CommandOption> {
            function_pointer: CommandHandler::cmd_bond,
        },
    );
    command_options.insert(
        String::from("device"),
        CommandOption {
            description: String::from("Take action on a remote device. (i.e. info)"),
            function_pointer: CommandHandler::cmd_device,
        },
    );
    command_options.insert(
        String::from("discovery"),
        CommandOption {
@@ -224,8 +260,20 @@ impl CommandHandler {
                    Some(x) => x.clone(),
                    None => String::from(""),
                };
                print_info!("State: {}", if enabled { "enabled" } else { "disabled" });
                let name = self.context.lock().unwrap().adapter_dbus.as_ref().unwrap().get_name();
                let uuids = self.context.lock().unwrap().adapter_dbus.as_ref().unwrap().get_uuids();
                print_info!("Address: {}", address);
                print_info!("Name: {}", name);
                print_info!("State: {}", if enabled { "enabled" } else { "disabled" });
                print_info!(
                    "Uuids: {}",
                    DisplayList(
                        uuids
                            .iter()
                            .map(|&x| DisplayUuid128Bit(x))
                            .collect::<Vec<DisplayUuid128Bit>>()
                    )
                );
            }
            _ => {
                println!("Invalid argument '{}'", args[0]);
@@ -284,6 +332,45 @@ impl CommandHandler {
        });
    }

    fn cmd_device(&mut self, args: &Vec<String>) {
        if !self.context.lock().unwrap().adapter_ready {
            self.adapter_not_ready();
            return;
        }

        enforce_arg_len(args, 2, "device <info> <address>", || match &args[0][0..] {
            "info" => {
                let device = BluetoothDevice {
                    address: String::from(&args[1]),
                    name: String::from("Classic Device"),
                };

                let uuids = self
                    .context
                    .lock()
                    .unwrap()
                    .adapter_dbus
                    .as_ref()
                    .unwrap()
                    .get_remote_uuids(device.clone());

                print_info!("Address: {}", &device.address);
                print_info!(
                    "Uuids: {}",
                    DisplayList(
                        uuids
                            .iter()
                            .map(|&x| DisplayUuid128Bit(x))
                            .collect::<Vec<DisplayUuid128Bit>>()
                    )
                );
            }
            _ => {
                println!("Invalid argument '{}'", args[0]);
            }
        });
    }

    fn cmd_gatt(&mut self, args: &Vec<String>) {
        if !self.context.lock().unwrap().adapter_ready {
            self.adapter_not_ready();
+42 −3
Original line number Diff line number Diff line
//! D-Bus proxy implementations of the APIs.

use bt_topshim::btif::BtSspVariant;
use bt_topshim::btif::{BtSspVariant, Uuid128Bit};
use bt_topshim::profiles::gatt::GattStatus;

use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback};
use btstack::bluetooth_gatt::{
    BluetoothGattCharacteristic, BluetoothGattDescriptor, BluetoothGattService,
    GattWriteRequestStatus, GattWriteType, IBluetoothGatt, IBluetoothGattCallback,
    IScannerCallback, LePhy, ScanFilter, ScanSettings, Uuid128Bit,
    IScannerCallback, LePhy, ScanFilter, ScanSettings,
};

use dbus::arg::{AppendAll, RefArg};
@@ -196,7 +196,7 @@ impl BluetoothDBus {
    }
}

// TODO: These are boilerplate codes, consider creating a macro to generate.
// TODO(b/200732080): These are boilerplate codes, consider creating a macro to generate.
impl IBluetooth for BluetoothDBus {
    fn register_callback(&mut self, callback: Box<dyn IBluetoothCallback + Send>) {
        let path_string = callback.get_object_id();
@@ -226,6 +226,19 @@ impl IBluetooth for BluetoothDBus {
        self.client_proxy.method("GetAddress", ())
    }

    fn get_uuids(&self) -> Vec<Uuid128Bit> {
        let result: Vec<Vec<u8>> = self.client_proxy.method("GetUuids", ());
        <Vec<Uuid128Bit> as DBusArg>::from_dbus(result, None, None, None).unwrap()
    }

    fn get_name(&self) -> String {
        self.client_proxy.method("GetName", ())
    }

    fn set_name(&self, name: String) -> bool {
        self.client_proxy.method("SetName", (name,))
    }

    fn start_discovery(&self) -> bool {
        self.client_proxy.method("StartDiscovery", ())
    }
@@ -234,6 +247,14 @@ impl IBluetooth for BluetoothDBus {
        self.client_proxy.method("CancelDiscovery", ())
    }

    fn is_discovering(&self) -> bool {
        self.client_proxy.method("IsDiscovering", ())
    }

    fn get_discovery_end_millis(&self) -> u64 {
        self.client_proxy.method("GetDiscoveryEndMillis", ())
    }

    fn create_bond(&self, device: BluetoothDevice, transport: BluetoothTransport) -> bool {
        self.client_proxy.method(
            "CreateBond",
@@ -260,6 +281,24 @@ impl IBluetooth for BluetoothDBus {
    fn get_bond_state(&self, device: BluetoothDevice) -> u32 {
        self.client_proxy.method("GetBondState", (BluetoothDevice::to_dbus(device).unwrap(),))
    }

    fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit> {
        let result: Vec<Vec<u8>> = self
            .client_proxy
            .method("GetRemoteUuids", (BluetoothDevice::to_dbus(device).unwrap(),));
        <Vec<Uuid128Bit> as DBusArg>::from_dbus(result, None, None, None).unwrap()
    }

    fn fetch_remote_uuids(&self, device: BluetoothDevice) -> bool {
        self.client_proxy.method("FetchRemoteUuids", (BluetoothDevice::to_dbus(device).unwrap(),))
    }

    fn sdp_search(&self, device: BluetoothDevice, uuid: Uuid128Bit) -> bool {
        self.client_proxy.method(
            "SdpSearch",
            (BluetoothDevice::to_dbus(device).unwrap(), Uuid128Bit::to_dbus(uuid).unwrap()),
        )
    }
}

#[dbus_propmap(AdapterWithEnabled)]
+41 −1
Original line number Diff line number Diff line
extern crate bt_shim;

use bt_topshim::btif::BtSspVariant;
use bt_topshim::btif::{BtSspVariant, Uuid128Bit};

use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback};
use btstack::RPCProxy;
@@ -78,6 +78,21 @@ impl IBluetooth for IBluetoothDBus {
        String::from("")
    }

    #[dbus_method("GetUuids")]
    fn get_uuids(&self) -> Vec<Uuid128Bit> {
        vec![]
    }

    #[dbus_method("GetName")]
    fn get_name(&self) -> String {
        String::new()
    }

    #[dbus_method("SetName")]
    fn set_name(&self, name: String) -> bool {
        true
    }

    #[dbus_method("StartDiscovery")]
    fn start_discovery(&self) -> bool {
        true
@@ -88,6 +103,16 @@ impl IBluetooth for IBluetoothDBus {
        true
    }

    #[dbus_method("IsDiscovering")]
    fn is_discovering(&self) -> bool {
        true
    }

    #[dbus_method("GetDiscoveryEndMillis")]
    fn get_discovery_end_millis(&self) -> u64 {
        0
    }

    #[dbus_method("CreateBond")]
    fn create_bond(&self, _device: BluetoothDevice, _transport: BluetoothTransport) -> bool {
        true
@@ -112,4 +137,19 @@ impl IBluetooth for IBluetoothDBus {
    fn get_bond_state(&self, _device: BluetoothDevice) -> u32 {
        0
    }

    #[dbus_method("GetRemoteUuids")]
    fn get_remote_uuids(&self, _device: BluetoothDevice) -> Vec<Uuid128Bit> {
        vec![]
    }

    #[dbus_method("FetchRemoteUuids")]
    fn fetch_remote_uuids(&self, _device: BluetoothDevice) -> bool {
        true
    }

    #[dbus_method("SdpSearch")]
    fn sdp_search(&self, _device: BluetoothDevice, _uuid: Uuid128Bit) -> bool {
        true
    }
}
+2 −2
Original line number Diff line number Diff line
use bt_topshim::profiles::gatt::GattStatus;
use bt_topshim::{btif::Uuid128Bit, profiles::gatt::GattStatus};

use btstack::bluetooth_gatt::{
    BluetoothGattCharacteristic, BluetoothGattDescriptor, BluetoothGattService,
    GattWriteRequestStatus, GattWriteType, IBluetoothGatt, IBluetoothGattCallback,
    IScannerCallback, LePhy, RSSISettings, ScanFilter, ScanSettings, ScanType, Uuid128Bit,
    IScannerCallback, LePhy, RSSISettings, ScanFilter, ScanSettings, ScanType,
};
use btstack::RPCProxy;

Loading