Commit da59bbd4 authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Commit Bot

[Bluetooth] Do not reverse BT address from HID ID

The ID from /sys/class/power_supply/hid-{btaddr}-battery is already in
the correct order so there is no need to reverse it. Tested with Apple
Magic Mouse.

Bug: b:161733238
Change-Id: Iad98f1ba016fee70f4fa9b2280f975dacf24bea4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2308855Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Sonny Sasaka <sonnysasaka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792335}
parent 297edd77
...@@ -19,7 +19,7 @@ namespace ash { ...@@ -19,7 +19,7 @@ namespace ash {
namespace { namespace {
const char kPath[] = "/sys/class/power_supply/hid-AA:BB:CC:DD:EE:FF-battery"; const char kPath[] = "/sys/class/power_supply/hid-AA:BB:CC:DD:EE:FF-battery";
const char kAddress[] = "ff:ee:dd:cc:bb:aa"; const char kAddress[] = "aa:bb:cc:dd:ee:ff";
const char kDeviceName[] = "test device"; const char kDeviceName[] = "test device";
} // namespace } // namespace
......
...@@ -53,11 +53,7 @@ std::string ExtractBluetoothAddressFromHIDBatteryPath(const std::string& path) { ...@@ -53,11 +53,7 @@ std::string ExtractBluetoothAddressFromHIDBatteryPath(const std::string& path) {
if (!RE2::FullMatch(identifier, kBluetoothAddressRegex)) if (!RE2::FullMatch(identifier, kBluetoothAddressRegex))
return std::string(); return std::string();
std::string reverse_address = base::ToLowerASCII(identifier); return base::ToLowerASCII(identifier);
std::vector<base::StringPiece> result = base::SplitStringPiece(
reverse_address, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
std::reverse(result.begin(), result.end());
return base::JoinString(result, ":");
} }
} // namespace ash } // namespace ash
...@@ -45,7 +45,7 @@ TEST_F(HidBatteryUtilTest, ExtractBluetoothAddressFromHIDBatteryPath) { ...@@ -45,7 +45,7 @@ TEST_F(HidBatteryUtilTest, ExtractBluetoothAddressFromHIDBatteryPath) {
ExtractBluetoothAddressFromHIDBatteryPath( ExtractBluetoothAddressFromHIDBatteryPath(
"/sys/class/power_supply/hid-A00:b1:C2:d3:E4:f5-battery")); "/sys/class/power_supply/hid-A00:b1:C2:d3:E4:f5-battery"));
EXPECT_EQ("f5:e4:d3:c2:b1:a0", EXPECT_EQ("a0:b1:c2:d3:e4:f5",
ExtractBluetoothAddressFromHIDBatteryPath( ExtractBluetoothAddressFromHIDBatteryPath(
"/sys/class/power_supply/hid-A0:b1:C2:d3:E4:f5-battery")); "/sys/class/power_supply/hid-A0:b1:C2:d3:E4:f5-battery"));
} }
......
...@@ -30,10 +30,10 @@ namespace { ...@@ -30,10 +30,10 @@ namespace {
// HID device. // HID device.
const char kTestBatteryPath[] = const char kTestBatteryPath[] =
"/sys/class/power_supply/hid-AA:BB:CC:DD:EE:FF-battery"; "/sys/class/power_supply/hid-AA:BB:CC:DD:EE:FF-battery";
const char kTestBatteryAddress[] = "ff:ee:dd:cc:bb:aa"; const char kTestBatteryAddress[] = "aa:bb:cc:dd:ee:ff";
const char kTestDeviceName[] = "test device"; const char kTestDeviceName[] = "test device";
const char kTestBatteryId[] = const char kTestBatteryId[] =
"battery_notification_bluetooth-ff:ee:dd:cc:bb:aa"; "battery_notification_bluetooth-aa:bb:cc:dd:ee:ff";
// Bluetooth devices. // Bluetooth devices.
const char kBluetoothDeviceAddress1[] = "aa:bb:cc:dd:ee:ff"; const char kBluetoothDeviceAddress1[] = "aa:bb:cc:dd:ee:ff";
...@@ -218,9 +218,9 @@ TEST_F(PeripheralBatteryNotifierTest, InvalidBatteryInfo) { ...@@ -218,9 +218,9 @@ TEST_F(PeripheralBatteryNotifierTest, InvalidBatteryInfo) {
TEST_F(PeripheralBatteryNotifierTest, ExtractBluetoothAddress) { TEST_F(PeripheralBatteryNotifierTest, ExtractBluetoothAddress) {
const std::string bluetooth_path = const std::string bluetooth_path =
"/sys/class/power_supply/hid-A0:b1:C2:d3:E4:f5-battery"; "/sys/class/power_supply/hid-A0:b1:C2:d3:E4:f5-battery";
const std::string expected_bluetooth_address = "f5:e4:d3:c2:b1:a0"; const std::string expected_bluetooth_address = "a0:b1:c2:d3:e4:f5";
const std::string expected_bluetooth_id = const std::string expected_bluetooth_id =
"battery_notification_bluetooth-f5:e4:d3:c2:b1:a0"; "battery_notification_bluetooth-a0:b1:c2:d3:e4:f5";
const std::string non_bluetooth_path = const std::string non_bluetooth_path =
"/sys/class/power_supply/hid-notbluetooth-battery"; "/sys/class/power_supply/hid-notbluetooth-battery";
......
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