mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 712378: Add an interface to control lights, and use it for the screen backlight on Gonk. r=cjones
This commit is contained in:
parent
1d8f86ce62
commit
e873ad365e
@ -1,38 +1,11 @@
|
||||
# ***** 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 = ../../..
|
||||
|
47
hal/Hal.cpp
47
hal/Hal.cpp
@ -1,39 +1,12 @@
|
||||
/* -*- 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 ***** */
|
||||
|
||||
@ -344,6 +317,18 @@ void SetScreenBrightness(double brightness)
|
||||
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();
|
||||
|
52
hal/Hal.h
52
hal/Hal.h
@ -1,39 +1,12 @@
|
||||
/* -*- 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 ***** */
|
||||
|
||||
@ -170,6 +143,23 @@ double GetScreenBrightness();
|
||||
*/
|
||||
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.
|
||||
|
@ -1,40 +1,12 @@
|
||||
/* -*- 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
|
||||
|
82
hal/HalTypes.h
Normal file
82
hal/HalTypes.h
Normal file
@ -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
|
@ -62,6 +62,7 @@ EXPORTS_mozilla = \
|
||||
HalImpl.h \
|
||||
HalSandbox.h \
|
||||
HalSensor.h \
|
||||
HalTypes.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
@ -103,6 +104,10 @@ CPPSRCS += \
|
||||
$(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
|
||||
|
@ -1,39 +1,12 @@
|
||||
/* -*- 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 ***** */
|
||||
|
||||
|
28
hal/fallback/FallbackLights.cpp
Normal file
28
hal/fallback/FallbackLights.cpp
Normal file
@ -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
|
@ -1,41 +1,14 @@
|
||||
/* -*- 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 ***** */
|
||||
|
||||
@ -54,6 +27,8 @@
|
||||
#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>
|
||||
@ -314,7 +289,6 @@ 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])
|
||||
@ -374,24 +348,13 @@ SetScreenEnabled(bool 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
|
||||
@ -405,14 +368,122 @@ SetScreenBrightness(double 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;
|
||||
|
||||
WriteToFile(screenBrightnessFilename, str);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -41,8 +41,12 @@ 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 {
|
||||
@ -54,6 +58,15 @@ namespace hal {
|
||||
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;
|
||||
@ -97,6 +110,11 @@ parent:
|
||||
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();
|
||||
|
||||
|
@ -1,39 +1,12 @@
|
||||
/* -*- 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 ***** */
|
||||
|
||||
@ -152,6 +125,22 @@ 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()
|
||||
{
|
||||
@ -291,6 +280,20 @@ public:
|
||||
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()
|
||||
{
|
||||
|
@ -1,40 +1,12 @@
|
||||
/* -*- 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
|
||||
|
@ -1,39 +1,11 @@
|
||||
#
|
||||
# ***** 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 = ../..
|
||||
|
Loading…
Reference in New Issue
Block a user