Commit b951d0ec authored by Zentaro Kavanagh's avatar Zentaro Kavanagh Committed by Commit Bot

Add support for testing ambient color device support

- Adds SupportsAmbientColor() method to PowerManagerClient
- Corresponding platform change [1]

[1] - https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1825453

BUG=b/138731765
TEST=end to end

Change-Id: I43d1532dc121b3edef099dc81bc51964b8d89f0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1835170
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Auto-Submit: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704313}
parent b8a8603f
......@@ -279,6 +279,10 @@ void FakePowerManagerClient::UnblockSuspend(
--num_pending_suspend_readiness_callbacks_;
}
bool FakePowerManagerClient::SupportsAmbientColor() {
return supports_ambient_color_;
}
void FakePowerManagerClient::CreateArcTimers(
const std::string& tag,
std::vector<std::pair<clockid_t, base::ScopedFD>> arc_timer_requests,
......
......@@ -118,6 +118,7 @@ class COMPONENT_EXPORT(DBUS_POWER) FakePowerManagerClient
void BlockSuspend(const base::UnguessableToken& token,
const std::string& debug_info) override;
void UnblockSuspend(const base::UnguessableToken& token) override;
bool SupportsAmbientColor() override;
void CreateArcTimers(
const std::string& tag,
std::vector<std::pair<clockid_t, base::ScopedFD>> arc_timer_requests,
......@@ -190,6 +191,10 @@ class COMPONENT_EXPORT(DBUS_POWER) FakePowerManagerClient
keyboard_brightness_percent_ = percent;
}
void set_supports_ambient_color(bool supports_ambient_color) {
supports_ambient_color_ = supports_ambient_color;
}
// Sets |tick_clock| to |tick_clock_|.
void set_tick_clock(const base::TickClock* tick_clock) {
tick_clock_ = tick_clock;
......@@ -255,6 +260,10 @@ class COMPONENT_EXPORT(DBUS_POWER) FakePowerManagerClient
// explicitly by calling ApplyPendingScreenBrightnessChange().
bool enqueue_brightness_changes_on_backlights_forced_off_ = false;
// Whether the device has an ambient color sensor. Can be set via
// SetSupportsAmbientColor().
bool supports_ambient_color_ = false;
// Pending screen brightness changes caused by SetBacklightsForcedOff().
// ApplyPendingScreenBrightnessChange() applies the first pending change.
std::queue<power_manager::BacklightBrightnessChange>
......
......@@ -134,4 +134,13 @@ TEST(FakePowerManagerClientTest, NotifyObserversTest) {
EXPECT_FALSE(client.HasObserver(&test_observer));
}
TEST(FakePowerManagerClientTest, AmbientColorSupport) {
FakePowerManagerClient client;
EXPECT_FALSE(client.SupportsAmbientColor());
client.set_supports_ambient_color(true);
EXPECT_TRUE(client.SupportsAmbientColor());
client.set_supports_ambient_color(false);
EXPECT_FALSE(client.SupportsAmbientColor());
}
} // namespace chromeos
......@@ -211,6 +211,7 @@ class PowerManagerClientImpl : public PowerManagerClient {
RegisterSuspendDelays();
RequestStatusUpdate();
CheckAmbientColorSupport();
}
// PowerManagerClient overrides:
......@@ -481,6 +482,10 @@ class PowerManagerClientImpl : public PowerManagerClient {
MaybeReportSuspendReadiness();
}
bool SupportsAmbientColor() override {
return device_supports_ambient_color_;
}
void CreateArcTimers(
const std::string& tag,
std::vector<std::pair<clockid_t, base::ScopedFD>> arc_timer_requests,
......@@ -747,6 +752,31 @@ class PowerManagerClientImpl : public PowerManagerClient {
std::move(callback).Run(state);
}
void CheckAmbientColorSupport() {
dbus::MethodCall method_call(power_manager::kPowerManagerInterface,
power_manager::kHasAmbientColorDeviceMethod);
power_manager_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&PowerManagerClientImpl::OnHasAmbientColorDevice,
weak_ptr_factory_.GetWeakPtr()));
}
void OnHasAmbientColorDevice(dbus::Response* response) {
if (!response) {
device_supports_ambient_color_ = false;
return;
}
dbus::MessageReader reader(response);
bool is_supported = false;
if (!reader.PopBool(&is_supported)) {
POWER_LOG(ERROR) << "Error reading response from powerd: "
<< response->ToString();
device_supports_ambient_color_ = false;
return;
}
device_supports_ambient_color_ = is_supported;
}
void OnGetSwitchStates(DBusMethodCallback<SwitchStates> callback,
dbus::Response* response) {
if (!response) {
......@@ -1162,6 +1192,10 @@ class PowerManagerClientImpl : public PowerManagerClient {
// Last state passed to SetIsProjecting().
bool last_is_projecting_ = false;
// Whether the device supports ambient color. This value is checked when the
// DBUS service starts and is cached.
bool device_supports_ambient_color_ = false;
// The last proto received from D-Bus; initially empty.
base::Optional<power_manager::PowerSupplyProperties> proto_;
......
......@@ -291,6 +291,9 @@ class COMPONENT_EXPORT(DBUS_POWER) PowerManagerClient {
// ready for a suspend.
virtual void UnblockSuspend(const base::UnguessableToken& token) = 0;
// Whether the device supports Ambient color.
virtual bool SupportsAmbientColor() = 0;
// Creates timers corresponding to clocks present in |arc_timer_requests|.
// ScopedFDs are used to indicate timer expiration as described in
// |StartArcTimer|. Aysnchronously runs |callback| with the created timers'
......
......@@ -241,6 +241,11 @@ class PowerManagerClientTest : public testing::Test {
*proxy_,
DoCallMethod(HasMember(power_manager::kGetPowerSupplyPropertiesMethod),
_, _));
// Init will test for the presence of an ambient light sensor.
EXPECT_CALL(
*proxy_,
DoCallMethod(HasMember(power_manager::kHasAmbientColorDeviceMethod), _,
_));
PowerManagerClient::Initialize(bus_.get());
client_ = PowerManagerClient::Get();
......
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