2011-10-06 02:15:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-09-30 11:00:48 +04:00
|
|
|
/* vim: set sw=2 ts=8 et ft=cpp : */
|
2012-02-10 14:04:44 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-02-02 10:09:00 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2012-02-10 14:04:44 +04:00
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-06 02:15:45 +04:00
|
|
|
|
|
|
|
#include "Hal.h"
|
2011-12-18 01:04:51 +04:00
|
|
|
#include "HalImpl.h"
|
|
|
|
#include "HalSandbox.h"
|
2011-10-06 02:15:45 +04:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
2011-11-02 19:14:01 +04:00
|
|
|
#include "mozilla/Observer.h"
|
2013-05-18 00:17:53 +04:00
|
|
|
#include "nsIDocument.h"
|
2011-09-30 11:00:48 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2013-05-18 00:17:53 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2011-09-30 11:00:48 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsITabChild.h"
|
|
|
|
#include "nsIDocShell.h"
|
2012-07-26 23:33:45 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2011-12-15 19:51:11 +04:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2011-12-18 01:04:26 +04:00
|
|
|
#include "WindowIdentifier.h"
|
2012-03-13 20:42:46 +04:00
|
|
|
#include "mozilla/dom/ScreenOrientation.h"
|
2012-11-17 19:05:18 +04:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2013-02-15 00:41:30 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2011-09-30 11:00:48 +04:00
|
|
|
|
2012-08-05 09:09:39 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
|
|
|
#define getpid _getpid
|
|
|
|
#endif
|
|
|
|
|
2011-09-30 11:00:48 +04:00
|
|
|
using namespace mozilla::services;
|
2013-02-15 00:41:30 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-10-06 02:15:45 +04:00
|
|
|
|
|
|
|
#define PROXY_IF_SANDBOXED(_call) \
|
|
|
|
do { \
|
|
|
|
if (InSandbox()) { \
|
2013-02-12 08:09:25 +04:00
|
|
|
if (!hal_sandbox::HalChildDestroyed()) { \
|
2012-10-07 05:53:22 +04:00
|
|
|
hal_sandbox::_call; \
|
|
|
|
} \
|
2011-10-06 02:15:45 +04:00
|
|
|
} else { \
|
|
|
|
hal_impl::_call; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2012-10-07 05:53:22 +04:00
|
|
|
#define RETURN_PROXY_IF_SANDBOXED(_call, defValue)\
|
2011-12-04 21:07:00 +04:00
|
|
|
do { \
|
|
|
|
if (InSandbox()) { \
|
2013-02-12 08:09:25 +04:00
|
|
|
if (hal_sandbox::HalChildDestroyed()) { \
|
2012-10-07 05:53:22 +04:00
|
|
|
return defValue; \
|
|
|
|
} \
|
2011-12-04 21:07:00 +04:00
|
|
|
return hal_sandbox::_call; \
|
|
|
|
} else { \
|
|
|
|
return hal_impl::_call; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2011-10-06 02:15:45 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace hal {
|
|
|
|
|
2012-10-30 03:32:10 +04:00
|
|
|
PRLogModuleInfo *
|
|
|
|
GetHalLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sHalLog;
|
|
|
|
if (!sHalLog) {
|
|
|
|
sHalLog = PR_NewLogModule("hal");
|
|
|
|
}
|
|
|
|
return sHalLog;
|
|
|
|
}
|
2011-09-30 11:00:48 +04:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void
|
2011-10-06 02:15:45 +04:00
|
|
|
AssertMainThread()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2011-09-30 11:00:48 +04:00
|
|
|
bool
|
2011-10-06 02:15:45 +04:00
|
|
|
InSandbox()
|
|
|
|
{
|
|
|
|
return GeckoProcessType_Content == XRE_GetProcessType();
|
|
|
|
}
|
|
|
|
|
2012-09-26 13:12:33 +04:00
|
|
|
void
|
|
|
|
AssertMainProcess()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(GeckoProcessType_Default == XRE_GetProcessType());
|
|
|
|
}
|
|
|
|
|
2011-09-30 11:00:48 +04:00
|
|
|
bool
|
2013-05-05 11:03:15 +04:00
|
|
|
WindowIsActive(nsIDOMWindow* aWindow)
|
2011-09-30 11:00:48 +04:00
|
|
|
{
|
2013-05-05 11:03:15 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
|
2011-09-30 11:00:48 +04:00
|
|
|
NS_ENSURE_TRUE(window, false);
|
|
|
|
|
2013-05-05 11:03:15 +04:00
|
|
|
nsIDocument* document = window->GetDoc();
|
|
|
|
NS_ENSURE_TRUE(document, false);
|
2011-09-30 11:00:48 +04:00
|
|
|
|
2013-05-05 11:03:15 +04:00
|
|
|
return !document->Hidden();
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-26 23:33:45 +04:00
|
|
|
StaticAutoPtr<WindowIdentifier::IDArrayType> gLastIDToVibrate;
|
2011-09-30 11:00:48 +04:00
|
|
|
|
|
|
|
void InitLastIDToVibrate()
|
|
|
|
{
|
|
|
|
gLastIDToVibrate = new WindowIdentifier::IDArrayType();
|
2011-12-15 19:51:11 +04:00
|
|
|
ClearOnShutdown(&gLastIDToVibrate);
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2011-10-06 02:15:45 +04:00
|
|
|
void
|
2012-05-25 11:18:30 +04:00
|
|
|
Vibrate(const nsTArray<uint32_t>& pattern, nsIDOMWindow* window)
|
2011-09-30 11:00:48 +04:00
|
|
|
{
|
2011-12-18 01:04:26 +04:00
|
|
|
Vibrate(pattern, WindowIdentifier(window));
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-25 11:18:30 +04:00
|
|
|
Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
|
2011-10-06 02:15:45 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-09-30 11:00:48 +04:00
|
|
|
|
|
|
|
// Only active windows may start vibrations. If |id| hasn't gone
|
|
|
|
// through the IPC layer -- that is, if our caller is the outside
|
|
|
|
// world, not hal_proxy -- check whether the window is active. If
|
|
|
|
// |id| has gone through IPC, don't check the window's visibility;
|
|
|
|
// only the window corresponding to the bottommost process has its
|
|
|
|
// visibility state set correctly.
|
|
|
|
if (!id.HasTraveledThroughIPC() && !WindowIsActive(id.GetWindow())) {
|
|
|
|
HAL_LOG(("Vibrate: Window is inactive, dropping vibrate."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-08 23:35:03 +04:00
|
|
|
if (!InSandbox()) {
|
|
|
|
if (!gLastIDToVibrate) {
|
2011-09-30 11:00:48 +04:00
|
|
|
InitLastIDToVibrate();
|
2012-11-08 23:35:03 +04:00
|
|
|
}
|
2011-09-30 11:00:48 +04:00
|
|
|
*gLastIDToVibrate = id.AsArray();
|
|
|
|
}
|
2012-11-08 23:35:03 +04:00
|
|
|
|
|
|
|
// Don't forward our ID if we are not in the sandbox, because hal_impl
|
|
|
|
// doesn't need it, and we don't want it to be tempted to read it. The
|
|
|
|
// empty identifier will assert if it's used.
|
|
|
|
PROXY_IF_SANDBOXED(Vibrate(pattern, InSandbox() ? id : WindowIdentifier()));
|
2011-10-06 02:15:45 +04:00
|
|
|
}
|
|
|
|
|
2011-12-18 01:04:26 +04:00
|
|
|
void
|
|
|
|
CancelVibrate(nsIDOMWindow* window)
|
|
|
|
{
|
|
|
|
CancelVibrate(WindowIdentifier(window));
|
|
|
|
}
|
|
|
|
|
2011-09-30 11:00:48 +04:00
|
|
|
void
|
|
|
|
CancelVibrate(const WindowIdentifier &id)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
|
|
|
|
// Although only active windows may start vibrations, a window may
|
|
|
|
// cancel its own vibration even if it's no longer active.
|
|
|
|
//
|
|
|
|
// After a window is marked as inactive, it sends a CancelVibrate
|
|
|
|
// request. We want this request to cancel a playing vibration
|
|
|
|
// started by that window, so we certainly don't want to reject the
|
|
|
|
// cancellation request because the window is now inactive.
|
|
|
|
//
|
|
|
|
// But it could be the case that, after this window became inactive,
|
|
|
|
// some other window came along and started a vibration. We don't
|
|
|
|
// want this window's cancellation request to cancel that window's
|
|
|
|
// actively-playing vibration!
|
|
|
|
//
|
|
|
|
// To solve this problem, we keep track of the id of the last window
|
|
|
|
// to start a vibration, and only accepts cancellation requests from
|
|
|
|
// the same window. All other cancellation requests are ignored.
|
|
|
|
|
2012-11-08 23:35:03 +04:00
|
|
|
if (InSandbox() || (gLastIDToVibrate && *gLastIDToVibrate == id.AsArray())) {
|
|
|
|
// Don't forward our ID if we are not in the sandbox, because hal_impl
|
|
|
|
// doesn't need it, and we don't want it to be tempted to read it. The
|
|
|
|
// empty identifier will assert if it's used.
|
|
|
|
PROXY_IF_SANDBOXED(CancelVibrate(InSandbox() ? id : WindowIdentifier()));
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-04 21:07:00 +04:00
|
|
|
|
2011-12-18 01:51:44 +04:00
|
|
|
template <class InfoType>
|
|
|
|
class ObserversManager
|
2011-11-02 19:14:01 +04:00
|
|
|
{
|
|
|
|
public:
|
2011-12-18 01:51:44 +04:00
|
|
|
void AddObserver(Observer<InfoType>* aObserver) {
|
2011-11-02 19:14:01 +04:00
|
|
|
if (!mObservers) {
|
2012-02-05 23:51:06 +04:00
|
|
|
mObservers = new mozilla::ObserverList<InfoType>();
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mObservers->AddObserver(aObserver);
|
|
|
|
|
|
|
|
if (mObservers->Length() == 1) {
|
2011-12-18 01:51:44 +04:00
|
|
|
EnableNotifications();
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-18 01:51:44 +04:00
|
|
|
void RemoveObserver(Observer<InfoType>* aObserver) {
|
2012-09-07 01:58:36 +04:00
|
|
|
bool removed = mObservers && mObservers->RemoveObserver(aObserver);
|
|
|
|
if (!removed) {
|
|
|
|
NS_WARNING("RemoveObserver() called for unregistered observer");
|
2012-03-14 22:18:26 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-11-02 19:14:01 +04:00
|
|
|
|
|
|
|
if (mObservers->Length() == 0) {
|
2011-12-18 01:51:44 +04:00
|
|
|
DisableNotifications();
|
2011-11-02 19:14:01 +04:00
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
OnNotificationsDisabled();
|
|
|
|
|
2011-11-02 19:14:01 +04:00
|
|
|
delete mObservers;
|
2012-09-07 01:58:36 +04:00
|
|
|
mObservers = nullptr;
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
void BroadcastInformation(const InfoType& aInfo) {
|
2013-08-23 23:51:15 +04:00
|
|
|
// It is possible for mObservers to be nullptr here on some platforms,
|
2012-05-24 21:53:40 +04:00
|
|
|
// because a call to BroadcastInformation gets queued up asynchronously
|
|
|
|
// while RemoveObserver is running (and before the notifications are
|
|
|
|
// disabled). The queued call can then get run after mObservers has
|
|
|
|
// been nulled out. See bug 757025.
|
|
|
|
if (!mObservers) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-07 15:03:25 +04:00
|
|
|
mObservers->Broadcast(aInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void EnableNotifications() = 0;
|
|
|
|
virtual void DisableNotifications() = 0;
|
|
|
|
virtual void OnNotificationsDisabled() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mozilla::ObserverList<InfoType>* mObservers;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class InfoType>
|
|
|
|
class CachingObserversManager : public ObserversManager<InfoType>
|
|
|
|
{
|
|
|
|
public:
|
2011-12-18 01:51:44 +04:00
|
|
|
InfoType GetCurrentInformation() {
|
|
|
|
if (mHasValidCache) {
|
|
|
|
return mInfo;
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
2011-12-18 01:51:44 +04:00
|
|
|
GetCurrentInformationInternal(&mInfo);
|
2012-07-27 22:39:44 +04:00
|
|
|
mHasValidCache = true;
|
2011-12-18 01:51:44 +04:00
|
|
|
return mInfo;
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
2011-12-18 01:51:44 +04:00
|
|
|
void CacheInformation(const InfoType& aInfo) {
|
|
|
|
mHasValidCache = true;
|
|
|
|
mInfo = aInfo;
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
2011-12-18 01:51:44 +04:00
|
|
|
void BroadcastCachedInformation() {
|
2012-03-07 19:44:05 +04:00
|
|
|
this->BroadcastInformation(mInfo);
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
2011-12-18 01:51:44 +04:00
|
|
|
protected:
|
|
|
|
virtual void GetCurrentInformationInternal(InfoType*) = 0;
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
virtual void OnNotificationsDisabled() {
|
|
|
|
mHasValidCache = false;
|
|
|
|
}
|
|
|
|
|
2011-11-02 19:14:01 +04:00
|
|
|
private:
|
2011-12-18 01:51:44 +04:00
|
|
|
InfoType mInfo;
|
|
|
|
bool mHasValidCache;
|
|
|
|
};
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
class BatteryObserversManager : public CachingObserversManager<BatteryInformation>
|
2011-12-18 01:51:44 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(EnableBatteryNotifications());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(DisableBatteryNotifications());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetCurrentInformationInternal(BatteryInformation* aInfo) {
|
|
|
|
PROXY_IF_SANDBOXED(GetCurrentBatteryInformation(aInfo));
|
|
|
|
}
|
2011-11-02 19:14:01 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static BatteryObserversManager sBatteryObservers;
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
class NetworkObserversManager : public CachingObserversManager<NetworkInformation>
|
2012-01-16 17:39:57 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(EnableNetworkNotifications());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(DisableNetworkNotifications());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetCurrentInformationInternal(NetworkInformation* aInfo) {
|
|
|
|
PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static NetworkObserversManager sNetworkObservers;
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
class WakeLockObserversManager : public ObserversManager<WakeLockInformation>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(DisableWakeLockNotifications());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static WakeLockObserversManager sWakeLockObservers;
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
class ScreenConfigurationObserversManager : public CachingObserversManager<ScreenConfiguration>
|
2012-03-13 20:42:46 +04:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
2012-05-09 01:36:07 +04:00
|
|
|
PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisableNotifications() {
|
2012-05-09 01:36:07 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
void GetCurrentInformationInternal(ScreenConfiguration* aInfo) {
|
|
|
|
PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo));
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
static ScreenConfigurationObserversManager sScreenConfigurationObservers;
|
2012-03-13 20:42:46 +04:00
|
|
|
|
2011-11-02 19:14:01 +04:00
|
|
|
void
|
2011-12-18 01:51:44 +04:00
|
|
|
RegisterBatteryObserver(BatteryObserver* aObserver)
|
2011-11-02 19:14:01 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-12-18 01:51:44 +04:00
|
|
|
sBatteryObservers.AddObserver(aObserver);
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-18 01:51:44 +04:00
|
|
|
UnregisterBatteryObserver(BatteryObserver* aObserver)
|
2011-11-02 19:14:01 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-12-18 01:51:44 +04:00
|
|
|
sBatteryObservers.RemoveObserver(aObserver);
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-18 01:51:44 +04:00
|
|
|
GetCurrentBatteryInformation(BatteryInformation* aInfo)
|
2011-11-02 19:14:01 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-12-18 01:51:44 +04:00
|
|
|
*aInfo = sBatteryObservers.GetCurrentInformation();
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
2011-12-18 01:51:44 +04:00
|
|
|
void
|
|
|
|
NotifyBatteryChange(const BatteryInformation& aInfo)
|
2011-11-02 19:14:01 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-12-18 01:51:44 +04:00
|
|
|
sBatteryObservers.CacheInformation(aInfo);
|
|
|
|
sBatteryObservers.BroadcastCachedInformation();
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
|
2011-12-04 21:07:00 +04:00
|
|
|
bool GetScreenEnabled()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false);
|
2011-12-04 21:07:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetScreenEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetScreenEnabled(enabled));
|
|
|
|
}
|
|
|
|
|
2012-04-17 02:35:33 +04:00
|
|
|
bool GetCpuSleepAllowed()
|
|
|
|
{
|
|
|
|
// Generally for interfaces that are accessible by normal web content
|
|
|
|
// we should cache the result and be notified on state changes, like
|
|
|
|
// what the battery API does. But since this is only used by
|
|
|
|
// privileged interface, the synchronous getter is OK here.
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed(), true);
|
2012-04-17 02:35:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetCpuSleepAllowed(bool allowed)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetCpuSleepAllowed(allowed));
|
|
|
|
}
|
|
|
|
|
2011-12-04 21:07:00 +04:00
|
|
|
double GetScreenBrightness()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness(), 0);
|
2011-12-04 21:07:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetScreenBrightness(double brightness)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(brightness, 0.0, 1.0)));
|
|
|
|
}
|
|
|
|
|
2012-10-23 11:15:43 +04:00
|
|
|
bool SetLight(LightType light, const LightConfiguration& aConfig)
|
2012-02-02 10:09:00 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(SetLight(light, aConfig), false);
|
2012-02-02 10:09:00 +04:00
|
|
|
}
|
|
|
|
|
2012-10-23 11:15:43 +04:00
|
|
|
bool GetLight(LightType light, LightConfiguration* aConfig)
|
2012-02-02 10:09:00 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig), false);
|
2012-02-02 10:09:00 +04:00
|
|
|
}
|
|
|
|
|
2012-10-23 11:15:43 +04:00
|
|
|
class SystemClockChangeObserversManager : public ObserversManager<int64_t>
|
2012-09-11 10:40:00 +04:00
|
|
|
{
|
2012-09-23 21:00:32 +04:00
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
2012-10-23 11:15:43 +04:00
|
|
|
PROXY_IF_SANDBOXED(EnableSystemClockChangeNotifications());
|
2012-09-11 10:40:00 +04:00
|
|
|
}
|
2012-09-23 21:00:32 +04:00
|
|
|
|
|
|
|
void DisableNotifications() {
|
2012-10-23 11:15:43 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableSystemClockChangeNotifications());
|
2012-09-23 21:00:32 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-23 11:15:43 +04:00
|
|
|
static SystemClockChangeObserversManager sSystemClockChangeObservers;
|
2012-09-11 10:40:00 +04:00
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
RegisterSystemClockChangeObserver(SystemClockChangeObserver* aObserver)
|
2012-09-11 10:40:00 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-23 11:15:43 +04:00
|
|
|
sSystemClockChangeObservers.AddObserver(aObserver);
|
2012-09-11 10:40:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
UnregisterSystemClockChangeObserver(SystemClockChangeObserver* aObserver)
|
2012-09-11 10:40:00 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-23 11:15:43 +04:00
|
|
|
sSystemClockChangeObservers.RemoveObserver(aObserver);
|
2012-09-11 10:40:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
NotifySystemClockChange(const int64_t& aClockDeltaMS)
|
2012-09-11 10:40:00 +04:00
|
|
|
{
|
2012-10-23 11:15:43 +04:00
|
|
|
sSystemClockChangeObservers.BroadcastInformation(aClockDeltaMS);
|
2012-09-11 10:40:00 +04:00
|
|
|
}
|
2012-10-23 11:15:43 +04:00
|
|
|
|
|
|
|
class SystemTimezoneChangeObserversManager : public ObserversManager<SystemTimezoneChangeInformation>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(EnableSystemTimezoneChangeNotifications());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(DisableSystemTimezoneChangeNotifications());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static SystemTimezoneChangeObserversManager sSystemTimezoneChangeObservers;
|
|
|
|
|
|
|
|
void
|
|
|
|
RegisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sSystemTimezoneChangeObservers.AddObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sSystemTimezoneChangeObservers.RemoveObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifySystemTimezoneChange(const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
|
|
|
|
{
|
|
|
|
sSystemTimezoneChangeObservers.BroadcastInformation(aSystemTimezoneChangeInfo);
|
|
|
|
}
|
|
|
|
|
2012-02-17 14:44:00 +04:00
|
|
|
void
|
2012-09-26 07:51:29 +04:00
|
|
|
AdjustSystemClock(int64_t aDeltaMilliseconds)
|
2012-02-17 14:44:00 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(AdjustSystemClock(aDeltaMilliseconds));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetTimezone(const nsCString& aTimezoneSpec)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetTimezone(aTimezoneSpec));
|
|
|
|
}
|
|
|
|
|
2013-10-15 12:43:53 +04:00
|
|
|
int32_t
|
|
|
|
GetTimezoneOffset()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetTimezoneOffset(), 0);
|
|
|
|
}
|
|
|
|
|
2012-08-23 13:00:00 +04:00
|
|
|
nsCString
|
|
|
|
GetTimezone()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetTimezone(), nsCString(""));
|
2012-08-23 13:00:00 +04:00
|
|
|
}
|
|
|
|
|
2012-02-05 23:51:06 +04:00
|
|
|
void
|
|
|
|
EnableSensorNotifications(SensorType aSensor) {
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(EnableSensorNotifications(aSensor));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableSensorNotifications(SensorType aSensor) {
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(DisableSensorNotifications(aSensor));
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef mozilla::ObserverList<SensorData> SensorObserverList;
|
2012-09-07 01:58:36 +04:00
|
|
|
static SensorObserverList* gSensorObservers = nullptr;
|
2012-02-05 23:51:06 +04:00
|
|
|
|
|
|
|
static SensorObserverList &
|
|
|
|
GetSensorObservers(SensorType sensor_type) {
|
|
|
|
MOZ_ASSERT(sensor_type < NUM_SENSOR_TYPE);
|
|
|
|
|
2012-09-07 01:58:36 +04:00
|
|
|
if(!gSensorObservers) {
|
2012-02-05 23:51:06 +04:00
|
|
|
gSensorObservers = new SensorObserverList[NUM_SENSOR_TYPE];
|
2012-09-07 01:58:36 +04:00
|
|
|
}
|
2012-02-05 23:51:06 +04:00
|
|
|
return gSensorObservers[sensor_type];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RegisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
|
|
|
|
SensorObserverList &observers = GetSensorObservers(aSensor);
|
|
|
|
|
|
|
|
AssertMainThread();
|
|
|
|
|
|
|
|
observers.AddObserver(aObserver);
|
|
|
|
if(observers.Length() == 1) {
|
|
|
|
EnableSensorNotifications(aSensor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
|
|
|
|
AssertMainThread();
|
2012-09-07 01:58:36 +04:00
|
|
|
|
|
|
|
if (!gSensorObservers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SensorObserverList &observers = GetSensorObservers(aSensor);
|
|
|
|
if (!observers.RemoveObserver(aObserver) || observers.Length() > 0) {
|
2012-05-21 14:12:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
DisableSensorNotifications(aSensor);
|
|
|
|
|
|
|
|
// Destroy sSensorObservers only if all observer lists are empty.
|
|
|
|
for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
|
|
|
|
if (gSensorObservers[i].Length() > 0) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-05 23:51:06 +04:00
|
|
|
}
|
2012-05-21 14:12:03 +04:00
|
|
|
delete [] gSensorObservers;
|
2012-07-30 18:20:58 +04:00
|
|
|
gSensorObservers = nullptr;
|
2012-02-05 23:51:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifySensorChange(const SensorData &aSensorData) {
|
|
|
|
SensorObserverList &observers = GetSensorObservers(aSensorData.sensor());
|
|
|
|
|
|
|
|
AssertMainThread();
|
|
|
|
|
|
|
|
observers.Broadcast(aSensorData);
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:39:57 +04:00
|
|
|
void
|
|
|
|
RegisterNetworkObserver(NetworkObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sNetworkObservers.AddObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterNetworkObserver(NetworkObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sNetworkObservers.RemoveObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetCurrentNetworkInformation(NetworkInformation* aInfo)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
*aInfo = sNetworkObservers.GetCurrentInformation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyNetworkChange(const NetworkInformation& aInfo)
|
|
|
|
{
|
|
|
|
sNetworkObservers.CacheInformation(aInfo);
|
|
|
|
sNetworkObservers.BroadcastCachedInformation();
|
|
|
|
}
|
|
|
|
|
2012-01-31 10:08:00 +04:00
|
|
|
void Reboot()
|
|
|
|
{
|
2012-09-26 13:12:33 +04:00
|
|
|
AssertMainProcess();
|
2012-01-31 10:08:00 +04:00
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(Reboot());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PowerOff()
|
|
|
|
{
|
2012-09-26 13:12:33 +04:00
|
|
|
AssertMainProcess();
|
2012-01-31 10:08:00 +04:00
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(PowerOff());
|
|
|
|
}
|
|
|
|
|
2012-10-02 11:26:32 +04:00
|
|
|
void StartForceQuitWatchdog(ShutdownMode aMode, int32_t aTimeoutSecs)
|
|
|
|
{
|
|
|
|
AssertMainProcess();
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(StartForceQuitWatchdog(aMode, aTimeoutSecs));
|
|
|
|
}
|
|
|
|
|
2011-08-03 22:12:08 +04:00
|
|
|
void StartMonitoringGamepadStatus()
|
|
|
|
{
|
|
|
|
PROXY_IF_SANDBOXED(StartMonitoringGamepadStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StopMonitoringGamepadStatus()
|
|
|
|
{
|
|
|
|
PROXY_IF_SANDBOXED(StopMonitoringGamepadStatus());
|
|
|
|
}
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
void
|
|
|
|
RegisterWakeLockObserver(WakeLockObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sWakeLockObservers.AddObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterWakeLockObserver(WakeLockObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sWakeLockObservers.RemoveObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-17 19:05:18 +04:00
|
|
|
ModifyWakeLock(const nsAString& aTopic,
|
2012-10-23 11:15:43 +04:00
|
|
|
WakeLockControl aLockAdjust,
|
2013-02-15 00:41:30 +04:00
|
|
|
WakeLockControl aHiddenAdjust,
|
|
|
|
uint64_t aProcessID /* = CONTENT_PROCESS_ID_UNKNOWN */)
|
2012-03-07 15:03:25 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
|
2013-02-15 00:41:30 +04:00
|
|
|
if (aProcessID == CONTENT_PROCESS_ID_UNKNOWN) {
|
|
|
|
aProcessID = InSandbox() ? ContentChild::GetSingleton()->GetID() :
|
|
|
|
CONTENT_PROCESS_ID_MAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
PROXY_IF_SANDBOXED(ModifyWakeLock(aTopic, aLockAdjust,
|
|
|
|
aHiddenAdjust, aProcessID));
|
2012-11-17 19:05:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetWakeLockInfo(const nsAString& aTopic, WakeLockInformation* aWakeLockInfo)
|
2012-03-07 15:03:25 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(GetWakeLockInfo(aTopic, aWakeLockInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyWakeLockChange(const WakeLockInformation& aInfo)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sWakeLockObservers.BroadcastInformation(aInfo);
|
|
|
|
}
|
|
|
|
|
2012-03-13 20:42:46 +04:00
|
|
|
void
|
2012-05-09 01:36:07 +04:00
|
|
|
RegisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
|
2012-03-13 20:42:46 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-05-09 01:36:07 +04:00
|
|
|
sScreenConfigurationObservers.AddObserver(aObserver);
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-09 01:36:07 +04:00
|
|
|
UnregisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
|
2012-03-13 20:42:46 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-05-09 01:36:07 +04:00
|
|
|
sScreenConfigurationObservers.RemoveObserver(aObserver);
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-09 01:36:07 +04:00
|
|
|
GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
|
2012-03-13 20:42:46 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-05-09 01:36:07 +04:00
|
|
|
*aScreenConfiguration = sScreenConfigurationObservers.GetCurrentInformation();
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-09 01:36:07 +04:00
|
|
|
NotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration)
|
2012-03-13 20:42:46 +04:00
|
|
|
{
|
2012-05-09 01:36:07 +04:00
|
|
|
sScreenConfigurationObservers.CacheInformation(aScreenConfiguration);
|
|
|
|
sScreenConfigurationObservers.BroadcastCachedInformation();
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
2012-03-29 23:43:16 +04:00
|
|
|
bool
|
|
|
|
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation), false);
|
2012-03-29 23:43:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnlockScreenOrientation()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(UnlockScreenOrientation());
|
|
|
|
}
|
|
|
|
|
2012-04-22 22:09:22 +04:00
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
EnableSwitchNotifications(SwitchDevice aDevice) {
|
2012-04-22 22:09:22 +04:00
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(EnableSwitchNotifications(aDevice));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
DisableSwitchNotifications(SwitchDevice aDevice) {
|
2012-04-22 22:09:22 +04:00
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(DisableSwitchNotifications(aDevice));
|
|
|
|
}
|
|
|
|
|
2012-10-23 11:15:43 +04:00
|
|
|
SwitchState GetCurrentSwitchState(SwitchDevice aDevice)
|
2012-04-22 22:09:22 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetCurrentSwitchState(aDevice), SWITCH_STATE_UNKNOWN);
|
2012-04-22 22:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef mozilla::ObserverList<SwitchEvent> SwitchObserverList;
|
|
|
|
|
2013-08-23 23:51:15 +04:00
|
|
|
static SwitchObserverList *sSwitchObserverLists = nullptr;
|
2012-04-22 22:09:22 +04:00
|
|
|
|
|
|
|
static SwitchObserverList&
|
2012-10-23 11:15:43 +04:00
|
|
|
GetSwitchObserverList(SwitchDevice aDevice) {
|
2012-04-22 22:09:22 +04:00
|
|
|
MOZ_ASSERT(0 <= aDevice && aDevice < NUM_SWITCH_DEVICE);
|
2013-08-23 23:51:15 +04:00
|
|
|
if (sSwitchObserverLists == nullptr) {
|
2012-04-22 22:09:22 +04:00
|
|
|
sSwitchObserverLists = new SwitchObserverList[NUM_SWITCH_DEVICE];
|
|
|
|
}
|
|
|
|
return sSwitchObserverLists[aDevice];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ReleaseObserversIfNeeded() {
|
|
|
|
for (int i = 0; i < NUM_SWITCH_DEVICE; i++) {
|
|
|
|
if (sSwitchObserverLists[i].Length() != 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//The length of every list is 0, no observer in the list.
|
|
|
|
delete [] sSwitchObserverLists;
|
2013-08-23 23:51:15 +04:00
|
|
|
sSwitchObserverLists = nullptr;
|
2012-04-22 22:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
RegisterSwitchObserver(SwitchDevice aDevice, SwitchObserver *aObserver)
|
2012-04-22 22:09:22 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
SwitchObserverList& observer = GetSwitchObserverList(aDevice);
|
|
|
|
observer.AddObserver(aObserver);
|
|
|
|
if (observer.Length() == 1) {
|
|
|
|
EnableSwitchNotifications(aDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
UnregisterSwitchObserver(SwitchDevice aDevice, SwitchObserver *aObserver)
|
2012-04-22 22:09:22 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-09-07 01:58:36 +04:00
|
|
|
|
|
|
|
if (!sSwitchObserverLists) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-22 22:09:22 +04:00
|
|
|
SwitchObserverList& observer = GetSwitchObserverList(aDevice);
|
2012-09-07 01:58:36 +04:00
|
|
|
if (!observer.RemoveObserver(aObserver) || observer.Length() > 0) {
|
|
|
|
return;
|
2012-04-22 22:09:22 +04:00
|
|
|
}
|
2012-09-07 01:58:36 +04:00
|
|
|
|
|
|
|
DisableSwitchNotifications(aDevice);
|
|
|
|
ReleaseObserversIfNeeded();
|
2012-04-22 22:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
NotifySwitchChange(const SwitchEvent& aEvent)
|
2012-04-22 22:09:22 +04:00
|
|
|
{
|
|
|
|
// When callback this notification, main thread may call unregister function
|
|
|
|
// first. We should check if this pointer is valid.
|
|
|
|
if (!sSwitchObserverLists)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SwitchObserverList& observer = GetSwitchObserverList(aEvent.device());
|
|
|
|
observer.Broadcast(aEvent);
|
|
|
|
}
|
|
|
|
|
2012-07-06 14:42:10 +04:00
|
|
|
static AlarmObserver* sAlarmObserver;
|
|
|
|
|
|
|
|
bool
|
|
|
|
RegisterTheOneAlarmObserver(AlarmObserver* aObserver)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!InSandbox());
|
|
|
|
MOZ_ASSERT(!sAlarmObserver);
|
|
|
|
|
|
|
|
sAlarmObserver = aObserver;
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(EnableAlarm(), false);
|
2012-07-06 14:42:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterTheOneAlarmObserver()
|
|
|
|
{
|
|
|
|
if (sAlarmObserver) {
|
2012-09-07 01:58:36 +04:00
|
|
|
sAlarmObserver = nullptr;
|
2012-07-06 14:42:10 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableAlarm());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyAlarmFired()
|
|
|
|
{
|
|
|
|
if (sAlarmObserver) {
|
|
|
|
sAlarmObserver->Notify(void_t());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
|
2012-07-06 14:42:10 +04:00
|
|
|
{
|
|
|
|
// It's pointless to program an alarm nothing is going to observe ...
|
|
|
|
MOZ_ASSERT(sAlarmObserver);
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds, aNanoseconds), false);
|
2012-07-06 14:42:10 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 09:09:39 +04:00
|
|
|
void
|
2013-05-10 00:27:06 +04:00
|
|
|
SetProcessPriority(int aPid,
|
|
|
|
ProcessPriority aPriority,
|
2013-10-01 07:54:59 +04:00
|
|
|
ProcessCPUPriority aCPUPriority,
|
|
|
|
uint32_t aBackgroundLRU)
|
2012-08-05 09:09:39 +04:00
|
|
|
{
|
2013-05-10 00:27:06 +04:00
|
|
|
// n.b. The sandboxed implementation crashes; SetProcessPriority works only
|
|
|
|
// from the main process.
|
2013-10-01 07:54:59 +04:00
|
|
|
MOZ_ASSERT(aBackgroundLRU == 0 || aPriority == PROCESS_PRIORITY_BACKGROUND);
|
|
|
|
PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority, aCPUPriority,
|
|
|
|
aBackgroundLRU));
|
2012-08-05 09:09:39 +04:00
|
|
|
}
|
|
|
|
|
2013-02-08 18:32:23 +04:00
|
|
|
// From HalTypes.h.
|
|
|
|
const char*
|
|
|
|
ProcessPriorityToString(ProcessPriority aPriority)
|
|
|
|
{
|
|
|
|
switch (aPriority) {
|
|
|
|
case PROCESS_PRIORITY_MASTER:
|
|
|
|
return "MASTER";
|
2013-02-15 00:41:30 +04:00
|
|
|
case PROCESS_PRIORITY_FOREGROUND_HIGH:
|
|
|
|
return "FOREGROUND_HIGH";
|
2013-02-08 18:32:23 +04:00
|
|
|
case PROCESS_PRIORITY_FOREGROUND:
|
|
|
|
return "FOREGROUND";
|
2013-09-24 12:10:20 +04:00
|
|
|
case PROCESS_PRIORITY_FOREGROUND_KEYBOARD:
|
|
|
|
return "FOREGROUND_KEYBOARD";
|
2013-02-08 18:32:23 +04:00
|
|
|
case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
|
|
|
|
return "BACKGROUND_PERCEIVABLE";
|
|
|
|
case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
|
|
|
|
return "BACKGROUND_HOMESCREEN";
|
|
|
|
case PROCESS_PRIORITY_BACKGROUND:
|
|
|
|
return "BACKGROUND";
|
2013-02-23 08:24:28 +04:00
|
|
|
case PROCESS_PRIORITY_UNKNOWN:
|
|
|
|
return "UNKNOWN";
|
2013-02-08 18:32:23 +04:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-10 00:27:06 +04:00
|
|
|
// From HalTypes.h.
|
|
|
|
const char*
|
|
|
|
ProcessPriorityToString(ProcessPriority aPriority,
|
|
|
|
ProcessCPUPriority aCPUPriority)
|
|
|
|
{
|
|
|
|
// Sorry this is ugly. At least it's all in one place.
|
|
|
|
//
|
|
|
|
// We intentionally fall through if aCPUPriority is invalid; we won't hit any
|
|
|
|
// of the if statements further down, so it's OK.
|
|
|
|
|
|
|
|
switch (aPriority) {
|
|
|
|
case PROCESS_PRIORITY_MASTER:
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
return "MASTER:CPU_NORMAL";
|
|
|
|
}
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
return "MASTER:CPU_LOW";
|
|
|
|
}
|
|
|
|
case PROCESS_PRIORITY_FOREGROUND_HIGH:
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
return "FOREGROUND_HIGH:CPU_NORMAL";
|
|
|
|
}
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
return "FOREGROUND_HIGH:CPU_LOW";
|
|
|
|
}
|
|
|
|
case PROCESS_PRIORITY_FOREGROUND:
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
return "FOREGROUND:CPU_NORMAL";
|
|
|
|
}
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
return "FOREGROUND:CPU_LOW";
|
|
|
|
}
|
2013-09-24 12:10:20 +04:00
|
|
|
case PROCESS_PRIORITY_FOREGROUND_KEYBOARD:
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
return "FOREGROUND_KEYBOARD:CPU_NORMAL";
|
|
|
|
}
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
return "FOREGROUND_KEYBOARD:CPU_LOW";
|
|
|
|
}
|
2013-05-10 00:27:06 +04:00
|
|
|
case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
return "BACKGROUND_PERCEIVABLE:CPU_NORMAL";
|
|
|
|
}
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
return "BACKGROUND_PERCEIVABLE:CPU_LOW";
|
|
|
|
}
|
|
|
|
case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
return "BACKGROUND_HOMESCREEN:CPU_NORMAL";
|
|
|
|
}
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
return "BACKGROUND_HOMESCREEN:CPU_LOW";
|
|
|
|
}
|
|
|
|
case PROCESS_PRIORITY_BACKGROUND:
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
return "BACKGROUND:CPU_NORMAL";
|
|
|
|
}
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
return "BACKGROUND:CPU_LOW";
|
|
|
|
}
|
|
|
|
case PROCESS_PRIORITY_UNKNOWN:
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
return "UNKNOWN:CPU_NORMAL";
|
|
|
|
}
|
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
return "UNKNOWN:CPU_LOW";
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// Fall through. (|default| is here to silence warnings.)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
|
2012-09-19 19:17:13 +04:00
|
|
|
static StaticAutoPtr<ObserverList<FMRadioOperationInformation> > sFMRadioObservers;
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitializeFMRadioObserver()
|
|
|
|
{
|
|
|
|
if (!sFMRadioObservers) {
|
|
|
|
sFMRadioObservers = new ObserverList<FMRadioOperationInformation>;
|
|
|
|
ClearOnShutdown(&sFMRadioObservers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RegisterFMRadioObserver(FMRadioObserver* aFMRadioObserver) {
|
|
|
|
AssertMainThread();
|
|
|
|
InitializeFMRadioObserver();
|
|
|
|
sFMRadioObservers->AddObserver(aFMRadioObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterFMRadioObserver(FMRadioObserver* aFMRadioObserver) {
|
|
|
|
AssertMainThread();
|
|
|
|
InitializeFMRadioObserver();
|
|
|
|
sFMRadioObservers->RemoveObserver(aFMRadioObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyFMRadioStatus(const FMRadioOperationInformation& aFMRadioState) {
|
|
|
|
InitializeFMRadioObserver();
|
|
|
|
sFMRadioObservers->Broadcast(aFMRadioState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EnableFMRadio(const FMRadioSettings& aInfo) {
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(EnableFMRadio(aInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableFMRadio() {
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(DisableFMRadio());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FMRadioSeek(const FMRadioSeekDirection& aDirection) {
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(FMRadioSeek(aDirection));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetFMRadioSettings(FMRadioSettings* aInfo) {
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(GetFMRadioSettings(aInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetFMRadioFrequency(const uint32_t aFrequency) {
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetFMRadioFrequency(aFrequency));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GetFMRadioFrequency() {
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetFMRadioFrequency(), 0);
|
2012-09-19 19:17:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsFMRadioOn() {
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(IsFMRadioOn(), false);
|
2012-09-19 19:17:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GetFMRadioSignalStrength() {
|
|
|
|
AssertMainThread();
|
2012-10-07 05:53:22 +04:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetFMRadioSignalStrength(), 0);
|
2012-09-19 19:17:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CancelFMRadioSeek() {
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(CancelFMRadioSeek());
|
|
|
|
}
|
|
|
|
|
|
|
|
FMRadioSettings
|
|
|
|
GetFMBandSettings(FMRadioCountry aCountry) {
|
|
|
|
FMRadioSettings settings;
|
|
|
|
|
|
|
|
switch (aCountry) {
|
|
|
|
case FM_RADIO_COUNTRY_US:
|
|
|
|
case FM_RADIO_COUNTRY_EU:
|
|
|
|
settings.upperLimit() = 108000;
|
|
|
|
settings.lowerLimit() = 87800;
|
|
|
|
settings.spaceType() = 200;
|
|
|
|
settings.preEmphasis() = 75;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_JP_STANDARD:
|
|
|
|
settings.upperLimit() = 76000;
|
|
|
|
settings.lowerLimit() = 90000;
|
|
|
|
settings.spaceType() = 100;
|
|
|
|
settings.preEmphasis() = 50;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_CY:
|
|
|
|
case FM_RADIO_COUNTRY_DE:
|
|
|
|
case FM_RADIO_COUNTRY_DK:
|
|
|
|
case FM_RADIO_COUNTRY_ES:
|
|
|
|
case FM_RADIO_COUNTRY_FI:
|
|
|
|
case FM_RADIO_COUNTRY_FR:
|
|
|
|
case FM_RADIO_COUNTRY_HU:
|
|
|
|
case FM_RADIO_COUNTRY_IR:
|
|
|
|
case FM_RADIO_COUNTRY_IT:
|
|
|
|
case FM_RADIO_COUNTRY_KW:
|
|
|
|
case FM_RADIO_COUNTRY_LT:
|
|
|
|
case FM_RADIO_COUNTRY_ML:
|
|
|
|
case FM_RADIO_COUNTRY_NO:
|
|
|
|
case FM_RADIO_COUNTRY_OM:
|
|
|
|
case FM_RADIO_COUNTRY_PG:
|
|
|
|
case FM_RADIO_COUNTRY_NL:
|
|
|
|
case FM_RADIO_COUNTRY_CZ:
|
|
|
|
case FM_RADIO_COUNTRY_UK:
|
|
|
|
case FM_RADIO_COUNTRY_RW:
|
|
|
|
case FM_RADIO_COUNTRY_SN:
|
|
|
|
case FM_RADIO_COUNTRY_SI:
|
|
|
|
case FM_RADIO_COUNTRY_ZA:
|
|
|
|
case FM_RADIO_COUNTRY_SE:
|
|
|
|
case FM_RADIO_COUNTRY_CH:
|
|
|
|
case FM_RADIO_COUNTRY_TW:
|
|
|
|
case FM_RADIO_COUNTRY_UA:
|
|
|
|
settings.upperLimit() = 108000;
|
|
|
|
settings.lowerLimit() = 87500;
|
|
|
|
settings.spaceType() = 100;
|
|
|
|
settings.preEmphasis() = 50;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_VA:
|
|
|
|
case FM_RADIO_COUNTRY_MA:
|
|
|
|
case FM_RADIO_COUNTRY_TR:
|
|
|
|
settings.upperLimit() = 10800;
|
|
|
|
settings.lowerLimit() = 87500;
|
|
|
|
settings.spaceType() = 100;
|
|
|
|
settings.preEmphasis() = 75;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_AU:
|
|
|
|
case FM_RADIO_COUNTRY_BD:
|
|
|
|
settings.upperLimit() = 108000;
|
|
|
|
settings.lowerLimit() = 87500;
|
|
|
|
settings.spaceType() = 200;
|
|
|
|
settings.preEmphasis() = 75;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_AW:
|
|
|
|
case FM_RADIO_COUNTRY_BS:
|
|
|
|
case FM_RADIO_COUNTRY_CO:
|
|
|
|
case FM_RADIO_COUNTRY_KR:
|
|
|
|
settings.upperLimit() = 108000;
|
|
|
|
settings.lowerLimit() = 88000;
|
|
|
|
settings.spaceType() = 200;
|
|
|
|
settings.preEmphasis() = 75;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_EC:
|
|
|
|
settings.upperLimit() = 108000;
|
|
|
|
settings.lowerLimit() = 88000;
|
|
|
|
settings.spaceType() = 200;
|
|
|
|
settings.preEmphasis() = 0;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_GM:
|
|
|
|
settings.upperLimit() = 108000;
|
|
|
|
settings.lowerLimit() = 88000;
|
|
|
|
settings.spaceType() = 0;
|
|
|
|
settings.preEmphasis() = 75;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_QA:
|
|
|
|
settings.upperLimit() = 108000;
|
|
|
|
settings.lowerLimit() = 88000;
|
|
|
|
settings.spaceType() = 200;
|
|
|
|
settings.preEmphasis() = 50;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_SG:
|
|
|
|
settings.upperLimit() = 108000;
|
|
|
|
settings.lowerLimit() = 88000;
|
|
|
|
settings.spaceType() = 200;
|
|
|
|
settings.preEmphasis() = 50;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_IN:
|
|
|
|
settings.upperLimit() = 100000;
|
|
|
|
settings.lowerLimit() = 108000;
|
|
|
|
settings.spaceType() = 100;
|
|
|
|
settings.preEmphasis() = 50;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_NZ:
|
|
|
|
settings.upperLimit() = 100000;
|
|
|
|
settings.lowerLimit() = 88000;
|
|
|
|
settings.spaceType() = 50;
|
|
|
|
settings.preEmphasis() = 50;
|
|
|
|
break;
|
|
|
|
case FM_RADIO_COUNTRY_USER_DEFINED:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(0);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2012-10-04 13:28:34 +04:00
|
|
|
void FactoryReset()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(FactoryReset());
|
|
|
|
}
|
|
|
|
|
2013-05-10 02:57:31 +04:00
|
|
|
void
|
|
|
|
StartDiskSpaceWatcher()
|
|
|
|
{
|
|
|
|
AssertMainProcess();
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(StartDiskSpaceWatcher());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StopDiskSpaceWatcher()
|
|
|
|
{
|
|
|
|
AssertMainProcess();
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(StopDiskSpaceWatcher());
|
|
|
|
}
|
|
|
|
|
2013-10-22 23:15:24 +04:00
|
|
|
uint32_t
|
|
|
|
GetTotalSystemMemory()
|
|
|
|
{
|
|
|
|
return hal_impl::GetTotalSystemMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-06 02:15:45 +04:00
|
|
|
} // namespace hal
|
|
|
|
} // namespace mozilla
|