Bug 1017463 - Remove SetLight / GetLight from PHal.ipdl. r=dhylands
authorKilik Kuo <kikuo@mozilla.com>
Wed, 11 Jun 2014 18:17:23 +0800
changeset 188576 bdb5750d23536b013bff9b69988edd2b81cde624
parent 188575 f6669e8d789178534ae2f676fe6d6e6c82077d45
child 188577 71e899337efa60985e31d3c46ba29c5ced6457d8
push idunknown
push userunknown
push dateunknown
reviewersdhylands
bugs1017463
milestone33.0a1
Bug 1017463 - Remove SetLight / GetLight from PHal.ipdl. r=dhylands
hal/Hal.cpp
hal/Hal.h
hal/HalInternal.h
hal/fallback/FallbackLights.cpp
hal/gonk/GonkHal.cpp
hal/moz.build
hal/sandbox/PHal.ipdl
hal/sandbox/SandboxHal.cpp
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -415,28 +415,16 @@ double GetScreenBrightness()
 }
 
 void SetScreenBrightness(double aBrightness)
 {
   AssertMainThread();
   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:
   void EnableNotifications() {
     PROXY_IF_SANDBOXED(EnableSystemClockChangeNotifications());
   }
 
   void DisableNotifications() {
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -164,34 +164,16 @@ bool GetCpuSleepAllowed();
 
 /**
  * Set whether the device is allowed to suspend automatically after
  * the screen is disabled.
  */
 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.
  *
  * The observer will receive data whenever the data generated by the
  * sensor is avaiable.
  */
 void RegisterSensorObserver(hal::SensorType aSensor,
                             hal::ISensorObserver *aObserver);
 
--- a/hal/HalInternal.h
+++ b/hal/HalInternal.h
@@ -9,17 +9,17 @@
 
 /*
  * This file is included by HalImpl.h and HalSandbox.h with a mechanism similar
  * to Hal.h. That means those headers set MOZ_HAL_NAMESPACE to specify in which
  * namespace the internal functions should appear.
  *
  * 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
 # error "You shouldn't directly include HalInternal.h!"
 #endif
 
 namespace mozilla {
 namespace MOZ_HAL_NAMESPACE {
deleted file mode 100644
--- 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
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -104,16 +104,138 @@
 #endif
 
 using namespace mozilla;
 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 {
 
 /**
  * This runnable runs for the lifetime of the program, once started.  It's
  * responsible for "playing" vibration patterns.
  */
 class VibratorRunnable
   : public nsIRunnable
@@ -277,23 +399,24 @@ public:
     if (info.charging() && (info.level() == 1)) {
       // Charging and battery full.
       color = BATTERY_FULL_ARGB;
     } else if (info.charging() && (info.level() < 1)) {
       // Charging but not full.
       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);
 
     {
       // bug 975667
       // Gecko gonk hal is required to emit battery charging/level notification via nsIObserverService.
       // This is useful for XPCOM components that are not statically linked to Gecko and cannot call
       // hal::EnableBatteryNotifications
@@ -544,54 +667,54 @@ SetScreenEnabled(bool aEnabled)
 {
   GetGonkDisplay()->SetEnabled(aEnabled);
   sScreenEnabled = 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
     // 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;
+    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;
 }
 
 void
 SetScreenBrightness(double brightness)
 {
   // Don't use De Morgan's law to push the ! into this expression; we want to
   // catch NaN too.
@@ -601,25 +724,25 @@ SetScreenBrightness(double brightness)
     return;
   }
 
   // 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.
   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);
   }
 }
 
 static Monitor* sInternalLockCpuMonitor = nullptr;
 
 static void
 UpdateCpuSleepState()
 {
@@ -651,123 +774,16 @@ GetCpuSleepAllowed()
 void
 SetCpuSleepAllowed(bool aAllowed)
 {
   MonitorAutoLock monitor(*sInternalLockCpuMonitor);
   sCpuSleepAllowed = 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)
 {
   int fd;
   struct timespec now;
 
   if (aDeltaMilliseconds == 0) {
     return;
--- a/hal/moz.build
+++ b/hal/moz.build
@@ -146,17 +146,16 @@ else:
     ]
 
 # Fallbacks for backends implemented on Gonk only.
 if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
     UNIFIED_SOURCES += [
         'fallback/FallbackDiskSpaceWatcher.cpp',
         'fallback/FallbackFactoryReset.cpp',
         'fallback/FallbackFMRadio.cpp',
-        'fallback/FallbackLights.cpp',
         'fallback/FallbackProcessPriority.cpp',
         'fallback/FallbackScreenPower.cpp',
         'fallback/FallbackSwitch.cpp',
         'fallback/FallbackThreadPriority.cpp',
         'fallback/FallbackTime.cpp',
         'fallback/FallbackWakeLocks.cpp',
     ]
 
--- a/hal/sandbox/PHal.ipdl
+++ b/hal/sandbox/PHal.ipdl
@@ -5,19 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include protocol PContent;
 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";
 using mozilla::hal::SwitchState from "mozilla/HalTypes.h";
 using mozilla::hal::SwitchDevice from "mozilla/HalTypes.h";
 using mozilla::hal::ProcessPriority from "mozilla/HalTypes.h";
 using struct nsIntRect from "nsRect.h";
 using PRTime from "prtime.h";
@@ -29,25 +26,16 @@ namespace mozilla {
 
 namespace hal {
 struct BatteryInformation {
   double level;
   bool   charging;
   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;
   float[] values;
   SensorAccuracyType accuracy;
 };
 
 struct NetworkInformation {
@@ -144,21 +132,16 @@ parent:
       returns (nsCString aTimezoneSpec);
     sync GetTimezoneOffset()
       returns (int32_t aTimezoneOffset);
     EnableSystemClockChangeNotifications();
     DisableSystemClockChangeNotifications();
     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,
                    uint64_t aProcessID);
     EnableWakeLockNotifications();
     DisableWakeLockNotifications();
     sync GetWakeLockInfo(nsString aTopic)
       returns (WakeLockInformation aWakeLockInfo);
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -185,32 +185,16 @@ GetScreenBrightness()
 }
 
 void
 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)
 {
   Hal()->SendAdjustSystemClock(aDeltaMilliseconds);
 }
 
 void
 SetTimezone(const nsCString& aTimezoneSpec)
@@ -682,40 +666,16 @@ public:
     if (!AssertAppProcessPermission(this, "power")) {
       return false;
     }
     hal::SetScreenBrightness(aBrightness);
     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
   {
     if (!AssertAppProcessPermission(this, "time")) {
       return false;
     }
     hal::AdjustSystemClock(aDeltaMilliseconds);
     return true;
   }