2011-10-05 22:15:45 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-09-30 07:00:48 +00:00
|
|
|
/* vim: set sw=2 ts=8 et ft=cpp : */
|
2012-02-10 10:04:44 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-02-02 06:09:00 +00:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2012-02-10 10:04:44 +00:00
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-05 22:15:45 +00:00
|
|
|
|
|
|
|
#include "Hal.h"
|
2011-12-17 21:04:51 +00:00
|
|
|
#include "HalImpl.h"
|
|
|
|
#include "HalSandbox.h"
|
2011-10-05 22:15:45 +00:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
2011-11-02 15:14:01 +00:00
|
|
|
#include "mozilla/Observer.h"
|
2013-05-17 20:17:53 +00:00
|
|
|
#include "nsIDocument.h"
|
2011-09-30 07:00:48 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
2013-05-17 20:17:53 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2011-09-30 07:00:48 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsITabChild.h"
|
|
|
|
#include "nsIDocShell.h"
|
2012-07-26 19:33:45 +00:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2011-12-15 15:51:11 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2011-12-17 21:04:26 +00:00
|
|
|
#include "WindowIdentifier.h"
|
2012-03-13 16:42:46 +00:00
|
|
|
#include "mozilla/dom/ScreenOrientation.h"
|
2012-11-17 15:05:18 +00:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2013-02-14 20:41:30 +00:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2011-09-30 07:00:48 +00:00
|
|
|
|
2012-08-05 05:09:39 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
|
|
|
#define getpid _getpid
|
|
|
|
#endif
|
|
|
|
|
2011-09-30 07:00:48 +00:00
|
|
|
using namespace mozilla::services;
|
2013-02-14 20:41:30 +00:00
|
|
|
using namespace mozilla::dom;
|
2011-10-05 22:15:45 +00:00
|
|
|
|
|
|
|
#define PROXY_IF_SANDBOXED(_call) \
|
|
|
|
do { \
|
|
|
|
if (InSandbox()) { \
|
2013-02-12 04:09:25 +00:00
|
|
|
if (!hal_sandbox::HalChildDestroyed()) { \
|
2012-10-07 01:53:22 +00:00
|
|
|
hal_sandbox::_call; \
|
|
|
|
} \
|
2011-10-05 22:15:45 +00:00
|
|
|
} else { \
|
|
|
|
hal_impl::_call; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2012-10-07 01:53:22 +00:00
|
|
|
#define RETURN_PROXY_IF_SANDBOXED(_call, defValue)\
|
2011-12-04 17:07:00 +00:00
|
|
|
do { \
|
|
|
|
if (InSandbox()) { \
|
2013-02-12 04:09:25 +00:00
|
|
|
if (hal_sandbox::HalChildDestroyed()) { \
|
2012-10-07 01:53:22 +00:00
|
|
|
return defValue; \
|
|
|
|
} \
|
2011-12-04 17:07:00 +00:00
|
|
|
return hal_sandbox::_call; \
|
|
|
|
} else { \
|
|
|
|
return hal_impl::_call; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2011-10-05 22:15:45 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace hal {
|
|
|
|
|
2012-10-29 23:32:10 +00:00
|
|
|
PRLogModuleInfo *
|
|
|
|
GetHalLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sHalLog;
|
|
|
|
if (!sHalLog) {
|
|
|
|
sHalLog = PR_NewLogModule("hal");
|
|
|
|
}
|
|
|
|
return sHalLog;
|
|
|
|
}
|
2011-09-30 07:00:48 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void
|
2011-10-05 22:15:45 +00:00
|
|
|
AssertMainThread()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2011-09-30 07:00:48 +00:00
|
|
|
bool
|
2011-10-05 22:15:45 +00:00
|
|
|
InSandbox()
|
|
|
|
{
|
|
|
|
return GeckoProcessType_Content == XRE_GetProcessType();
|
|
|
|
}
|
|
|
|
|
2012-09-26 09:12:33 +00:00
|
|
|
void
|
|
|
|
AssertMainProcess()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(GeckoProcessType_Default == XRE_GetProcessType());
|
|
|
|
}
|
|
|
|
|
2011-09-30 07:00:48 +00:00
|
|
|
bool
|
2013-05-05 07:03:15 +00:00
|
|
|
WindowIsActive(nsIDOMWindow* aWindow)
|
2011-09-30 07:00:48 +00:00
|
|
|
{
|
2013-05-05 07:03:15 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
|
2011-09-30 07:00:48 +00:00
|
|
|
NS_ENSURE_TRUE(window, false);
|
|
|
|
|
2013-05-05 07:03:15 +00:00
|
|
|
nsIDocument* document = window->GetDoc();
|
|
|
|
NS_ENSURE_TRUE(document, false);
|
2011-09-30 07:00:48 +00:00
|
|
|
|
2013-05-05 07:03:15 +00:00
|
|
|
return !document->Hidden();
|
2011-09-30 07:00:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 19:33:45 +00:00
|
|
|
StaticAutoPtr<WindowIdentifier::IDArrayType> gLastIDToVibrate;
|
2011-09-30 07:00:48 +00:00
|
|
|
|
|
|
|
void InitLastIDToVibrate()
|
|
|
|
{
|
|
|
|
gLastIDToVibrate = new WindowIdentifier::IDArrayType();
|
2011-12-15 15:51:11 +00:00
|
|
|
ClearOnShutdown(&gLastIDToVibrate);
|
2011-09-30 07:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2011-10-05 22:15:45 +00:00
|
|
|
void
|
2012-05-25 07:18:30 +00:00
|
|
|
Vibrate(const nsTArray<uint32_t>& pattern, nsIDOMWindow* window)
|
2011-09-30 07:00:48 +00:00
|
|
|
{
|
2011-12-17 21:04:26 +00:00
|
|
|
Vibrate(pattern, WindowIdentifier(window));
|
2011-09-30 07:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-25 07:18:30 +00:00
|
|
|
Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
|
2011-10-05 22:15:45 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-09-30 07:00:48 +00: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 19:35:03 +00:00
|
|
|
if (!InSandbox()) {
|
|
|
|
if (!gLastIDToVibrate) {
|
2011-09-30 07:00:48 +00:00
|
|
|
InitLastIDToVibrate();
|
2012-11-08 19:35:03 +00:00
|
|
|
}
|
2011-09-30 07:00:48 +00:00
|
|
|
*gLastIDToVibrate = id.AsArray();
|
|
|
|
}
|
2012-11-08 19:35:03 +00: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-05 22:15:45 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 21:04:26 +00:00
|
|
|
void
|
|
|
|
CancelVibrate(nsIDOMWindow* window)
|
|
|
|
{
|
|
|
|
CancelVibrate(WindowIdentifier(window));
|
|
|
|
}
|
|
|
|
|
2011-09-30 07:00:48 +00: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 19:35:03 +00: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 07:00:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-04 17:07:00 +00:00
|
|
|
|
2011-12-17 21:51:44 +00:00
|
|
|
template <class InfoType>
|
|
|
|
class ObserversManager
|
2011-11-02 15:14:01 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-12-17 21:51:44 +00:00
|
|
|
void AddObserver(Observer<InfoType>* aObserver) {
|
2011-11-02 15:14:01 +00:00
|
|
|
if (!mObservers) {
|
2012-02-05 19:51:06 +00:00
|
|
|
mObservers = new mozilla::ObserverList<InfoType>();
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mObservers->AddObserver(aObserver);
|
|
|
|
|
|
|
|
if (mObservers->Length() == 1) {
|
2011-12-17 21:51:44 +00:00
|
|
|
EnableNotifications();
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 21:51:44 +00:00
|
|
|
void RemoveObserver(Observer<InfoType>* aObserver) {
|
2012-09-06 21:58:36 +00:00
|
|
|
bool removed = mObservers && mObservers->RemoveObserver(aObserver);
|
|
|
|
if (!removed) {
|
|
|
|
NS_WARNING("RemoveObserver() called for unregistered observer");
|
2012-03-14 18:18:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-02 15:14:01 +00:00
|
|
|
|
|
|
|
if (mObservers->Length() == 0) {
|
2011-12-17 21:51:44 +00:00
|
|
|
DisableNotifications();
|
2011-11-02 15:14:01 +00:00
|
|
|
|
2012-03-07 11:03:25 +00:00
|
|
|
OnNotificationsDisabled();
|
|
|
|
|
2011-11-02 15:14:01 +00:00
|
|
|
delete mObservers;
|
2012-09-06 21:58:36 +00:00
|
|
|
mObservers = nullptr;
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 11:03:25 +00:00
|
|
|
void BroadcastInformation(const InfoType& aInfo) {
|
2012-05-24 17:53:40 +00:00
|
|
|
// It is possible for mObservers to be NULL here on some platforms,
|
|
|
|
// 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 11:03:25 +00: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-17 21:51:44 +00:00
|
|
|
InfoType GetCurrentInformation() {
|
|
|
|
if (mHasValidCache) {
|
|
|
|
return mInfo;
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 21:51:44 +00:00
|
|
|
GetCurrentInformationInternal(&mInfo);
|
2012-07-27 18:39:44 +00:00
|
|
|
mHasValidCache = true;
|
2011-12-17 21:51:44 +00:00
|
|
|
return mInfo;
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 21:51:44 +00:00
|
|
|
void CacheInformation(const InfoType& aInfo) {
|
|
|
|
mHasValidCache = true;
|
|
|
|
mInfo = aInfo;
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 21:51:44 +00:00
|
|
|
void BroadcastCachedInformation() {
|
2012-03-07 15:44:05 +00:00
|
|
|
this->BroadcastInformation(mInfo);
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 21:51:44 +00:00
|
|
|
protected:
|
|
|
|
virtual void GetCurrentInformationInternal(InfoType*) = 0;
|
|
|
|
|
2012-03-07 11:03:25 +00:00
|
|
|
virtual void OnNotificationsDisabled() {
|
|
|
|
mHasValidCache = false;
|
|
|
|
}
|
|
|
|
|
2011-11-02 15:14:01 +00:00
|
|
|
private:
|
2011-12-17 21:51:44 +00:00
|
|
|
InfoType mInfo;
|
|
|
|
bool mHasValidCache;
|
|
|
|
};
|
|
|
|
|
2012-03-07 11:03:25 +00:00
|
|
|
class BatteryObserversManager : public CachingObserversManager<BatteryInformation>
|
2011-12-17 21:51:44 +00: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 15:14:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static BatteryObserversManager sBatteryObservers;
|
|
|
|
|
2012-03-07 11:03:25 +00:00
|
|
|
class NetworkObserversManager : public CachingObserversManager<NetworkInformation>
|
2012-01-16 13:39:57 +00: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 11:03:25 +00:00
|
|
|
class WakeLockObserversManager : public ObserversManager<WakeLockInformation>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableNotifications() {
|
|
|
|
PROXY_IF_SANDBOXED(DisableWakeLockNotifications());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static WakeLockObserversManager sWakeLockObservers;
|
|
|
|
|
2012-05-08 21:36:07 +00:00
|
|
|
class ScreenConfigurationObserversManager : public CachingObserversManager<ScreenConfiguration>
|
2012-03-13 16:42:46 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
2012-05-08 21:36:07 +00:00
|
|
|
PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
|
2012-03-13 16:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisableNotifications() {
|
2012-05-08 21:36:07 +00:00
|
|
|
PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
|
2012-03-13 16:42:46 +00:00
|
|
|
}
|
|
|
|
|
2012-05-08 21:36:07 +00:00
|
|
|
void GetCurrentInformationInternal(ScreenConfiguration* aInfo) {
|
|
|
|
PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo));
|
2012-03-13 16:42:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-08 21:36:07 +00:00
|
|
|
static ScreenConfigurationObserversManager sScreenConfigurationObservers;
|
2012-03-13 16:42:46 +00:00
|
|
|
|
2011-11-02 15:14:01 +00:00
|
|
|
void
|
2011-12-17 21:51:44 +00:00
|
|
|
RegisterBatteryObserver(BatteryObserver* aObserver)
|
2011-11-02 15:14:01 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-12-17 21:51:44 +00:00
|
|
|
sBatteryObservers.AddObserver(aObserver);
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-17 21:51:44 +00:00
|
|
|
UnregisterBatteryObserver(BatteryObserver* aObserver)
|
2011-11-02 15:14:01 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-12-17 21:51:44 +00:00
|
|
|
sBatteryObservers.RemoveObserver(aObserver);
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-17 21:51:44 +00:00
|
|
|
GetCurrentBatteryInformation(BatteryInformation* aInfo)
|
2011-11-02 15:14:01 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-12-17 21:51:44 +00:00
|
|
|
*aInfo = sBatteryObservers.GetCurrentInformation();
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 21:51:44 +00:00
|
|
|
void
|
|
|
|
NotifyBatteryChange(const BatteryInformation& aInfo)
|
2011-11-02 15:14:01 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2011-12-17 21:51:44 +00:00
|
|
|
sBatteryObservers.CacheInformation(aInfo);
|
|
|
|
sBatteryObservers.BroadcastCachedInformation();
|
2011-11-02 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-04 17:07:00 +00:00
|
|
|
bool GetScreenEnabled()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false);
|
2011-12-04 17:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetScreenEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetScreenEnabled(enabled));
|
|
|
|
}
|
|
|
|
|
2012-04-16 22:35:33 +00: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 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed(), true);
|
2012-04-16 22:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetCpuSleepAllowed(bool allowed)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetCpuSleepAllowed(allowed));
|
|
|
|
}
|
|
|
|
|
2011-12-04 17:07:00 +00:00
|
|
|
double GetScreenBrightness()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness(), 0);
|
2011-12-04 17:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetScreenBrightness(double brightness)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(brightness, 0.0, 1.0)));
|
|
|
|
}
|
|
|
|
|
2012-10-23 07:15:43 +00:00
|
|
|
bool SetLight(LightType light, const LightConfiguration& aConfig)
|
2012-02-02 06:09:00 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(SetLight(light, aConfig), false);
|
2012-02-02 06:09:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-23 07:15:43 +00:00
|
|
|
bool GetLight(LightType light, LightConfiguration* aConfig)
|
2012-02-02 06:09:00 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig), false);
|
2012-02-02 06:09:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-23 07:15:43 +00:00
|
|
|
class SystemClockChangeObserversManager : public ObserversManager<int64_t>
|
2012-09-11 06:40:00 +00:00
|
|
|
{
|
2012-09-23 17:00:32 +00:00
|
|
|
protected:
|
|
|
|
void EnableNotifications() {
|
2012-10-23 07:15:43 +00:00
|
|
|
PROXY_IF_SANDBOXED(EnableSystemClockChangeNotifications());
|
2012-09-11 06:40:00 +00:00
|
|
|
}
|
2012-09-23 17:00:32 +00:00
|
|
|
|
|
|
|
void DisableNotifications() {
|
2012-10-23 07:15:43 +00:00
|
|
|
PROXY_IF_SANDBOXED(DisableSystemClockChangeNotifications());
|
2012-09-23 17:00:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-23 07:15:43 +00:00
|
|
|
static SystemClockChangeObserversManager sSystemClockChangeObservers;
|
2012-09-11 06:40:00 +00:00
|
|
|
|
|
|
|
void
|
2012-10-23 07:15:43 +00:00
|
|
|
RegisterSystemClockChangeObserver(SystemClockChangeObserver* aObserver)
|
2012-09-11 06:40:00 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-23 07:15:43 +00:00
|
|
|
sSystemClockChangeObservers.AddObserver(aObserver);
|
2012-09-11 06:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 07:15:43 +00:00
|
|
|
UnregisterSystemClockChangeObserver(SystemClockChangeObserver* aObserver)
|
2012-09-11 06:40:00 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-23 07:15:43 +00:00
|
|
|
sSystemClockChangeObservers.RemoveObserver(aObserver);
|
2012-09-11 06:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 07:15:43 +00:00
|
|
|
NotifySystemClockChange(const int64_t& aClockDeltaMS)
|
2012-09-11 06:40:00 +00:00
|
|
|
{
|
2012-10-23 07:15:43 +00:00
|
|
|
sSystemClockChangeObservers.BroadcastInformation(aClockDeltaMS);
|
2012-09-11 06:40:00 +00:00
|
|
|
}
|
2012-10-23 07:15:43 +00: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 10:44:00 +00:00
|
|
|
void
|
2012-09-26 03:51:29 +00:00
|
|
|
AdjustSystemClock(int64_t aDeltaMilliseconds)
|
2012-02-17 10:44:00 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(AdjustSystemClock(aDeltaMilliseconds));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetTimezone(const nsCString& aTimezoneSpec)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetTimezone(aTimezoneSpec));
|
|
|
|
}
|
|
|
|
|
2012-08-23 09:00:00 +00:00
|
|
|
nsCString
|
|
|
|
GetTimezone()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetTimezone(), nsCString(""));
|
2012-08-23 09:00:00 +00:00
|
|
|
}
|
|
|
|
|
2012-02-05 19:51:06 +00: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-06 21:58:36 +00:00
|
|
|
static SensorObserverList* gSensorObservers = nullptr;
|
2012-02-05 19:51:06 +00:00
|
|
|
|
|
|
|
static SensorObserverList &
|
|
|
|
GetSensorObservers(SensorType sensor_type) {
|
|
|
|
MOZ_ASSERT(sensor_type < NUM_SENSOR_TYPE);
|
|
|
|
|
2012-09-06 21:58:36 +00:00
|
|
|
if(!gSensorObservers) {
|
2012-02-05 19:51:06 +00:00
|
|
|
gSensorObservers = new SensorObserverList[NUM_SENSOR_TYPE];
|
2012-09-06 21:58:36 +00:00
|
|
|
}
|
2012-02-05 19:51:06 +00: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-06 21:58:36 +00:00
|
|
|
|
|
|
|
if (!gSensorObservers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SensorObserverList &observers = GetSensorObservers(aSensor);
|
|
|
|
if (!observers.RemoveObserver(aObserver) || observers.Length() > 0) {
|
2012-05-21 10:12:03 +00: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 19:51:06 +00:00
|
|
|
}
|
2012-05-21 10:12:03 +00:00
|
|
|
delete [] gSensorObservers;
|
2012-07-30 14:20:58 +00:00
|
|
|
gSensorObservers = nullptr;
|
2012-02-05 19:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifySensorChange(const SensorData &aSensorData) {
|
|
|
|
SensorObserverList &observers = GetSensorObservers(aSensorData.sensor());
|
|
|
|
|
|
|
|
AssertMainThread();
|
|
|
|
|
|
|
|
observers.Broadcast(aSensorData);
|
|
|
|
}
|
|
|
|
|
2012-01-16 13:39:57 +00: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 06:08:00 +00:00
|
|
|
void Reboot()
|
|
|
|
{
|
2012-09-26 09:12:33 +00:00
|
|
|
AssertMainProcess();
|
2012-01-31 06:08:00 +00:00
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(Reboot());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PowerOff()
|
|
|
|
{
|
2012-09-26 09:12:33 +00:00
|
|
|
AssertMainProcess();
|
2012-01-31 06:08:00 +00:00
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(PowerOff());
|
|
|
|
}
|
|
|
|
|
2012-10-02 07:26:32 +00:00
|
|
|
void StartForceQuitWatchdog(ShutdownMode aMode, int32_t aTimeoutSecs)
|
|
|
|
{
|
|
|
|
AssertMainProcess();
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(StartForceQuitWatchdog(aMode, aTimeoutSecs));
|
|
|
|
}
|
|
|
|
|
2011-08-03 18:12:08 +00:00
|
|
|
void StartMonitoringGamepadStatus()
|
|
|
|
{
|
|
|
|
PROXY_IF_SANDBOXED(StartMonitoringGamepadStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StopMonitoringGamepadStatus()
|
|
|
|
{
|
|
|
|
PROXY_IF_SANDBOXED(StopMonitoringGamepadStatus());
|
|
|
|
}
|
|
|
|
|
2012-03-07 11:03:25 +00:00
|
|
|
void
|
|
|
|
RegisterWakeLockObserver(WakeLockObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sWakeLockObservers.AddObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterWakeLockObserver(WakeLockObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sWakeLockObservers.RemoveObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-17 15:05:18 +00:00
|
|
|
ModifyWakeLock(const nsAString& aTopic,
|
2012-10-23 07:15:43 +00:00
|
|
|
WakeLockControl aLockAdjust,
|
2013-02-14 20:41:30 +00:00
|
|
|
WakeLockControl aHiddenAdjust,
|
|
|
|
uint64_t aProcessID /* = CONTENT_PROCESS_ID_UNKNOWN */)
|
2012-03-07 11:03:25 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
|
2013-02-14 20:41:30 +00: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 15:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetWakeLockInfo(const nsAString& aTopic, WakeLockInformation* aWakeLockInfo)
|
2012-03-07 11:03:25 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(GetWakeLockInfo(aTopic, aWakeLockInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyWakeLockChange(const WakeLockInformation& aInfo)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
sWakeLockObservers.BroadcastInformation(aInfo);
|
|
|
|
}
|
|
|
|
|
2012-03-13 16:42:46 +00:00
|
|
|
void
|
2012-05-08 21:36:07 +00:00
|
|
|
RegisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
|
2012-03-13 16:42:46 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-05-08 21:36:07 +00:00
|
|
|
sScreenConfigurationObservers.AddObserver(aObserver);
|
2012-03-13 16:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-08 21:36:07 +00:00
|
|
|
UnregisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
|
2012-03-13 16:42:46 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-05-08 21:36:07 +00:00
|
|
|
sScreenConfigurationObservers.RemoveObserver(aObserver);
|
2012-03-13 16:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-08 21:36:07 +00:00
|
|
|
GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
|
2012-03-13 16:42:46 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-05-08 21:36:07 +00:00
|
|
|
*aScreenConfiguration = sScreenConfigurationObservers.GetCurrentInformation();
|
2012-03-13 16:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-08 21:36:07 +00:00
|
|
|
NotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration)
|
2012-03-13 16:42:46 +00:00
|
|
|
{
|
2012-05-08 21:36:07 +00:00
|
|
|
sScreenConfigurationObservers.CacheInformation(aScreenConfiguration);
|
|
|
|
sScreenConfigurationObservers.BroadcastCachedInformation();
|
2012-03-13 16:42:46 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 19:43:16 +00:00
|
|
|
bool
|
|
|
|
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation), false);
|
2012-03-29 19:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnlockScreenOrientation()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(UnlockScreenOrientation());
|
|
|
|
}
|
|
|
|
|
2012-04-22 18:09:22 +00:00
|
|
|
void
|
2012-10-23 07:15:43 +00:00
|
|
|
EnableSwitchNotifications(SwitchDevice aDevice) {
|
2012-04-22 18:09:22 +00:00
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(EnableSwitchNotifications(aDevice));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 07:15:43 +00:00
|
|
|
DisableSwitchNotifications(SwitchDevice aDevice) {
|
2012-04-22 18:09:22 +00:00
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(DisableSwitchNotifications(aDevice));
|
|
|
|
}
|
|
|
|
|
2012-10-23 07:15:43 +00:00
|
|
|
SwitchState GetCurrentSwitchState(SwitchDevice aDevice)
|
2012-04-22 18:09:22 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetCurrentSwitchState(aDevice), SWITCH_STATE_UNKNOWN);
|
2012-04-22 18:09:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef mozilla::ObserverList<SwitchEvent> SwitchObserverList;
|
|
|
|
|
|
|
|
static SwitchObserverList *sSwitchObserverLists = NULL;
|
|
|
|
|
|
|
|
static SwitchObserverList&
|
2012-10-23 07:15:43 +00:00
|
|
|
GetSwitchObserverList(SwitchDevice aDevice) {
|
2012-04-22 18:09:22 +00:00
|
|
|
MOZ_ASSERT(0 <= aDevice && aDevice < NUM_SWITCH_DEVICE);
|
|
|
|
if (sSwitchObserverLists == NULL) {
|
|
|
|
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;
|
|
|
|
sSwitchObserverLists = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 07:15:43 +00:00
|
|
|
RegisterSwitchObserver(SwitchDevice aDevice, SwitchObserver *aObserver)
|
2012-04-22 18:09:22 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
SwitchObserverList& observer = GetSwitchObserverList(aDevice);
|
|
|
|
observer.AddObserver(aObserver);
|
|
|
|
if (observer.Length() == 1) {
|
|
|
|
EnableSwitchNotifications(aDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 07:15:43 +00:00
|
|
|
UnregisterSwitchObserver(SwitchDevice aDevice, SwitchObserver *aObserver)
|
2012-04-22 18:09:22 +00:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2012-09-06 21:58:36 +00:00
|
|
|
|
|
|
|
if (!sSwitchObserverLists) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-22 18:09:22 +00:00
|
|
|
SwitchObserverList& observer = GetSwitchObserverList(aDevice);
|
2012-09-06 21:58:36 +00:00
|
|
|
if (!observer.RemoveObserver(aObserver) || observer.Length() > 0) {
|
|
|
|
return;
|
2012-04-22 18:09:22 +00:00
|
|
|
}
|
2012-09-06 21:58:36 +00:00
|
|
|
|
|
|
|
DisableSwitchNotifications(aDevice);
|
|
|
|
ReleaseObserversIfNeeded();
|
2012-04-22 18:09:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 07:15:43 +00:00
|
|
|
NotifySwitchChange(const SwitchEvent& aEvent)
|
2012-04-22 18:09:22 +00: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 10:42:10 +00:00
|
|
|
static AlarmObserver* sAlarmObserver;
|
|
|
|
|
|
|
|
bool
|
|
|
|
RegisterTheOneAlarmObserver(AlarmObserver* aObserver)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!InSandbox());
|
|
|
|
MOZ_ASSERT(!sAlarmObserver);
|
|
|
|
|
|
|
|
sAlarmObserver = aObserver;
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(EnableAlarm(), false);
|
2012-07-06 10:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterTheOneAlarmObserver()
|
|
|
|
{
|
|
|
|
if (sAlarmObserver) {
|
2012-09-06 21:58:36 +00:00
|
|
|
sAlarmObserver = nullptr;
|
2012-07-06 10:42:10 +00:00
|
|
|
PROXY_IF_SANDBOXED(DisableAlarm());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyAlarmFired()
|
|
|
|
{
|
|
|
|
if (sAlarmObserver) {
|
|
|
|
sAlarmObserver->Notify(void_t());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
|
2012-07-06 10:42:10 +00:00
|
|
|
{
|
|
|
|
// It's pointless to program an alarm nothing is going to observe ...
|
|
|
|
MOZ_ASSERT(sAlarmObserver);
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds, aNanoseconds), false);
|
2012-07-06 10:42:10 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 05:09:39 +00:00
|
|
|
void
|
2013-05-09 20:27:06 +00:00
|
|
|
SetProcessPriority(int aPid,
|
|
|
|
ProcessPriority aPriority,
|
|
|
|
ProcessCPUPriority aCPUPriority)
|
2012-08-05 05:09:39 +00:00
|
|
|
{
|
2013-05-09 20:27:06 +00:00
|
|
|
// n.b. The sandboxed implementation crashes; SetProcessPriority works only
|
|
|
|
// from the main process.
|
|
|
|
PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority, aCPUPriority));
|
2012-08-05 05:09:39 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 14:32:23 +00:00
|
|
|
// From HalTypes.h.
|
|
|
|
const char*
|
|
|
|
ProcessPriorityToString(ProcessPriority aPriority)
|
|
|
|
{
|
|
|
|
switch (aPriority) {
|
|
|
|
case PROCESS_PRIORITY_MASTER:
|
|
|
|
return "MASTER";
|
2013-02-14 20:41:30 +00:00
|
|
|
case PROCESS_PRIORITY_FOREGROUND_HIGH:
|
|
|
|
return "FOREGROUND_HIGH";
|
2013-02-08 14:32:23 +00:00
|
|
|
case PROCESS_PRIORITY_FOREGROUND:
|
|
|
|
return "FOREGROUND";
|
|
|
|
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 04:24:28 +00:00
|
|
|
case PROCESS_PRIORITY_UNKNOWN:
|
|
|
|
return "UNKNOWN";
|
2013-02-08 14:32:23 +00:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 20:27:06 +00: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";
|
|
|
|
}
|
|
|
|
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 15:17:13 +00: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 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetFMRadioFrequency(), 0);
|
2012-09-19 15:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsFMRadioOn() {
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(IsFMRadioOn(), false);
|
2012-09-19 15:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GetFMRadioSignalStrength() {
|
|
|
|
AssertMainThread();
|
2012-10-07 01:53:22 +00:00
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetFMRadioSignalStrength(), 0);
|
2012-09-19 15:17:13 +00: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 09:28:34 +00:00
|
|
|
void FactoryReset()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(FactoryReset());
|
|
|
|
}
|
|
|
|
|
2013-05-09 22:57:31 +00:00
|
|
|
void
|
|
|
|
StartDiskSpaceWatcher()
|
|
|
|
{
|
|
|
|
AssertMainProcess();
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(StartDiskSpaceWatcher());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StopDiskSpaceWatcher()
|
|
|
|
{
|
|
|
|
AssertMainProcess();
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(StopDiskSpaceWatcher());
|
|
|
|
}
|
|
|
|
|
2011-10-05 22:15:45 +00:00
|
|
|
} // namespace hal
|
|
|
|
} // namespace mozilla
|