diff --git a/dom/power/PowerManager.cpp b/dom/power/PowerManager.cpp index 77ee386e25de..58982e224c61 100644 --- a/dom/power/PowerManager.cpp +++ b/dom/power/PowerManager.cpp @@ -154,6 +154,18 @@ PowerManager::SetScreenEnabled(bool aEnabled) hal::SetScreenEnabled(aEnabled); } +bool +PowerManager::KeyLightEnabled() +{ + return hal::GetKeyLightEnabled(); +} + +void +PowerManager::SetKeyLightEnabled(bool aEnabled) +{ + hal::SetKeyLightEnabled(aEnabled); +} + double PowerManager::ScreenBrightness() { diff --git a/dom/power/PowerManager.h b/dom/power/PowerManager.h index 5ab6c6361efe..d84994018fb3 100644 --- a/dom/power/PowerManager.h +++ b/dom/power/PowerManager.h @@ -53,6 +53,8 @@ public: ErrorResult& aRv); bool ScreenEnabled(); void SetScreenEnabled(bool aEnabled); + bool KeyLightEnabled(); + void SetKeyLightEnabled(bool aEnabled); double ScreenBrightness(); void SetScreenBrightness(double aBrightness, ErrorResult& aRv); bool CpuSleepAllowed(); diff --git a/dom/power/test/mochitest.ini b/dom/power/test/mochitest.ini index 75176dbbb91f..1d1da9d9df04 100644 --- a/dom/power/test/mochitest.ini +++ b/dom/power/test/mochitest.ini @@ -12,3 +12,5 @@ skip-if = toolkit != "gonk" skip-if = toolkit != "gonk" [test_power_set_screen_enabled.html] skip-if = toolkit != "gonk" +[test_power_set_key_light_enabled.html] +skip-if = toolkit != "gonk" diff --git a/dom/power/test/test_power_set_key_light_enabled.html b/dom/power/test/test_power_set_key_light_enabled.html new file mode 100644 index 000000000000..96b9cc0db202 --- /dev/null +++ b/dom/power/test/test_power_set_key_light_enabled.html @@ -0,0 +1,64 @@ + + +
+ ++ ++ + diff --git a/dom/webidl/MozPowerManager.webidl b/dom/webidl/MozPowerManager.webidl index 4ab38858fd9a..04d75046d84e 100644 --- a/dom/webidl/MozPowerManager.webidl +++ b/dom/webidl/MozPowerManager.webidl @@ -49,6 +49,13 @@ interface MozPowerManager */ attribute boolean screenEnabled; + /** + * Is the device's keypad/button backlight enabled? Setting it to false will + * turn off the device's keypad/button backlight. And the brightness level + * is the same as |screenBrightness|. + */ + attribute boolean keyLightEnabled; + /** * How bright is the screen's backlight, on a scale from 0 (very dim) to 1 * (full brightness)? Setting this attribute modifies the screen's diff --git a/hal/Hal.cpp b/hal/Hal.cpp index 17c602d6b2bd..4617c562aa96 100644 --- a/hal/Hal.cpp +++ b/hal/Hal.cpp @@ -374,10 +374,22 @@ bool GetScreenEnabled() RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false); } -void SetScreenEnabled(bool enabled) +void SetScreenEnabled(bool aEnabled) { AssertMainThread(); - PROXY_IF_SANDBOXED(SetScreenEnabled(enabled)); + PROXY_IF_SANDBOXED(SetScreenEnabled(aEnabled)); +} + +bool GetKeyLightEnabled() +{ + AssertMainThread(); + RETURN_PROXY_IF_SANDBOXED(GetKeyLightEnabled(), false); +} + +void SetKeyLightEnabled(bool aEnabled) +{ + AssertMainThread(); + PROXY_IF_SANDBOXED(SetKeyLightEnabled(aEnabled)); } bool GetCpuSleepAllowed() @@ -390,10 +402,10 @@ bool GetCpuSleepAllowed() RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed(), true); } -void SetCpuSleepAllowed(bool allowed) +void SetCpuSleepAllowed(bool aAllowed) { AssertMainThread(); - PROXY_IF_SANDBOXED(SetCpuSleepAllowed(allowed)); + PROXY_IF_SANDBOXED(SetCpuSleepAllowed(aAllowed)); } double GetScreenBrightness() @@ -402,10 +414,10 @@ double GetScreenBrightness() RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness(), 0); } -void SetScreenBrightness(double brightness) +void SetScreenBrightness(double aBrightness) { AssertMainThread(); - PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(brightness, 0.0, 1.0))); + PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(aBrightness, 0.0, 1.0))); } bool SetLight(LightType light, const LightConfiguration& aConfig) diff --git a/hal/Hal.h b/hal/Hal.h index a01f4fe3cc28..6cce248a9f05 100644 --- a/hal/Hal.h +++ b/hal/Hal.h @@ -124,7 +124,17 @@ bool GetScreenEnabled(); * * Note that it may take a few seconds for the screen to turn on or off. */ -void SetScreenEnabled(bool enabled); +void SetScreenEnabled(bool aEnabled); + +/** + * Determine whether the device's keypad/button backlight is currently enabled. + */ +bool GetKeyLightEnabled(); + +/** + * Enable or disable the device's keypad/button backlight. + */ +void SetKeyLightEnabled(bool aEnabled); /** * Get the brightness of the device's screen's backlight, on a scale from 0 @@ -145,7 +155,7 @@ double GetScreenBrightness(); * followed by GetScreenBrightness(), the value returned by * GetScreenBrightness() may not be exactly x. */ -void SetScreenBrightness(double brightness); +void SetScreenBrightness(double aBrightness); /** * Determine whether the device is allowed to sleep. @@ -156,7 +166,7 @@ bool GetCpuSleepAllowed(); * Set whether the device is allowed to suspend automatically after * the screen is disabled. */ -void SetCpuSleepAllowed(bool allowed); +void SetCpuSleepAllowed(bool aAllowed); /** * Set the value of a light to a particular color, with a specific flash pattern. diff --git a/hal/fallback/FallbackScreenPower.cpp b/hal/fallback/FallbackScreenPower.cpp index 9dcde71588f5..72d843fd2498 100644 --- a/hal/fallback/FallbackScreenPower.cpp +++ b/hal/fallback/FallbackScreenPower.cpp @@ -14,7 +14,17 @@ GetScreenEnabled() } void -SetScreenEnabled(bool enabled) +SetScreenEnabled(bool aEnabled) +{} + +bool +GetKeyLightEnabled() +{ + return true; +} + +void +SetKeyLightEnabled(bool aEnabled) {} double @@ -24,7 +34,7 @@ GetScreenBrightness() } void -SetScreenBrightness(double brightness) +SetScreenBrightness(double aBrightness) {} } // hal_impl diff --git a/hal/gonk/GonkHal.cpp b/hal/gonk/GonkHal.cpp index c44516afc917..212d6be685ce 100644 --- a/hal/gonk/GonkHal.cpp +++ b/hal/gonk/GonkHal.cpp @@ -540,21 +540,53 @@ GetScreenEnabled() } void -SetScreenEnabled(bool enabled) +SetScreenEnabled(bool aEnabled) { - GetGonkDisplay()->SetEnabled(enabled); - sScreenEnabled = enabled; + GetGonkDisplay()->SetEnabled(aEnabled); + sScreenEnabled = aEnabled; +} + +bool +GetKeyLightEnabled() +{ + hal::LightConfiguration config; + hal_impl::GetLight(hal::eHalLightID_Buttons, &config); + return (config.color() != 0x00000000); +} + +void +SetKeyLightEnabled(bool aEnabled) +{ + hal::LightConfiguration config; + config.mode() = hal::eHalLightMode_User; + config.flash() = hal::eHalLightFlash_None; + config.flashOnMS() = config.flashOffMS() = 0; + config.color() = 0x00000000; + + if (aEnabled) { + // Convert the value in [0, 1] to an int between 0 and 255 and then convert + // it to a color. Note that the high byte is FF, corresponding to the alpha + // channel. + double brightness = GetScreenBrightness(); + uint32_t val = static_cast