Commit 639338ed authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Settings] Fix Bluetooth search results

Previously, we would always show settings search results for "Connect",
"Disconnect", "Pair", and "Unpair", even if there were no available
devices to perform those functions.

Now, we only show those search results if they are applicable. In
addition, this makes the search results seem much less noisy when
searching for "Bluetooth".

Fixed: 1094364
Change-Id: I88f22b3f11667a3aae66da469d4accf3526246e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255021Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781432}
parent e5e231ce
......@@ -17,6 +17,8 @@
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_ui_data_source.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/chromeos/bluetooth_utils.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/strings/grit/bluetooth_strings.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -28,64 +30,88 @@ namespace {
const std::vector<SearchConcept>& GetBluetoothSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_BLUETOOTH_PAIR,
{IDS_OS_SETTINGS_TAG_BLUETOOTH,
mojom::kBluetoothDevicesSubpagePath,
mojom::SearchResultIcon::kBluetooth,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kBluetoothPairDevice}},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_CONNECT,
mojom::SearchResultType::kSubpage,
{.subpage = mojom::Subpage::kBluetoothDevices}},
});
return *tags;
}
const std::vector<SearchConcept>& GetBluetoothOnSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_BLUETOOTH_TURN_OFF,
mojom::kBluetoothDevicesSubpagePath,
mojom::SearchResultIcon::kBluetooth,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kBluetoothConnectToDevice}},
{IDS_OS_SETTINGS_TAG_BLUETOOTH,
{.setting = mojom::Setting::kBluetoothOnOff},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_TURN_OFF_ALT1,
SearchConcept::kAltTagEnd}},
});
return *tags;
}
const std::vector<SearchConcept>& GetBluetoothOffSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_BLUETOOTH_TURN_ON,
mojom::kBluetoothDevicesSubpagePath,
mojom::SearchResultIcon::kBluetooth,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSubpage,
{.subpage = mojom::Subpage::kBluetoothDevices}},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_DISCONNECT,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kBluetoothOnOff},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_TURN_ON_ALT1, SearchConcept::kAltTagEnd}},
});
return *tags;
}
const std::vector<SearchConcept>& GetBluetoothConnectableSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_BLUETOOTH_CONNECT,
mojom::kBluetoothDevicesSubpagePath,
mojom::SearchResultIcon::kBluetooth,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kBluetoothDisconnectFromDevice}},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_UNPAIR,
{.setting = mojom::Setting::kBluetoothConnectToDevice}},
});
return *tags;
}
const std::vector<SearchConcept>& GetBluetoothConnectedSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_BLUETOOTH_DISCONNECT,
mojom::kBluetoothDevicesSubpagePath,
mojom::SearchResultIcon::kBluetooth,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kBluetoothUnpairDevice},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_UNPAIR_ALT1, SearchConcept::kAltTagEnd}},
{.setting = mojom::Setting::kBluetoothDisconnectFromDevice}},
});
return *tags;
}
const std::vector<SearchConcept>& GetBluetoothOnSearchConcepts() {
const std::vector<SearchConcept>& GetBluetoothPairableSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_BLUETOOTH_TURN_OFF,
{IDS_OS_SETTINGS_TAG_BLUETOOTH_PAIR,
mojom::kBluetoothDevicesSubpagePath,
mojom::SearchResultIcon::kBluetooth,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kBluetoothOnOff},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_TURN_OFF_ALT1,
SearchConcept::kAltTagEnd}},
{.setting = mojom::Setting::kBluetoothPairDevice}},
});
return *tags;
}
const std::vector<SearchConcept>& GetBluetoothOffSearchConcepts() {
const std::vector<SearchConcept>& GetBluetoothPairedSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_BLUETOOTH_TURN_ON,
{IDS_OS_SETTINGS_TAG_BLUETOOTH_UNPAIR,
mojom::kBluetoothDevicesSubpagePath,
mojom::SearchResultIcon::kBluetooth,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kBluetoothOnOff},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_TURN_ON_ALT1, SearchConcept::kAltTagEnd}},
{.setting = mojom::Setting::kBluetoothUnpairDevice},
{IDS_OS_SETTINGS_TAG_BLUETOOTH_UNPAIR_ALT1, SearchConcept::kAltTagEnd}},
});
return *tags;
}
......@@ -209,6 +235,21 @@ void BluetoothSection::AdapterPoweredChanged(device::BluetoothAdapter* adapter,
UpdateSearchTags();
}
void BluetoothSection::DeviceAdded(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
UpdateSearchTags();
}
void BluetoothSection::DeviceChanged(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
UpdateSearchTags();
}
void BluetoothSection::DeviceRemoved(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
UpdateSearchTags();
}
void BluetoothSection::OnFetchBluetoothAdapter(
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter) {
bluetooth_adapter_ = bluetooth_adapter;
......@@ -221,16 +262,54 @@ void BluetoothSection::UpdateSearchTags() {
registry()->RemoveSearchTags(GetBluetoothSearchConcepts());
registry()->RemoveSearchTags(GetBluetoothOnSearchConcepts());
registry()->RemoveSearchTags(GetBluetoothOffSearchConcepts());
registry()->RemoveSearchTags(GetBluetoothConnectableSearchConcepts());
registry()->RemoveSearchTags(GetBluetoothConnectedSearchConcepts());
registry()->RemoveSearchTags(GetBluetoothPairableSearchConcepts());
registry()->RemoveSearchTags(GetBluetoothPairedSearchConcepts());
if (!bluetooth_adapter_->IsPresent())
return;
registry()->AddSearchTags(GetBluetoothSearchConcepts());
if (bluetooth_adapter_->IsPowered())
registry()->AddSearchTags(GetBluetoothOnSearchConcepts());
else
if (!bluetooth_adapter_->IsPowered()) {
registry()->AddSearchTags(GetBluetoothOffSearchConcepts());
return;
}
registry()->AddSearchTags(GetBluetoothOnSearchConcepts());
// Filter devices so that only those shown in the UI are returned. Note that
// passing |max_devices| of 0 indicates that there is no maximum.
device::BluetoothAdapter::DeviceList devices =
device::FilterBluetoothDeviceList(bluetooth_adapter_->GetDevices(),
device::BluetoothFilterType::KNOWN,
/*max_devices=*/0);
bool connectable_device_exists = false;
bool connected_device_exists = false;
bool pairable_device_exists = false;
bool paired_device_exists = false;
for (const device::BluetoothDevice* device : devices) {
// Note: Device must be paired to be connectable.
if (device->IsPaired() && device->IsConnectable() && !device->IsConnected())
connectable_device_exists = true;
if (device->IsConnected())
connected_device_exists = true;
if (device->IsPairable() && !device->IsPaired())
pairable_device_exists = true;
if (device->IsPaired())
paired_device_exists = true;
}
if (connectable_device_exists)
registry()->AddSearchTags(GetBluetoothConnectableSearchConcepts());
if (connected_device_exists)
registry()->AddSearchTags(GetBluetoothConnectedSearchConcepts());
if (pairable_device_exists)
registry()->AddSearchTags(GetBluetoothPairableSearchConcepts());
if (paired_device_exists)
registry()->AddSearchTags(GetBluetoothPairedSearchConcepts());
}
} // namespace settings
......
......@@ -42,6 +42,12 @@ class BluetoothSection : public OsSettingsSection,
bool present) override;
void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
bool powered) override;
void DeviceAdded(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) override;
void DeviceChanged(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) override;
void DeviceRemoved(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) override;
void OnFetchBluetoothAdapter(
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment