Bug 712378: Add an interface to control lights, and use it for the screen backlight on Gonk. r=cjones
authorJim Straus <jstraus@mozilla.com>
Wed, 01 Feb 2012 22:09:00 -0800
changeset 86028 20289eb83e51685aeae7e02d5571b750e3572b40
parent 86027 c925a45fcf5b619637e262bb3cbfd3a1a2207485
child 86029 5a80e90839fd559d00314bf22a0516f77eacd8f8
push id5627
push usercjones@mozilla.com
push dateThu, 02 Feb 2012 08:33:21 +0000
treeherdermozilla-inbound@20289eb83e51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs712378
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 712378: Add an interface to control lights, and use it for the screen backlight on Gonk. r=cjones
dom/system/b2g/Makefile.in
hal/Hal.cpp
hal/Hal.h
hal/HalImpl.h
hal/HalTypes.h
hal/Makefile.in
hal/fallback/FallbackHal.cpp
hal/fallback/FallbackLights.cpp
hal/gonk/GonkHal.cpp
hal/sandbox/PHal.ipdl
hal/sandbox/SandboxHal.cpp
hal/sandbox/SandboxHal.h
toolkit/library/Makefile.in
--- a/dom/system/b2g/Makefile.in
+++ b/dom/system/b2g/Makefile.in
@@ -1,43 +1,16 @@
 # ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is Telephony.
-#
-# The Initial Developer of the Original Code is
-#   The Mozilla Foundation.
-# Portions created by the Initial Developer are Copyright (C) 2011
-# the Initial Developer. All Rights Reserved.
+# 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/. */#
 #
 # Contributor(s):
 #   Ben Turner <bent.mozilla@gmail.com> (Original Author)
 #
-# Alternatively, the contents of this file may be used under the terms of
-# either the GNU General Public License Version 2 or later (the "GPL"), or
-# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
 # ***** END LICENSE BLOCK *****
 
 DEPTH            = ../../..
 topsrcdir        = @top_srcdir@
 srcdir           = @srcdir@
 VPATH            = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -1,44 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Code.
- *
- * The Initial Developer of the Original Code is
- *   The Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
+ * 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/.
  * Contributor(s):
  *   Chris Jones <jones.chris.g@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
+ *   Jim Straus <jstraus@mozilla.com>
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "Hal.h"
 #include "HalImpl.h"
 #include "HalSandbox.h"
 #include "mozilla/Util.h"
 #include "nsThreadUtils.h"
@@ -339,16 +312,28 @@ double GetScreenBrightness()
 }
 
 void SetScreenBrightness(double brightness)
 {
   AssertMainThread();
   PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(brightness, 0.0, 1.0)));
 }
 
