Commit b44c414b authored by derat@chromium.org's avatar derat@chromium.org

chromeos: Ignore power button presses when screen is off.

Make PowerButtonController ignore power button events when
the screen is turned off -- if the user hits the power
button to turn the screen back on, we don't want to lock or
shutdown if they hold it a bit too long.

BUG=128451
TEST=added, also did manual testing


Review URL: https://chromiumcodereview.appspot.com/10382211

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137679 0039d316-1c4b-4281-b951-d872f2087c98
parent 1d0475b9
...@@ -285,6 +285,7 @@ PowerButtonController::PowerButtonController() ...@@ -285,6 +285,7 @@ PowerButtonController::PowerButtonController()
unlocked_login_status_(user::LOGGED_IN_NONE), unlocked_login_status_(user::LOGGED_IN_NONE),
power_button_down_(false), power_button_down_(false),
lock_button_down_(false), lock_button_down_(false),
screen_is_off_(false),
shutting_down_(false), shutting_down_(false),
has_legacy_power_button_( has_legacy_power_button_(
CommandLine::ForCurrentProcess()->HasSwitch( CommandLine::ForCurrentProcess()->HasSwitch(
...@@ -345,6 +346,10 @@ void PowerButtonController::OnLockStateChanged(bool locked) { ...@@ -345,6 +346,10 @@ void PowerButtonController::OnLockStateChanged(bool locked) {
} }
} }
void PowerButtonController::OnScreenBrightnessChanged(double percent) {
screen_is_off_ = percent <= 0.001;
}
void PowerButtonController::OnStartingLock() { void PowerButtonController::OnStartingLock() {
if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED)
return; return;
...@@ -368,6 +373,11 @@ void PowerButtonController::OnPowerButtonEvent( ...@@ -368,6 +373,11 @@ void PowerButtonController::OnPowerButtonEvent(
if (shutting_down_) if (shutting_down_)
return; return;
// Avoid starting the lock/shutdown sequence if the power button is pressed
// while the screen is off (http://crbug.com/128451).
if (screen_is_off_)
return;
if (has_legacy_power_button_) { if (has_legacy_power_button_) {
// If power button releases won't get reported correctly because we're not // If power button releases won't get reported correctly because we're not
// running on official hardware, just lock the screen or shut down // running on official hardware, just lock the screen or shut down
......
...@@ -142,6 +142,9 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, ...@@ -142,6 +142,9 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver,
has_legacy_power_button_ = legacy; has_legacy_power_button_ = legacy;
} }
// Called when the current screen brightness changes.
void OnScreenBrightnessChanged(double percent);
// Called when Chrome gets a request to display the lock screen. // Called when Chrome gets a request to display the lock screen.
void OnStartingLock(); void OnStartingLock();
...@@ -203,6 +206,9 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, ...@@ -203,6 +206,9 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver,
bool power_button_down_; bool power_button_down_;
bool lock_button_down_; bool lock_button_down_;
// Is the screen currently turned off?
bool screen_is_off_;
// Are we in the process of shutting the machine down? // Are we in the process of shutting the machine down?
bool shutting_down_; bool shutting_down_;
......
...@@ -539,5 +539,22 @@ TEST_F(PowerButtonControllerTest, ResizeBackgroundLayer) { ...@@ -539,5 +539,22 @@ TEST_F(PowerButtonControllerTest, ResizeBackgroundLayer) {
test_api_->GetBackgroundLayerBounds().ToString()); test_api_->GetBackgroundLayerBounds().ToString());
} }
// Test that we ignore power button presses when the screen is turned off.
TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) {
controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
// When the screen brightness is at 0%, we shouldn't do anything in response
// to power button presses.
controller_->OnScreenBrightnessChanged(0.0);
controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
EXPECT_FALSE(test_api_->lock_timer_is_running());
// After increasing the brightness to 10%, we should start the timer like
// usual.
controller_->OnScreenBrightnessChanged(10.0);
controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
EXPECT_TRUE(test_api_->lock_timer_is_running());
}
} // namespace test } // namespace test
} // namespace ash } // namespace ash
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/power/brightness_observer.h" #include "chrome/browser/chromeos/power/brightness_observer.h"
#include "ash/shell.h"
#include "ash/wm/power_button_controller.h"
#include "chrome/browser/extensions/system/system_api.h" #include "chrome/browser/extensions/system/system_api.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
...@@ -19,6 +21,8 @@ BrightnessObserver::~BrightnessObserver() { ...@@ -19,6 +21,8 @@ BrightnessObserver::~BrightnessObserver() {
void BrightnessObserver::BrightnessChanged(int level, bool user_initiated) { void BrightnessObserver::BrightnessChanged(int level, bool user_initiated) {
extensions::DispatchBrightnessChangedEvent(level, user_initiated); extensions::DispatchBrightnessChangedEvent(level, user_initiated);
ash::Shell::GetInstance()->power_button_controller()->
OnScreenBrightnessChanged(static_cast<double>(level));
} }
} // namespace chromeos } // namespace chromeos
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
namespace chromeos { namespace chromeos {
// This observer displays a bubble at the bottom of the screen showing the // This observer listens for changes to the screen brightness and notifies
// current brightness level whenever the user changes it. // extensions and ash::PowerButtonController about them.
class BrightnessObserver : public PowerManagerClient::Observer { class BrightnessObserver : public PowerManagerClient::Observer {
public: public:
// This class registers/unregisters itself as an observer in ctor/dtor. // This class registers/unregisters itself as an observer in ctor/dtor.
......
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