Commit 8dbc2286 authored by Daniel Erat's avatar Daniel Erat Committed by Commit Bot

chromeos: Disable touchscreen for user inactivity.

Make TabletPowerButtonController disable the touchscreen
when powerd reports that the display was turned off
automatically (typically due to user inactivity).

This is intended to remove an inconsistency from the user's
perspective where the touchscreen turns the screen on when
the device is awake but in a screen-off state due to
inactivity, but doesn't wake the device when it's in S3
(i.e. suspended, asleep).

BUG=743291
TEST=manual: run set_short_powerd_timeouts, then:
     a) tap power button and verify touchscreen is disabled.
        after tapping power button again, screen turns on
        and touchscreen works.
     b) wait 20 seconds for screen to turn off due to
        inactivity and verify touchscreen is disabled. after
        hitting a key, screen turns on and touchscreen works
        again.
     c) manually decrease brightness to 0, wait five
        seconds, and then verify that touchscreen increases
        backlight brightness to min-visible level

Change-Id: I16c9769f587fe91bf2e6c3e68d06ccb83b299294
Reviewed-on: https://chromium-review.googlesource.com/572766Reviewed-by: default avatarQiang(Joe) Xu <warx@chromium.org>
Commit-Queue: Dan Erat <derat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487212}
parent fe8719e6
......@@ -178,7 +178,7 @@ void TabletPowerButtonController::OnPowerButtonEvent(
}
last_button_down_time_ = tick_clock_->NowTicks();
screen_off_when_power_button_down_ = brightness_level_is_zero_;
screen_off_when_power_button_down_ = screen_state_ != ScreenState::ON;
SetDisplayForcedOff(false);
StartShutdownTimer();
} else {
......@@ -244,7 +244,17 @@ void TabletPowerButtonController::PowerManagerRestarted() {
void TabletPowerButtonController::BrightnessChanged(int level,
bool user_initiated) {
brightness_level_is_zero_ = level == 0;
const ScreenState old_state = screen_state_;
if (level != 0)
screen_state_ = ScreenState::ON;
else
screen_state_ = user_initiated ? ScreenState::OFF : ScreenState::OFF_AUTO;
// Disable the touchscreen when the screen is turned off due to inactivity:
// https://crbug.com/743291
if ((screen_state_ == ScreenState::OFF_AUTO) !=
(old_state == ScreenState::OFF_AUTO))
UpdateTouchscreenStatus();
}
void TabletPowerButtonController::SuspendDone(
......@@ -446,8 +456,10 @@ void TabletPowerButtonController::OnGotInitialBacklightsForcedOff(
}
void TabletPowerButtonController::UpdateTouchscreenStatus() {
const bool enable_touchscreen =
!backlights_forced_off_ && (screen_state_ != ScreenState::OFF_AUTO);
ShellDelegate* delegate = Shell::Get()->shell_delegate();
delegate->SetTouchscreenEnabledInPrefs(!backlights_forced_off_,
delegate->SetTouchscreenEnabledInPrefs(enable_touchscreen,
true /* use_local_state */);
delegate->UpdateTouchscreenStatusFromPrefs();
}
......
......@@ -144,8 +144,20 @@ class ASH_EXPORT TabletPowerButtonController
// and locking is possible.
void LockScreenIfRequired();
// True if the brightness level is currently set to off.
bool brightness_level_is_zero_ = false;
// Screen state as communicated by D-Bus signals from powerd about backlight
// brightness changes.
enum class ScreenState {
// The screen is on.
ON,
// The screen is off.
OFF,
// The screen is off, specifically due to an automated change like user
// inactivity.
OFF_AUTO,
};
// Current screen state.
ScreenState screen_state_ = ScreenState::ON;
// Current forced-off state of backlights.
bool backlights_forced_off_ = false;
......
......@@ -408,7 +408,7 @@ TEST_F(TabletPowerButtonControllerTest, IgnorePowerOnKeyEvent) {
// Tests that under (1) tablet power button pressed/released, (2) keyboard/mouse
// events on laptop mode when screen is off, requesting/stopping backlights
// forced off should also set corresponding touchscreen state in local pref.
TEST_F(TabletPowerButtonControllerTest, TouchscreenState) {
TEST_F(TabletPowerButtonControllerTest, DisableTouchscreenWhileForcedOff) {
// Tests tablet power button.
ASSERT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
PressPowerButton();
......@@ -443,6 +443,23 @@ TEST_F(TabletPowerButtonControllerTest, TouchscreenState) {
EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
}
// When the screen is turned off automatically, the touchscreen should also be
// disabled.
TEST_F(TabletPowerButtonControllerTest, DisableTouchscreenForInactivity) {
ASSERT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
// Turn screen off for automated change (e.g. user is inactive).
power_manager_client_->SendBrightnessChanged(0, false);
EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, true);
EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
// After decreasing the brightness to zero for a user request, the touchscreen
// should remain enabled.
power_manager_client_->SendBrightnessChanged(0, true);
EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
}
// When user switches convertible device between laptop mode and tablet mode,
// power button may be pressed and held, which may cause unwanted shutdown.
TEST_F(TabletPowerButtonControllerTest,
......
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