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 @@ + + + + + Test Enabling/Disabling Screen with Power Management API + + + + +

+ +
+  
+
+ + 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(round(brightness * 255.0)); + uint32_t color = (0xff<<24) + (val<<16) + (val<<8) + val; + + config.color() = color; + } + + hal_impl::SetLight(hal::eHalLightID_Buttons, config); + hal_impl::SetLight(hal::eHalLightID_Keyboard, config); } double GetScreenBrightness() { - hal::LightConfiguration aConfig; + hal::LightConfiguration config; hal::LightType light = hal::eHalLightID_Backlight; - hal::GetLight(light, &aConfig); + hal_impl::GetLight(light, &config); // backlight is brightness only, so using one of the RGB elements as value. - int brightness = aConfig.color() & 0xFF; + int brightness = config.color() & 0xFF; return brightness / 255.0; } @@ -571,16 +603,19 @@ SetScreenBrightness(double brightness) // Convert the value in [0, 1] to an int between 0 and 255 and convert to a color // note that the high byte is FF, corresponding to the alpha channel. - int val = static_cast(round(brightness * 255)); + uint32_t val = static_cast(round(brightness * 255.0)); uint32_t color = (0xff<<24) + (val<<16) + (val<<8) + val; - hal::LightConfiguration aConfig; - aConfig.mode() = hal::eHalLightMode_User; - aConfig.flash() = hal::eHalLightFlash_None; - aConfig.flashOnMS() = aConfig.flashOffMS() = 0; - aConfig.color() = color; - hal::SetLight(hal::eHalLightID_Backlight, aConfig); - hal::SetLight(hal::eHalLightID_Buttons, aConfig); + hal::LightConfiguration config; + config.mode() = hal::eHalLightMode_User; + config.flash() = hal::eHalLightFlash_None; + config.flashOnMS() = config.flashOffMS() = 0; + config.color() = color; + hal_impl::SetLight(hal::eHalLightID_Backlight, config); + if (GetKeyLightEnabled()) { + hal_impl::SetLight(hal::eHalLightID_Buttons, config); + hal_impl::SetLight(hal::eHalLightID_Keyboard, config); + } } static Monitor* sInternalLockCpuMonitor = nullptr; diff --git a/hal/sandbox/PHal.ipdl b/hal/sandbox/PHal.ipdl index 41f75a7d07f6..91fa8e97f44f 100644 --- a/hal/sandbox/PHal.ipdl +++ b/hal/sandbox/PHal.ipdl @@ -127,13 +127,16 @@ parent: returns (NetworkInformation aNetworkInfo); sync GetScreenEnabled() returns (bool enabled); - SetScreenEnabled(bool enabled); + SetScreenEnabled(bool aEnabled); + + sync GetKeyLightEnabled() returns (bool enabled); + SetKeyLightEnabled(bool aEnabled); sync GetCpuSleepAllowed() returns (bool allowed); - SetCpuSleepAllowed(bool allowed); + SetCpuSleepAllowed(bool aAllowed); sync GetScreenBrightness() returns (double brightness); - SetScreenBrightness(double brightness); + SetScreenBrightness(double aBrightness); AdjustSystemClock(int64_t aDeltaMilliseconds); SetTimezone(nsCString aTimezoneSpec); diff --git a/hal/sandbox/SandboxHal.cpp b/hal/sandbox/SandboxHal.cpp index e027bd88140b..f5e0166b433a 100644 --- a/hal/sandbox/SandboxHal.cpp +++ b/hal/sandbox/SandboxHal.cpp @@ -143,9 +143,23 @@ GetScreenEnabled() } void -SetScreenEnabled(bool enabled) +SetScreenEnabled(bool aEnabled) { - Hal()->SendSetScreenEnabled(enabled); + Hal()->SendSetScreenEnabled(aEnabled); +} + +bool +GetKeyLightEnabled() +{ + bool enabled = false; + Hal()->SendGetKeyLightEnabled(&enabled); + return enabled; +} + +void +SetKeyLightEnabled(bool aEnabled) +{ + Hal()->SendSetKeyLightEnabled(aEnabled); } bool @@ -157,9 +171,9 @@ GetCpuSleepAllowed() } void -SetCpuSleepAllowed(bool allowed) +SetCpuSleepAllowed(bool aAllowed) { - Hal()->SendSetCpuSleepAllowed(allowed); + Hal()->SendSetCpuSleepAllowed(aAllowed); } double @@ -171,9 +185,9 @@ GetScreenBrightness() } void -SetScreenBrightness(double brightness) +SetScreenBrightness(double aBrightness) { - Hal()->SendSetScreenBrightness(brightness); + Hal()->SendSetScreenBrightness(aBrightness); } bool @@ -591,62 +605,82 @@ public: } virtual bool - RecvGetScreenEnabled(bool *enabled) MOZ_OVERRIDE + RecvGetScreenEnabled(bool* aEnabled) MOZ_OVERRIDE { if (!AssertAppProcessPermission(this, "power")) { return false; } - *enabled = hal::GetScreenEnabled(); + *aEnabled = hal::GetScreenEnabled(); return true; } virtual bool - RecvSetScreenEnabled(const bool &enabled) MOZ_OVERRIDE + RecvSetScreenEnabled(const bool& aEnabled) MOZ_OVERRIDE { if (!AssertAppProcessPermission(this, "power")) { return false; } - hal::SetScreenEnabled(enabled); + hal::SetScreenEnabled(aEnabled); return true; } virtual bool - RecvGetCpuSleepAllowed(bool *allowed) MOZ_OVERRIDE + RecvGetKeyLightEnabled(bool* aEnabled) MOZ_OVERRIDE { if (!AssertAppProcessPermission(this, "power")) { return false; } - *allowed = hal::GetCpuSleepAllowed(); + *aEnabled = hal::GetKeyLightEnabled(); return true; } virtual bool - RecvSetCpuSleepAllowed(const bool &allowed) MOZ_OVERRIDE + RecvSetKeyLightEnabled(const bool& aEnabled) MOZ_OVERRIDE { if (!AssertAppProcessPermission(this, "power")) { return false; } - hal::SetCpuSleepAllowed(allowed); + hal::SetKeyLightEnabled(aEnabled); return true; } virtual bool - RecvGetScreenBrightness(double *brightness) MOZ_OVERRIDE + RecvGetCpuSleepAllowed(bool* aAllowed) MOZ_OVERRIDE { if (!AssertAppProcessPermission(this, "power")) { return false; } - *brightness = hal::GetScreenBrightness(); + *aAllowed = hal::GetCpuSleepAllowed(); return true; } virtual bool - RecvSetScreenBrightness(const double &brightness) MOZ_OVERRIDE + RecvSetCpuSleepAllowed(const bool& aAllowed) MOZ_OVERRIDE { if (!AssertAppProcessPermission(this, "power")) { return false; } - hal::SetScreenBrightness(brightness); + hal::SetCpuSleepAllowed(aAllowed); + return true; + } + + virtual bool + RecvGetScreenBrightness(double* aBrightness) MOZ_OVERRIDE + { + if (!AssertAppProcessPermission(this, "power")) { + return false; + } + *aBrightness = hal::GetScreenBrightness(); + return true; + } + + virtual bool + RecvSetScreenBrightness(const double& aBrightness) MOZ_OVERRIDE + { + if (!AssertAppProcessPermission(this, "power")) { + return false; + } + hal::SetScreenBrightness(aBrightness); return true; }