Commit 7f0eb94d authored by Nikhil Athreya's avatar Nikhil Athreya Committed by Commit Bot

power: Add GetKeyboardBrightnessPercent

Adds a GetKeyboardBrightnessPercent method to the PowerManagerClient
interface. This method was added in order to track keyboard energy
consumption over time so that chrome://power could approximate power
usage of other devices over time.

keyboard brightness change as you increase and decrease your keyboard
brightness.

BUG: crbug.com/851767
TEST: Call this method inside Chrome on a Chrome OS device and see the
Change-Id: I35323708da1e0bcc9b4549b85ad6e2d8ad215af5
Reviewed-on: https://chromium-review.googlesource.com/1120839Reviewed-by: default avatarDan Erat <derat@chromium.org>
Commit-Queue: Nikhil Athreya <nathreya@google.com>
Cr-Commit-Position: refs/heads/master@{#572025}
parent 9ffdcdbf
......@@ -102,6 +102,13 @@ void FakePowerManagerClient::DecreaseKeyboardBrightness() {}
void FakePowerManagerClient::IncreaseKeyboardBrightness() {}
void FakePowerManagerClient::GetKeyboardBrightnessPercent(
DBusMethodCallback<double> callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), keyboard_brightness_percent_));
}
const base::Optional<power_manager::PowerSupplyProperties>&
FakePowerManagerClient::GetLastStatus() {
return props_;
......
......@@ -78,6 +78,8 @@ class CHROMEOS_EXPORT FakePowerManagerClient : public PowerManagerClient {
void GetScreenBrightnessPercent(DBusMethodCallback<double> callback) override;
void DecreaseKeyboardBrightness() override;
void IncreaseKeyboardBrightness() override;
void GetKeyboardBrightnessPercent(
DBusMethodCallback<double> callback) override;
const base::Optional<power_manager::PowerSupplyProperties>& GetLastStatus()
override;
void RequestStatusUpdate() override;
......@@ -164,6 +166,10 @@ class CHROMEOS_EXPORT FakePowerManagerClient : public PowerManagerClient {
screen_brightness_percent_ = percent;
}
void set_keyboard_brightness_percent(const base::Optional<double>& percent) {
keyboard_brightness_percent_ = percent;
}
private:
// Callback that will be run by asynchronous suspend delays to report
// readiness.
......@@ -193,6 +199,9 @@ class CHROMEOS_EXPORT FakePowerManagerClient : public PowerManagerClient {
// Current screen brightness in the range [0.0, 100.0].
base::Optional<double> screen_brightness_percent_;
// Current keyboard brightness in the range [0.0, 100.0].
base::Optional<double> keyboard_brightness_percent_;
// Last screen brightness requested via SetScreenBrightnessPercent().
// Unlike |screen_brightness_percent_|, this value will not be changed by
// SetBacklightsForcedOff() method - a method that implicitly changes screen
......
......@@ -228,7 +228,20 @@ class PowerManagerClientImpl : public PowerManagerClient {
power_manager::kGetScreenBrightnessPercentMethod);
power_manager_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&PowerManagerClientImpl::OnGetScreenBrightnessPercent,
base::BindOnce(
&PowerManagerClientImpl::OnGetScreenOrKeyboardBrightnessPercent,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetKeyboardBrightnessPercent(
DBusMethodCallback<double> callback) override {
dbus::MethodCall method_call(
power_manager::kPowerManagerInterface,
power_manager::kGetKeyboardBrightnessPercentMethod);
power_manager_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(
&PowerManagerClientImpl::OnGetScreenOrKeyboardBrightnessPercent,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
......@@ -648,13 +661,10 @@ class PowerManagerClientImpl : public PowerManagerClient {
}
}
void OnGetScreenBrightnessPercent(DBusMethodCallback<double> callback,
void OnGetScreenOrKeyboardBrightnessPercent(
DBusMethodCallback<double> callback,
dbus::Response* response) {
if (!response) {
if (!system::StatisticsProvider::GetInstance()->IsRunningOnVm()) {
POWER_LOG(ERROR) << "Error calling "
<< power_manager::kGetScreenBrightnessPercentMethod;
}
std::move(callback).Run(base::nullopt);
return;
}
......
......@@ -192,6 +192,11 @@ class CHROMEOS_EXPORT PowerManagerClient : public DBusClient {
// Increases the keyboard brightness.
virtual void IncreaseKeyboardBrightness() = 0;
// Similar to GetScreenBrightnessPercent, but gets the keyboard brightness
// instead.
virtual void GetKeyboardBrightnessPercent(
DBusMethodCallback<double> callback) = 0;
// Returns the last power status that was received from D-Bus, if any.
virtual const base::Optional<power_manager::PowerSupplyProperties>&
GetLastStatus() = 0;
......
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