Commit 6039e11b authored by En-Shuo Hsu's avatar En-Shuo Hsu Committed by Commit Bot

cras: Add ResendBluetoothBattery

Added a new method for chrome to ask CRAS to resend Bluetooth battery
for cases that the battery level is cleaned. Ex: User logout.

BUG=b:166530001
TEST=build chrome and run unit_tests

Change-Id: Ie11da0787f0137f7c33089057d5233ad00bdf500
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2395876Reviewed-by: default avatarHsinyu Chao <hychao@chromium.org>
Commit-Queue: En-Shuo Hsu <enshuo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806044}
parent e3c7dd4d
...@@ -859,6 +859,10 @@ void CrasAudioHandler::BluetoothBatteryChanged(const std::string& address, ...@@ -859,6 +859,10 @@ void CrasAudioHandler::BluetoothBatteryChanged(const std::string& address,
observer.OnBluetoothBatteryChanged(address, level); observer.OnBluetoothBatteryChanged(address, level);
} }
void CrasAudioHandler::ResendBluetoothBattery() {
CrasAudioClient::Get()->ResendBluetoothBattery();
}
void CrasAudioHandler::OnAudioPolicyPrefChanged() { void CrasAudioHandler::OnAudioPolicyPrefChanged() {
ApplyAudioPolicy(); ApplyAudioPolicy();
} }
......
...@@ -322,6 +322,11 @@ class COMPONENT_EXPORT(CHROMEOS_AUDIO) CrasAudioHandler ...@@ -322,6 +322,11 @@ class COMPONENT_EXPORT(CHROMEOS_AUDIO) CrasAudioHandler
// returned. // returned.
int32_t system_aec_group_id() const; int32_t system_aec_group_id() const;
// Asks CRAS to resend BluetoothBatteryChanged signal, used in cases when
// Chrome cleans up the stored battery information but still has the device
// connected afterward. For example: User logout.
void ResendBluetoothBattery();
protected: protected:
CrasAudioHandler( CrasAudioHandler(
mojo::PendingRemote<media_session::mojom::MediaControllerManager> mojo::PendingRemote<media_session::mojom::MediaControllerManager>
......
...@@ -419,6 +419,14 @@ class CrasAudioClientImpl : public CrasAudioClient { ...@@ -419,6 +419,14 @@ class CrasAudioClientImpl : public CrasAudioClient {
base::DoNothing()); base::DoNothing());
} }
void ResendBluetoothBattery() override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kResendBluetoothBattery);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void WaitForServiceToBeAvailable( void WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) override { WaitForServiceToBeAvailableCallback callback) override {
cras_proxy_->WaitForServiceToBeAvailable(std::move(callback)); cras_proxy_->WaitForServiceToBeAvailable(std::move(callback));
......
...@@ -187,6 +187,9 @@ class COMPONENT_EXPORT(DBUS_AUDIO) CrasAudioClient { ...@@ -187,6 +187,9 @@ class COMPONENT_EXPORT(DBUS_AUDIO) CrasAudioClient {
virtual void SetPlayerMetadata( virtual void SetPlayerMetadata(
const std::map<std::string, std::string>& metadata) = 0; const std::map<std::string, std::string>& metadata) = 0;
// Asks Cras to resend battery level for Bluetooth device if exists .
virtual void ResendBluetoothBattery() = 0;
// Runs the callback as soon as the service becomes available. // Runs the callback as soon as the service becomes available.
virtual void WaitForServiceToBeAvailable( virtual void WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) = 0; WaitForServiceToBeAvailableCallback callback) = 0;
......
...@@ -1262,4 +1262,18 @@ TEST_F(CrasAudioClientTest, SetPlayerMetadata) { ...@@ -1262,4 +1262,18 @@ TEST_F(CrasAudioClientTest, SetPlayerMetadata) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
TEST_F(CrasAudioClientTest, ResendBluetoothBattery) {
// Create response.
std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
// Set expectations.
PrepareForMethodCall(cras::kResendBluetoothBattery,
base::BindRepeating(&ExpectNoArgument), response.get());
// Call method.
client()->ResendBluetoothBattery();
// Run the message loop.
base::RunLoop().RunUntilIdle();
}
} // namespace chromeos } // namespace chromeos
...@@ -247,6 +247,11 @@ void FakeCrasAudioClient::AddActiveOutputNode(uint64_t node_id) { ...@@ -247,6 +247,11 @@ void FakeCrasAudioClient::AddActiveOutputNode(uint64_t node_id) {
} }
} }
void FakeCrasAudioClient::ResendBluetoothBattery() {
for (auto& observer : observers_)
observer.BluetoothBatteryChanged("11:22:33:44:55:66", battery_level_);
}
void FakeCrasAudioClient::WaitForServiceToBeAvailable( void FakeCrasAudioClient::WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) { WaitForServiceToBeAvailableCallback callback) {
std::move(callback).Run(true); std::move(callback).Run(true);
...@@ -303,6 +308,10 @@ void FakeCrasAudioClient::NotifyHotwordTriggeredForTesting(uint64_t tv_sec, ...@@ -303,6 +308,10 @@ void FakeCrasAudioClient::NotifyHotwordTriggeredForTesting(uint64_t tv_sec,
observer.HotwordTriggered(tv_sec, tv_nsec); observer.HotwordTriggered(tv_sec, tv_nsec);
} }
void FakeCrasAudioClient::SetBluetoothBattteryLevelForTesting(uint32_t level) {
battery_level_ = level;
}
AudioNodeList::iterator FakeCrasAudioClient::FindNode(uint64_t node_id) { AudioNodeList::iterator FakeCrasAudioClient::FindNode(uint64_t node_id) {
return std::find_if( return std::find_if(
node_list_.begin(), node_list_.end(), node_list_.begin(), node_list_.end(),
......
...@@ -59,6 +59,7 @@ class COMPONENT_EXPORT(DBUS_AUDIO) FakeCrasAudioClient ...@@ -59,6 +59,7 @@ class COMPONENT_EXPORT(DBUS_AUDIO) FakeCrasAudioClient
void SetPlayerDuration(const int64_t& duration) override; void SetPlayerDuration(const int64_t& duration) override;
void SetPlayerMetadata( void SetPlayerMetadata(
const std::map<std::string, std::string>& metadata) override; const std::map<std::string, std::string>& metadata) override;
void ResendBluetoothBattery() override;
void WaitForServiceToBeAvailable( void WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) override; WaitForServiceToBeAvailableCallback callback) override;
...@@ -83,6 +84,9 @@ class COMPONENT_EXPORT(DBUS_AUDIO) FakeCrasAudioClient ...@@ -83,6 +84,9 @@ class COMPONENT_EXPORT(DBUS_AUDIO) FakeCrasAudioClient
// Generates fake hotword signal for HotwordTriggered. // Generates fake hotword signal for HotwordTriggered.
void NotifyHotwordTriggeredForTesting(uint64_t tv_sec, uint64_t tv_nsec); void NotifyHotwordTriggeredForTesting(uint64_t tv_sec, uint64_t tv_nsec);
// Set a mock battery level for ResendBatteryLevel.
void SetBluetoothBattteryLevelForTesting(uint32_t level);
const AudioNodeList& node_list() const { return node_list_; } const AudioNodeList& node_list() const { return node_list_; }
const uint64_t& active_input_node_id() const { return active_input_node_id_; } const uint64_t& active_input_node_id() const { return active_input_node_id_; }
const uint64_t& active_output_node_id() const { const uint64_t& active_output_node_id() const {
...@@ -103,6 +107,7 @@ class COMPONENT_EXPORT(DBUS_AUDIO) FakeCrasAudioClient ...@@ -103,6 +107,7 @@ class COMPONENT_EXPORT(DBUS_AUDIO) FakeCrasAudioClient
// By default, immediately sends OutputNodeVolumeChange signal following the // By default, immediately sends OutputNodeVolumeChange signal following the
// SetOutputNodeVolume fake dbus call. // SetOutputNodeVolume fake dbus call.
bool notify_volume_change_with_delay_ = false; bool notify_volume_change_with_delay_ = false;
uint32_t battery_level_ = 0;
base::ObserverList<Observer>::Unchecked observers_; base::ObserverList<Observer>::Unchecked observers_;
DISALLOW_COPY_AND_ASSIGN(FakeCrasAudioClient); DISALLOW_COPY_AND_ASSIGN(FakeCrasAudioClient);
......
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