+bool SetLight(LightType light, const hal::LightConfiguration& aConfig)
+{
+  AssertMainThread();
+  RETURN_PROXY_IF_SANDBOXED(SetLight(light, aConfig));
+}
+
+bool GetLight(LightType light, hal::LightConfiguration* aConfig)
+{
+  AssertMainThread();
+  RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig));
+}
+
 void
 EnableSensorNotifications(SensorType aSensor) {
   AssertMainThread();
   PROXY_IF_SANDBOXED(EnableSensorNotifications(aSensor));
 }
 
 void
 DisableSensorNotifications(SensorType aSensor) {
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -1,44 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Code.
- *
- * The Initial Developer of the Original Code is
- *   The Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
+ * 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/.
  * Contributor(s):
  *   Chris Jones <jones.chris.g@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
+ *   Jim Straus <jstraus@mozilla.com>
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_Hal_h
 #define mozilla_Hal_h 1
 
 #include "mozilla/hal_sandbox/PHal.h"
 #include "base/basictypes.h"
@@ -165,16 +138,33 @@ double GetScreenBrightness();
  *
  * Note that we may reduce the resolution of the given brightness value before
  * sending it to the screen.  Therefore if you call SetScreenBrightness(x)
  * followed by GetScreenBrightness(), the value returned by
  * GetScreenBrightness() may not be exactly x.
  */
 void SetScreenBrightness(double brightness);
 
+/**
+ * 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,
--- a/hal/HalImpl.h
+++ b/hal/HalImpl.h
@@ -1,45 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Code.
- *
- * The Initial Developer of the Original Code is
- *   The Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
+ * 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/.
  * Contributor(s):
  *   Chris Jones <jones.chris.g@gmail.com>
  *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_HalImpl_h
 #define mozilla_HalImpl_h
 
 #define MOZ_HAL_NAMESPACE hal_impl
 #undef mozilla_Hal_h
 #undef mozilla_HalInternal_h
new file mode 100644
--- /dev/null
+++ b/hal/HalTypes.h
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * 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/.
+ * Contributor(s):
+ *   Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
+ *   Jim Straus <jstraus@mozilla.com>
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef mozilla_hal_Types_h
+#define mozilla_hal_Types_h
+
+#include "IPCMessageUtils.h"
+
+namespace mozilla {
+namespace hal {
+
+/**
+ * These are defined by libhardware, specifically, hardware/libhardware/include/hardware/lights.h
+ * in the gonk subsystem.
+ * If these change and are exposed to JS, make sure nsIHal.idl is updated as well.
+ */
+enum LightType {
+    eHalLightID_Backlight = 0,
+    eHalLightID_Keyboard = 1,
+    eHalLightID_Buttons = 2,
+    eHalLightID_Battery = 3,
+    eHalLightID_Notifications = 4,
+    eHalLightID_Attention = 5,
+    eHalLightID_Bluetooth = 6,
+    eHalLightID_Wifi = 7,
+    eHalLightID_Count = 8         // This should stay at the end
+};
+enum LightMode {
+    eHalLightMode_User = 0,       // brightness is managed by user setting
+    eHalLightMode_Sensor = 1      // brightness is managed by a light sensor
+};
+enum FlashMode {
+    eHalLightFlash_None = 0,
+    eHalLightFlash_Timed = 1,     // timed flashing.  Use flashOnMS and flashOffMS for timing
+    eHalLightFlash_Hardware = 2   // hardware assisted flashing
+};
+} // namespace hal
+} // namespace mozilla
+
+namespace IPC {
+
+/**
+ * Light type serializer.
+ */
+template <>
+struct ParamTraits<mozilla::hal::LightType>
+  : public EnumSerializer<mozilla::hal::LightType,
+                          mozilla::hal::eHalLightID_Backlight,
+                          mozilla::hal::eHalLightID_Count>
+{};
+
+/**
+ * Light mode serializer.
+ */
+template <>
+struct ParamTraits<mozilla::hal::LightMode>
+  : public EnumSerializer<mozilla::hal::LightMode,
+                          mozilla::hal::eHalLightMode_User,
+                          mozilla::hal::eHalLightMode_Sensor>
+{};
+
+/**
+ * Flash mode serializer.
+ */
+template <>
+struct ParamTraits<mozilla::hal::FlashMode>
+  : public EnumSerializer<mozilla::hal::FlashMode,
+                          mozilla::hal::eHalLightFlash_None,
+                          mozilla::hal::eHalLightFlash_Hardware>
+{};
+
+} // namespace IPC
+
+#endif // mozilla_hal_Types_h
--- a/hal/Makefile.in
+++ b/hal/Makefile.in
@@ -57,16 +57,17 @@ LIBXUL_LIBRARY = 1
 EXPORT_LIBRARY = 1
 
 EXPORTS_NAMESPACES = mozilla
 EXPORTS_mozilla = \
   Hal.h \
   HalImpl.h \
   HalSandbox.h \
   HalSensor.h \
+  HalTypes.h \
   $(NULL)
 
 CPPSRCS = \
   Hal.cpp \
   SandboxHal.cpp \
   WindowIdentifier.cpp \
   $(NULL)
 
@@ -98,14 +99,18 @@ CPPSRCS += \
   $(NULL)
 else
 CPPSRCS += \
   FallbackHal.cpp \
   FallbackSensor.cpp \
   $(NULL)
 endif
 
+ifneq (gonk,$(MOZ_WIDGET_TOOLKIT)) #{
+CPPSRCS += FallbackLights.cpp
+endif #}
+
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 include $(topsrcdir)/config/rules.mk
 
 CFLAGS          += $(MOZ_DBUS_GLIB_CFLAGS)
 CXXFLAGS        += $(MOZ_DBUS_GLIB_CFLAGS)
