Bug 911242 - [LED] De-couple the control of screen backlight and keyboard backlight. r=dhylands, sr=sicking

This commit is contained in:
Sean Lin 2014-05-30 11:11:23 +08:00
Родитель c9d1aee8c2
Коммит 08364d3403
11 изменённых файлов: 237 добавлений и 46 удалений

Просмотреть файл

@ -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()
{

Просмотреть файл

@ -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();

Просмотреть файл

@ -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"

Просмотреть файл

@ -0,0 +1,64 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test Enabling/Disabling Screen with Power Management API</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
<script type="application/javascript">
"use strict";
function testEnableKeyLight() {
try {
navigator.mozPower.keyLightEnabled = true;
ok(navigator.mozPower.keyLightEnabled === true, "Enabled key backlight.");
} catch (e) {
ok(false, "Unexpected exception trying to enable key backlight.");
}
}
function testDisableKeyLight() {
try {
navigator.mozPower.keyLightEnabled = false;
ok(navigator.mozPower.keyLightEnabled === false, "Disabled key backlight.");
} catch (e) {
ok(false, "Unexpected exception trying to disable key backlight.");
}
}
function startTests() {
// Make sure we don't suspend
navigator.mozPower.cpuSleepAllowed = false;
testDisableKeyLight();
testEnableKeyLight();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
if (SpecialPowers.hasPermission("power", document)) {
// Currently only applicable on FxOS
if (navigator.userAgent.indexOf("Mobile") != -1 &&
navigator.appVersion.indexOf("Android") == -1) {
startTests();
} else {
ok(true, "mozPower on Firefox OS only.");
SimpleTest.finish();
}
} else {
// Add the permission and reload so it's propogated
SpecialPowers.addPermission("power", true, document);
window.location.reload();
}
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -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

Просмотреть файл

@ -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)

Просмотреть файл

@ -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.

Просмотреть файл

@ -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

Просмотреть файл

@ -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<int>(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<int>(round(brightness * 255));
uint32_t val = static_cast<int>(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;

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;
}