Bug 1017463 - Remove SetLight / GetLight from PHal.ipdl. r=dhylands

This commit is contained in:
Kilik Kuo 2014-06-11 18:17:23 +08:00
parent b3b134d636
commit 7fde2154a4
8 changed files with 153 additions and 253 deletions

View File

@ -420,18 +420,6 @@ void SetScreenBrightness(double aBrightness)
PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(aBrightness, 0.0, 1.0)));
}
bool SetLight(LightType light, const LightConfiguration& aConfig)
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(SetLight(light, aConfig), false);
}
bool GetLight(LightType light, LightConfiguration* aConfig)
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig), false);
}
class SystemClockChangeObserversManager : public ObserversManager<int64_t>
{
protected:

View File

@ -168,24 +168,6 @@ bool GetCpuSleepAllowed();
*/
void SetCpuSleepAllowed(bool aAllowed);
/**
* Set the value of a light to a particular color, with a specific flash pattern.
* light specifices which light. See Hal.idl for the list of constants
* mode specifies user set or based on ambient light sensor
* flash specifies whether or how to flash the light
* flashOnMS and flashOffMS specify the pattern for XXX flash mode
* color specifies the color. If the light doesn't support color, the given color is
* transformed into a brightness, or just an on/off if that is all the light is capable of.
* returns true if successful and false if failed.
*/
bool SetLight(hal::LightType light, const hal::LightConfiguration& aConfig);
/**
* GET the value of a light returning a particular color, with a specific flash pattern.
* returns true if successful and false if failed.
*/
bool GetLight(hal::LightType light, hal::LightConfiguration* aConfig);
/**
* Register an observer for the sensor of given type.
*

View File

@ -14,7 +14,7 @@
*
* The difference between Hal.h and HalInternal.h is that methods declared in
* HalInternal.h don't appear in the hal namespace. That also means this file
* should not be included except by HalInternal.h and HalSandbox.h.
* should not be included except by HalImpl.h and HalSandbox.h.
*/
#ifndef MOZ_HAL_NAMESPACE

View File

@ -1,28 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Hal.h"
namespace mozilla {
namespace hal_impl {
bool
SetLight(hal::LightType light, const hal::LightConfiguration& aConfig)
{
return true;
}
bool
GetLight(hal::LightType light, hal::LightConfiguration* aConfig)
{
aConfig->light() = light;
// The rest of the fields are 0 by default, which is fine.
return true;
}
} // namespace hal_impl
} // namespace mozilla

View File

@ -109,6 +109,128 @@ using namespace mozilla::hal;
namespace mozilla {
namespace hal_impl {
struct LightConfiguration {
hal::LightType light;
hal::LightMode mode;
hal::FlashMode flash;
uint32_t flashOnMS;
uint32_t flashOffMS;
uint32_t color;
};
static light_device_t* sLights[hal::eHalLightID_Count]; // will be initialized to nullptr
static light_device_t*
GetDevice(hw_module_t* module, char const* name)
{
int err;
hw_device_t* device;
err = module->methods->open(module, name, &device);
if (err == 0) {
return (light_device_t*)device;
} else {
return nullptr;
}
}
static void
InitLights()
{
// assume that if backlight is nullptr, nothing has been set yet
// if this is not true, the initialization will occur everytime a light is read or set!
if (!sLights[hal::eHalLightID_Backlight]) {
int err;
hw_module_t* module;
err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
if (err == 0) {
sLights[hal::eHalLightID_Backlight]
= GetDevice(module, LIGHT_ID_BACKLIGHT);
sLights[hal::eHalLightID_Keyboard]
= GetDevice(module, LIGHT_ID_KEYBOARD);
sLights[hal::eHalLightID_Buttons]
= GetDevice(module, LIGHT_ID_BUTTONS);
sLights[hal::eHalLightID_Battery]
= GetDevice(module, LIGHT_ID_BATTERY);
sLights[hal::eHalLightID_Notifications]
= GetDevice(module, LIGHT_ID_NOTIFICATIONS);
sLights[hal::eHalLightID_Attention]
= GetDevice(module, LIGHT_ID_ATTENTION);
sLights[hal::eHalLightID_Bluetooth]
= GetDevice(module, LIGHT_ID_BLUETOOTH);
sLights[hal::eHalLightID_Wifi]
= GetDevice(module, LIGHT_ID_WIFI);
}
}
}
/**
* The state last set for the lights until liblights supports
* getting the light state.
*/
static light_state_t sStoredLightState[hal::eHalLightID_Count];
/**
* Set the value of a light to a particular color, with a specific flash pattern.
* light specifices which light. See Hal.idl for the list of constants
* mode specifies user set or based on ambient light sensor
* flash specifies whether or how to flash the light
* flashOnMS and flashOffMS specify the pattern for XXX flash mode
* color specifies the color. If the light doesn't support color, the given color is
* transformed into a brightness, or just an on/off if that is all the light is capable of.
* returns true if successful and false if failed.
*/
static bool
SetLight(hal::LightType light, const LightConfiguration& aConfig)
{
light_state_t state;
InitLights();
if (light < 0 || light >= hal::eHalLightID_Count ||
sLights[light] == nullptr) {
return false;
}
memset(&state, 0, sizeof(light_state_t));
state.color = aConfig.color;
state.flashMode = aConfig.flash;
state.flashOnMS = aConfig.flashOnMS;
state.flashOffMS = aConfig.flashOffMS;
state.brightnessMode = aConfig.mode;
sLights[light]->set_light(sLights[light], &state);
sStoredLightState[light] = state;
return true;
}
/**
* GET the value of a light returning a particular color, with a specific flash pattern.
* returns true if successful and false if failed.
*/
static bool
GetLight(hal::LightType light, LightConfiguration* aConfig)
{
light_state_t state;
if (light < 0 || light >= hal::eHalLightID_Count ||
sLights[light] == nullptr) {
return false;
}
memset(&state, 0, sizeof(light_state_t));
state = sStoredLightState[light];
aConfig->light = light;
aConfig->color = state.color;
aConfig->flash = hal::FlashMode(state.flashMode);
aConfig->flashOnMS = state.flashOnMS;
aConfig->flashOffMS = state.flashOffMS;
aConfig->mode = hal::LightMode(state.brightnessMode);
return true;
}
namespace {
/**
@ -282,13 +404,14 @@ public:
color = BATTERY_CHARGING_ARGB;
} // else turn off battery indicator.
hal::LightConfiguration aConfig(hal::eHalLightID_Battery,
hal::eHalLightMode_User,
hal::eHalLightFlash_None,
0,
0,
color);
hal_impl::SetLight(hal::eHalLightID_Battery, aConfig);
LightConfiguration aConfig;
aConfig.light = hal::eHalLightID_Battery;
aConfig.mode = hal::eHalLightMode_User;
aConfig.flash = hal::eHalLightFlash_None;
aConfig.flashOnMS = aConfig.flashOffMS = 0;
aConfig.color = color;
SetLight(hal::eHalLightID_Battery, aConfig);
hal::NotifyBatteryChange(info);
@ -549,19 +672,19 @@ SetScreenEnabled(bool aEnabled)
bool
GetKeyLightEnabled()
{
hal::LightConfiguration config;
hal_impl::GetLight(hal::eHalLightID_Buttons, &config);
return (config.color() != 0x00000000);
LightConfiguration config;
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;
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
@ -571,22 +694,22 @@ SetKeyLightEnabled(bool aEnabled)
uint32_t val = static_cast<int>(round(brightness * 255.0));
uint32_t color = (0xff<<24) + (val<<16) + (val<<8) + val;
config.color() = color;
config.color = color;
}
hal_impl::SetLight(hal::eHalLightID_Buttons, config);
hal_impl::SetLight(hal::eHalLightID_Keyboard, config);
SetLight(hal::eHalLightID_Buttons, config);
SetLight(hal::eHalLightID_Keyboard, config);
}
double
GetScreenBrightness()
{
hal::LightConfiguration config;
LightConfiguration config;
hal::LightType light = hal::eHalLightID_Backlight;
hal_impl::GetLight(light, &config);
GetLight(light, &config);
// backlight is brightness only, so using one of the RGB elements as value.
int brightness = config.color() & 0xFF;
int brightness = config.color & 0xFF;
return brightness / 255.0;
}
@ -606,15 +729,15 @@ SetScreenBrightness(double brightness)
uint32_t val = static_cast<int>(round(brightness * 255.0));
uint32_t color = (0xff<<24) + (val<<16) + (val<<8) + val;
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);
LightConfiguration config;
config.mode = hal::eHalLightMode_User;
config.flash = hal::eHalLightFlash_None;
config.flashOnMS = config.flashOffMS = 0;
config.color = color;
SetLight(hal::eHalLightID_Backlight, config);
if (GetKeyLightEnabled()) {
hal_impl::SetLight(hal::eHalLightID_Buttons, config);
hal_impl::SetLight(hal::eHalLightID_Keyboard, config);
SetLight(hal::eHalLightID_Buttons, config);
SetLight(hal::eHalLightID_Keyboard, config);
}
}
@ -656,113 +779,6 @@ SetCpuSleepAllowed(bool aAllowed)
UpdateCpuSleepState();
}
static light_device_t* sLights[hal::eHalLightID_Count]; // will be initialized to nullptr
light_device_t* GetDevice(hw_module_t* module, char const* name)
{
int err;
hw_device_t* device;
err = module->methods->open(module, name, &device);
if (err == 0) {
return (light_device_t*)device;
} else {
return nullptr;
}
}
void
InitLights()
{
// assume that if backlight is nullptr, nothing has been set yet
// if this is not true, the initialization will occur everytime a light is read or set!
if (!sLights[hal::eHalLightID_Backlight]) {
int err;
hw_module_t* module;
err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
if (err == 0) {
sLights[hal::eHalLightID_Backlight]
= GetDevice(module, LIGHT_ID_BACKLIGHT);
sLights[hal::eHalLightID_Keyboard]
= GetDevice(module, LIGHT_ID_KEYBOARD);
sLights[hal::eHalLightID_Buttons]
= GetDevice(module, LIGHT_ID_BUTTONS);
sLights[hal::eHalLightID_Battery]
= GetDevice(module, LIGHT_ID_BATTERY);
sLights[hal::eHalLightID_Notifications]
= GetDevice(module, LIGHT_ID_NOTIFICATIONS);
sLights[hal::eHalLightID_Attention]
= GetDevice(module, LIGHT_ID_ATTENTION);
sLights[hal::eHalLightID_Bluetooth]
= GetDevice(module, LIGHT_ID_BLUETOOTH);
sLights[hal::eHalLightID_Wifi]
= GetDevice(module, LIGHT_ID_WIFI);
}
}
}
/**
* The state last set for the lights until liblights supports
* getting the light state.
*/
static light_state_t sStoredLightState[hal::eHalLightID_Count];
bool
SetLight(hal::LightType light, const hal::LightConfiguration& aConfig)
{
light_state_t state;
InitLights();
if (light < 0 || light >= hal::eHalLightID_Count ||
sLights[light] == nullptr) {
return false;
}
memset(&state, 0, sizeof(light_state_t));
state.color = aConfig.color();
state.flashMode = aConfig.flash();
state.flashOnMS = aConfig.flashOnMS();
state.flashOffMS = aConfig.flashOffMS();
state.brightnessMode = aConfig.mode();
sLights[light]->set_light(sLights[light], &state);
sStoredLightState[light] = state;
return true;
}
bool
GetLight(hal::LightType light, hal::LightConfiguration* aConfig)
{
light_state_t state;
#ifdef HAVEGETLIGHT
InitLights();
#endif
if (light < 0 || light >= hal::eHalLightID_Count ||
sLights[light] == nullptr) {
return false;
}
memset(&state, 0, sizeof(light_state_t));
#ifdef HAVEGETLIGHT
sLights[light]->get_light(sLights[light], &state);
#else
state = sStoredLightState[light];
#endif
aConfig->light() = light;
aConfig->color() = state.color;
aConfig->flash() = hal::FlashMode(state.flashMode);
aConfig->flashOnMS() = state.flashOnMS;
aConfig->flashOffMS() = state.flashOffMS;
aConfig->mode() = hal::LightMode(state.brightnessMode);
return true;
}
void
AdjustSystemClock(int64_t aDeltaMilliseconds)
{

View File

@ -151,7 +151,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
'fallback/FallbackDiskSpaceWatcher.cpp',
'fallback/FallbackFactoryReset.cpp',
'fallback/FallbackFMRadio.cpp',
'fallback/FallbackLights.cpp',
'fallback/FallbackProcessPriority.cpp',
'fallback/FallbackScreenPower.cpp',
'fallback/FallbackSwitch.cpp',

View File

@ -10,9 +10,6 @@ include protocol PBrowser;
include "mozilla/GfxMessageUtils.h";
using mozilla::dom::ScreenOrientation from "mozilla/dom/ScreenOrientation.h";
using mozilla::hal::FlashMode from "mozilla/HalTypes.h";
using mozilla::hal::LightType from "mozilla/HalTypes.h";
using mozilla::hal::LightMode from "mozilla/HalTypes.h";
using mozilla::hal::SensorType from "mozilla/HalSensor.h";
using mozilla::hal::SensorAccuracyType from "mozilla/HalSensor.h";
using mozilla::hal::WakeLockControl from "mozilla/HalTypes.h";
@ -34,15 +31,6 @@ struct BatteryInformation {
double remainingTime;
};
struct LightConfiguration {
LightType light;
LightMode mode;
FlashMode flash;
uint32_t flashOnMS;
uint32_t flashOffMS;
uint32_t color;
};
struct SensorData {
SensorType sensor;
PRTime timestamp;
@ -149,11 +137,6 @@ parent:
EnableSystemTimezoneChangeNotifications();
DisableSystemTimezoneChangeNotifications();
sync SetLight(LightType light, LightConfiguration aConfig)
returns (bool status);
sync GetLight(LightType light)
returns (LightConfiguration aConfig, bool status);
ModifyWakeLock(nsString aTopic,
WakeLockControl aLockAdjust,
WakeLockControl aHiddenAdjust,

View File

@ -190,22 +190,6 @@ SetScreenBrightness(double aBrightness)
Hal()->SendSetScreenBrightness(aBrightness);
}
bool
SetLight(hal::LightType light, const hal::LightConfiguration& aConfig)
{
bool status;
Hal()->SendSetLight(light, aConfig, &status);
return status;
}
bool
GetLight(hal::LightType light, hal::LightConfiguration* aConfig)
{
bool status;
Hal()->SendGetLight(light, aConfig, &status);
return status;
}
void
AdjustSystemClock(int64_t aDeltaMilliseconds)
{
@ -686,30 +670,6 @@ public:
return true;
}
virtual bool
RecvSetLight(const LightType& aLight, const hal::LightConfiguration& aConfig, bool *status) MOZ_OVERRIDE
{
// XXX currently, the hardware key light and screen backlight are
// controlled as a unit. Those are set through the power API, and
// there's no other way to poke lights currently, so we require
// "power" privileges here.
if (!AssertAppProcessPermission(this, "power")) {
return false;
}
*status = hal::SetLight(aLight, aConfig);
return true;
}
virtual bool
RecvGetLight(const LightType& aLight, LightConfiguration* aConfig, bool* status) MOZ_OVERRIDE
{
if (!AssertAppProcessPermission(this, "power")) {
return false;
}
*status = hal::GetLight(aLight, aConfig);
return true;
}
virtual bool
RecvAdjustSystemClock(const int64_t &aDeltaMilliseconds) MOZ_OVERRIDE
{