diff --git a/hal/Hal.cpp b/hal/Hal.cpp index 392338c08ee..537735bff80 100644 --- a/hal/Hal.cpp +++ b/hal/Hal.cpp @@ -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 { protected: diff --git a/hal/Hal.h b/hal/Hal.h index 6cce248a9f0..44f7bb5dd99 100644 --- a/hal/Hal.h +++ b/hal/Hal.h @@ -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. * diff --git a/hal/HalInternal.h b/hal/HalInternal.h index 1c36f6f1fc1..50ea373363d 100644 --- a/hal/HalInternal.h +++ b/hal/HalInternal.h @@ -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 diff --git a/hal/fallback/FallbackLights.cpp b/hal/fallback/FallbackLights.cpp deleted file mode 100644 index 04670878a24..00000000000 --- a/hal/fallback/FallbackLights.cpp +++ /dev/null @@ -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 diff --git a/hal/gonk/GonkHal.cpp b/hal/gonk/GonkHal.cpp index 212d6be685c..f021b91b30d 100644 --- a/hal/gonk/GonkHal.cpp +++ b/hal/gonk/GonkHal.cpp @@ -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(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(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) { diff --git a/hal/moz.build b/hal/moz.build index c6582462327..565eda44482 100644 --- a/hal/moz.build +++ b/hal/moz.build @@ -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', diff --git a/hal/sandbox/PHal.ipdl b/hal/sandbox/PHal.ipdl index 79826fc06af..46927791b1e 100644 --- a/hal/sandbox/PHal.ipdl +++ b/hal/sandbox/PHal.ipdl @@ -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, diff --git a/hal/sandbox/SandboxHal.cpp b/hal/sandbox/SandboxHal.cpp index ea48113155e..5f16c4455cc 100644 --- a/hal/sandbox/SandboxHal.cpp +++ b/hal/sandbox/SandboxHal.cpp @@ -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 {