Skip to content

Commit

Permalink
[Bluetooth] Expose BluetoothTransport via chrome.bluetooth.
Browse files Browse the repository at this point in the history
We plan to implement metrics which capture pairing success in
pairing dialogs, and need to know the transport type of the
pairing device at that moment, in order to understand if any
transport type is more problematic than others. This CL
exposes the transport type to the pairing dialogs.

Bug: 953149
Change-Id: Iea54a04e9f1828e872c5ae6d5e1a072275a22582
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1582968
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654528}
  • Loading branch information
Ryan Hansberry authored and Commit Bot committed Apr 26, 2019
1 parent 8bc95bc commit 16de3b1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
32 changes: 31 additions & 1 deletion extensions/browser/api/bluetooth/bluetooth_api_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_common.h"
#include "device/bluetooth/bluetooth_device.h"
#include "extensions/common/api/bluetooth.h"

namespace bluetooth = extensions::api::bluetooth;

using bluetooth::VendorIdSource;
using device::BluetoothDevice;
using device::BluetoothDeviceType;
using bluetooth::VendorIdSource;
#if defined(OS_LINUX)
using device::BluetoothTransport;
#endif

namespace {

Expand Down Expand Up @@ -86,6 +90,28 @@ bool ConvertDeviceTypeToApi(const BluetoothDeviceType& input,
}
}

#if defined(OS_LINUX)
bool ConvertTransportToApi(const BluetoothTransport& input,
bluetooth::Transport* output) {
switch (input) {
case BluetoothTransport::BLUETOOTH_TRANSPORT_INVALID:
*output = bluetooth::TRANSPORT_INVALID;
return true;
case BluetoothTransport::BLUETOOTH_TRANSPORT_CLASSIC:
*output = bluetooth::TRANSPORT_CLASSIC;
return true;
case BluetoothTransport::BLUETOOTH_TRANSPORT_LE:
*output = bluetooth::TRANSPORT_LE;
return true;
case BluetoothTransport::BLUETOOTH_TRANSPORT_DUAL:
*output = bluetooth::TRANSPORT_DUAL;
return true;
default:
return false;
}
}
#endif

} // namespace

namespace extensions {
Expand Down Expand Up @@ -132,6 +158,10 @@ void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device,
out->inquiry_tx_power.reset(new int(device.GetInquiryTxPower().value()));
else
out->inquiry_tx_power.reset();

#if defined(OS_LINUX)
ConvertTransportToApi(device.GetType(), &(out->transport));
#endif
}

void PopulateAdapterState(const device::BluetoothAdapter& adapter,
Expand Down
6 changes: 6 additions & 0 deletions extensions/common/api/bluetooth.idl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace bluetooth {
// Types for filtering bluetooth devices.
enum FilterType {all, known};

// Transport type of the bluetooth device.
enum Transport {invalid, classic, le, dual};

// Information about the state of the Bluetooth adapter.
dictionary AdapterState {
// The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'.
Expand Down Expand Up @@ -90,6 +93,9 @@ namespace bluetooth {
// that include this field in AD. It is avaliable and valid only during
// discovery.
long? inquiryTxPower;

// The transport type of the bluetooth device.
Transport? transport;
};

dictionary BluetoothFilter {
Expand Down
16 changes: 14 additions & 2 deletions third_party/closure_compiler/externs/bluetooth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -54,6 +54,17 @@ chrome.bluetooth.FilterType = {
KNOWN: 'known',
};

/**
* @enum {string}
* @see https://developer.chrome.com/extensions/bluetooth#type-Transport
*/
chrome.bluetooth.Transport = {
INVALID: 'invalid',
CLASSIC: 'classic',
LE: 'le',
DUAL: 'dual',
};

/**
* @typedef {{
* address: string,
Expand Down Expand Up @@ -82,7 +93,8 @@ chrome.bluetooth.AdapterState;
* connectable: (boolean|undefined),
* uuids: (!Array<string>|undefined),
* inquiryRssi: (number|undefined),
* inquiryTxPower: (number|undefined)
* inquiryTxPower: (number|undefined),
* transport: (!chrome.bluetooth.Transport|undefined)
* }}
* @see https://developer.chrome.com/extensions/bluetooth#type-Device
*/
Expand Down

0 comments on commit 16de3b1

Please sign in to comment.