--- a/hal/fallback/FallbackHal.cpp
+++ b/hal/fallback/FallbackHal.cpp
@@ -1,44 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Code.
- *
- * The Initial Developer of the Original Code is
- *   The Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
+ * 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/.
  * Contributor(s):
  *   Chris Jones <jones.chris.g@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
+ *   Jim Straus <jstraus@mozilla.com>
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "Hal.h"
 #include "mozilla/dom/battery/Constants.h"
 #include "mozilla/dom/network/Constants.h"
 
 using mozilla::hal::WindowIdentifier;
new file mode 100644
--- /dev/null
+++ b/hal/fallback/FallbackLights.cpp
@@ -0,0 +1,28 @@
+/* -*- 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
@@ -1,46 +1,19 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Code.
- *
- * The Initial Developer of the Original Code is
- *   The Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
+ * 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/.
  * Contributor(s):
  *   Chris Jones <jones.chris.g@gmail.com>
  *   Michael Wu <mwu@mozilla.com>
  *   Justin Lebar <justin.lebar@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
+ *   Jim Straus <jstraus@mozilla.com>
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "hardware_legacy/uevent.h"
 #include "Hal.h"
 #include "HalImpl.h"
 #include "mozilla/dom/battery/Constants.h"
 #include "mozilla/FileUtils.h"
@@ -49,16 +22,18 @@
 #include "mozilla/Monitor.h"
 #include "mozilla/Services.h"
 #include "mozilla/FileUtils.h"
 #include "nsThreadUtils.h"
 #include "nsIRunnable.h"
 #include "nsIThread.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
+#include "hardware/lights.h"
+#include "hardware/hardware.h"
 #include "hardware_legacy/vibrator.h"
 #include <stdio.h>
 #include <math.h>
 #include <fcntl.h>
 #include <errno.h>
 #include "mozilla/dom/network/Constants.h"
 
 using mozilla::hal::WindowIdentifier;
@@ -309,17 +284,16 @@ GetCurrentBatteryInformation(hal::Batter
 }
 
 namespace {
 
 /**
  * RAII class to help us remember to close file descriptors.
  */
 const char *screenEnabledFilename = "/sys/power/state";
-const char *screenBrightnessFilename = "/sys/class/leds/lcd-backlight/brightness";
 
 template<ssize_t n>
 bool ReadFromFile(const char *filename, char (&buf)[n])
 {
   int fd = open(filename, O_RDONLY);
   ScopedClose autoClose(fd);
   if (fd < 0) {
     HAL_LOG(("Unable to open file %s.", filename));
@@ -369,55 +343,152 @@ SetScreenEnabled(bool enabled)
 {
   WriteToFile(screenEnabledFilename, enabled ? "on" : "mem");
   sScreenEnabled = enabled;
 }
 
 double
 GetScreenBrightness()
 {
-  char buf[32];
-  ReadFromFile(screenBrightnessFilename, buf);
+  hal::LightConfiguration aConfig;
+  hal::LightType light = hal::eHalLightID_Backlight;
 
-  errno = 0;
-  unsigned long val = strtoul(buf, NULL, 10);
-  if (errno) {
-    HAL_LOG(("Cannot parse contents of %s; expected an unsigned "
-             "int, but contains \"%s\".",
-             screenBrightnessFilename, buf));
-    return 1;
-  }
-
-  if (val > 255) {
-    HAL_LOG(("Got out-of-range brightness %d, truncating to 1.0", val));
-    val = 255;
-  }
-
-  return val / 255.0;
+  hal::GetLight(light, &aConfig);
+  // backlight is brightness only, so using one of the RGB elements as value.
+  int brightness = aConfig.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.
   if (!(0 <= brightness && brightness <= 1)) {
     HAL_LOG(("SetScreenBrightness: Dropping illegal brightness %f.",
              brightness));
     return;
   }
 
-  // Convert the value in [0, 1] to an int between 0 and 255, then write to a
-  // string.
+  // 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));
-  char str[4];
-  DebugOnly<int> numChars = snprintf(str, sizeof(str), "%d", val);
-  MOZ_ASSERT(numChars < static_cast<int>(sizeof(str)));
+  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);
+}
+
+static light_device_t* sLights[hal::eHalLightID_Count];	// will be initialized to NULL
+
+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 NULL;
+  }
+}
+
+void
+InitLights()
+{
+  // assume that if backlight is NULL, 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);
+        }
+    }
+}
 
