1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_BLUETOOTH_CHROMEOS_BLUETOOTH_UTILS_H_
#define DEVICE_BLUETOOTH_CHROMEOS_BLUETOOTH_UTILS_H_
#include <optional>
#include "components/prefs/pref_service.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_export.h"
namespace base {
class TimeDelta;
} // namespace base
// This file contains common utilities, including filtering bluetooth devices
// based on the filter criteria.
namespace device {
enum class BluetoothFilterType {
// No filtering, all bluetooth devices will be returned.
ALL = 0,
// Return bluetooth devices that are known to the UI.
// I.e. bluetooth device type != UNKNOWN
KNOWN,
};
enum class DeviceSelectionUISurfaces {
kSettings,
kSystemTray,
};
enum class PoweredStateOperation {
kEnable,
kDisable,
};
enum class UserInitiatedReconnectionUISurfaces {
kSettings,
kSystemTray,
};
// This enum is tied directly to a UMA enum defined in
// //tools/metrics/histograms/metadata/bluetooth/enums.xml, and should always
// reflect it (do not change one without changing the other).
enum class ConnectionFailureReason {
kUnknownError = 0,
kSystemError = 1,
kAuthFailed = 2,
kAuthTimeout = 3,
kFailed = 4,
kUnknownConnectionError = 5,
kUnsupportedDevice = 6,
kNotConnectable = 7,
kAuthCanceled = 8,
kAuthRejected = 9,
kInprogress = 10,
kNotFound = 11,
kBluetoothDisabled = 12,
kDeviceNotReady = 13,
kAlreadyConnected = 14,
kDeviceAlreadyExists = 15,
kInvalidArgs = 16,
kNonAuthTimeout = 17,
kNoMemory = 18,
kJniEnvironment = 19,
kJniThreadAttach = 20,
kWakelock = 21,
kUnexpectedState = 22,
kSocketError = 23,
kMaxValue = kSocketError
};
// This enum is tied directly to a UMA enum defined in
// //tools/metrics/histograms/enums.xml, and should always reflect it (do not
// change one without changing the other).
enum class BluetoothUiSurface {
kSettingsDeviceListSubpage = 0,
kSettingsDeviceDetailSubpage = 1,
kSettingsPairingDialog = 2,
kBluetoothQuickSettings = 3,
kStandalonePairingDialog = 4,
// [Deprecated] kPairedNotification = 5,
kConnectionToast = 6,
kDisconnectedToast = 7,
kOobeHidDetection = 8,
kPairedToast = 9,
kMaxValue = kPairedToast
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class ForgetResult {
kFailure = 0,
kSuccess = 1,
kMaxValue = kSuccess,
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class DisconnectResult {
kFailure = 0,
kSuccess = 1,
kMaxValue = kSuccess
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SetNicknameResult {
kInvalidNicknameFormat = 0,
kDeviceNotFound = 1,
kPrefsUnavailable = 2,
kSuccess = 3,
kMaxValue = kSuccess,
};
// This enum is tied directly to a UMA enum defined in
// //tools/metrics/histograms/enums.xml, and should always reflect it (do not
// change one without changing the other).
enum class BluetoothTransportType {
kUnknown = 0,
kClassic = 1,
kLE = 2,
kDual = 3,
kInvalid = 4,
kMaxValue = kInvalid
};
// Converts ConnectErrorCode to ConnectionFailureReason.
DEVICE_BLUETOOTH_EXPORT ConnectionFailureReason GetConnectionFailureReason(
device::BluetoothDevice::ConnectErrorCode error_code);
// Return filtered devices based on the filter type and max number of devices.
DEVICE_BLUETOOTH_EXPORT device::BluetoothAdapter::DeviceList
FilterBluetoothDeviceList(const BluetoothAdapter::DeviceList& devices,
BluetoothFilterType filter_type,
int max_devices);
// Returns |true| if the device is unsupported and should not be known by the
// UI.
DEVICE_BLUETOOTH_EXPORT bool IsUnsupportedDevice(
const device::BluetoothDevice* device);
// Record outcome of user attempting to pair to a device.
DEVICE_BLUETOOTH_EXPORT void RecordPairingResult(
std::optional<ConnectionFailureReason> failure_reason,
BluetoothTransport transport,
base::TimeDelta duration);
// Record outcome of user attempting to reconnect to a previously paired device.
DEVICE_BLUETOOTH_EXPORT void RecordUserInitiatedReconnectionAttemptResult(
std::optional<ConnectionFailureReason> failure_reason,
UserInitiatedReconnectionUISurfaces surface);
// Record how long it took for a user to find and select the device they wished
// to connect to.
DEVICE_BLUETOOTH_EXPORT void RecordDeviceSelectionDuration(
base::TimeDelta duration,
DeviceSelectionUISurfaces surface,
bool was_paired,
BluetoothTransport transport);
// Record the result of device's Bluetooth being powered on or off.
DEVICE_BLUETOOTH_EXPORT void RecordPoweredStateOperationResult(
PoweredStateOperation operation,
bool success);
// Record each time the local device's Bluetooth is powered on or off.
DEVICE_BLUETOOTH_EXPORT void RecordPoweredState(bool is_powered);
// Record each time a device forget attempt completes.
DEVICE_BLUETOOTH_EXPORT void RecordForgetResult(ForgetResult forget_result);
// Records each bluetooth device disconnect.
DEVICE_BLUETOOTH_EXPORT void RecordDeviceDisconnect(
BluetoothDeviceType device_type);
// Record the result of each user initiated bluetooth device disconnect attempt.
DEVICE_BLUETOOTH_EXPORT void RecordUserInitiatedDisconnectResult(
DisconnectResult disconnect_result,
BluetoothTransport transport);
// Record each time a bluetooth UI surface is displayed.
DEVICE_BLUETOOTH_EXPORT void RecordUiSurfaceDisplayed(
BluetoothUiSurface ui_surface);
// Record how long it took for an attempted user initiated bluetooth device
// reconnection to occur.
DEVICE_BLUETOOTH_EXPORT void RecordUserInitiatedReconnectionAttemptDuration(
std::optional<ConnectionFailureReason> failure_reason,
BluetoothTransport transport,
base::TimeDelta duration);
// Record each time a Bluetooth device nickname change is attempted.
DEVICE_BLUETOOTH_EXPORT void RecordSetDeviceNickName(SetNicknameResult success);
// Record the time interval between consecutive bluetooth connections.
DEVICE_BLUETOOTH_EXPORT void RecordTimeIntervalBetweenConnections(
base::TimeDelta time_interval_since_last_connection);
// Record the number of times the connection toast is shown to user in the
// last 24 hours.
DEVICE_BLUETOOTH_EXPORT void MaybeRecordConnectionToastShownCount(
PrefService* local_state_pref,
bool triggered_by_connect);
DEVICE_BLUETOOTH_EXPORT void RecordFlossManagerClientInit(
bool success,
base::TimeDelta duration);
// Record each time a Bluetooth device has missing keys
DEVICE_BLUETOOTH_EXPORT void RecordDeviceKeyMissing();
} // namespace device
#endif // DEVICE_BLUETOOTH_CHROMEOS_BLUETOOTH_UTILS_H_
|