-  WriteToFile(screenBrightnessFilename, str);
+/**
+ * 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] == NULL) {
+    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] == NULL) {
+    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
 EnableNetworkNotifications()
 {}
 
 void
 DisableNetworkNotifications()
--- a/hal/sandbox/PHal.ipdl
+++ b/hal/sandbox/PHal.ipdl
@@ -36,29 +36,42 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 include protocol PContent;
 include protocol PBrowser;
 include "nspr/prtime.h";
 include "mozilla/HalSensor.h";
+include "mozilla/HalTypes.h";
 
 using PRTime;
+using mozilla::hal::FlashMode;
+using mozilla::hal::LightType;
+using mozilla::hal::LightMode;
 using mozilla::hal::SensorType;
 
 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;
   };
 }
 
 namespace hal {
@@ -93,16 +106,21 @@ parent:
       returns (NetworkInformation aNetworkInfo);
 
     sync GetScreenEnabled() returns (bool enabled);
     SetScreenEnabled(bool enabled);
 
     sync GetScreenBrightness() returns (double brightness);
     SetScreenBrightness(double brightness);
 
+    sync SetLight(LightType light, LightConfiguration aConfig)
+      returns (bool status);
+    sync GetLight(LightType light)
+      returns (LightConfiguration aConfig, bool status);
+
     Reboot();
     PowerOff();
 
     EnableSensorNotifications(SensorType aSensor);
     DisableSensorNotifications(SensorType aSensor);
 
     __delete__();
 };
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -1,44 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Code.
- *
- * The Initial Developer of the Original Code is
- *   The Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
+ * 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/.
  * Contributor(s):
  *   Chris Jones <jones.chris.g@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
+ *   Jim Straus <jstraus@mozilla.com>
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "Hal.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/hal_sandbox/PHalChild.h"
 #include "mozilla/hal_sandbox/PHalParent.h"
 #include "mozilla/dom/TabParent.h"
@@ -147,16 +120,32 @@ GetScreenBrightness()
 }
 
 void
 SetScreenBrightness(double brightness)
 {
   Hal()->SendSetScreenBrightness(brightness);
 }
 
+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
 Reboot()
 {
   Hal()->SendReboot();
 }
 
 void
 PowerOff()
@@ -287,16 +276,30 @@ public:
   NS_OVERRIDE virtual bool
   RecvSetScreenBrightness(const double &brightness)
   {
     hal::SetScreenBrightness(brightness);
     return true;
   }
 
   NS_OVERRIDE virtual bool
+  RecvSetLight(const LightType& aLight,  const hal::LightConfiguration& aConfig, bool *status)
+  {
+    *status = hal::SetLight(aLight, aConfig);
+    return true;
+  }
+
+  NS_OVERRIDE virtual bool
+  RecvGetLight(const LightType& aLight, LightConfiguration* aConfig, bool* status)
+  {
+    *status = hal::GetLight(aLight, aConfig);
+    return true;
+  }
+
+  NS_OVERRIDE virtual bool
   RecvReboot()
   {
     hal::Reboot();
     return true;
   }
 
   NS_OVERRIDE virtual bool
   RecvPowerOff()
--- a/hal/sandbox/SandboxHal.h
+++ b/hal/sandbox/SandboxHal.h
@@ -1,45 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Code.
- *
- * The Initial Developer of the Original Code is
- *   The Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
+ * 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/.
  * Contributor(s):
  *   Chris Jones <jones.chris.g@gmail.com>
  *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_SandboxHal_h
 #define mozilla_SandboxHal_h
 
 namespace mozilla {
 namespace hal_sandbox {
 
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -1,44 +1,16 @@
 #
 # ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Benjamin Smedberg <benjamin@smedbergs.us>
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
+# 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/.
 # Contributor(s):
 #   Shawn Wilsher <me@shawnwilsher.com>
 #
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
 # ***** END LICENSE BLOCK *****
 
 DEPTH     = ../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk