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"
|
2016-02-15 09:33:00 +03:00
|
|
|
|
2011-12-18 01:04:51 +04:00
|
|
|
#include "HalImpl.h"
|
2014-09-24 17:23:18 +04:00
|
|
|
#include "HalLog.h"
|
2011-12-18 01:04:51 +04:00
|
|
|
#include "HalSandbox.h"
|
2016-02-15 09:33:00 +03:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsITabChild.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2011-10-06 02:15:45 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
2013-05-18 00:17:53 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2016-02-15 09:33:00 +03:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
|
|
#include "mozilla/Observer.h"
|
2011-09-30 11:00:48 +04:00
|
|
|
#include "mozilla/Services.h"
|
2012-07-26 23:33:45 +04:00
|
|
|
#include "mozilla/StaticPtr.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"
|
2016-02-15 09:33:00 +03:00
|
|
|
#include "mozilla/dom/ScreenOrientation.h"
|
|
|
|
#include "WindowIdentifier.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 {
|
|
|
|
|
2016-01-28 21:35:00 +03:00
|
|
|
mozilla::LogModule *
|
2012-10-30 03:32:10 +04:00
|
|
|
GetHalLog()
|
|
|
|
{
|
2016-01-28 21:35:00 +03:00
|
|
|
static mozilla::LazyLogModule sHalLog("hal");
|
2012-10-30 03:32:10 +04:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2015-11-17 12:18:38 +03:00
|
|
|
#if !defined(MOZ_WIDGET_GONK)
|
|
|
|
|
2011-09-30 11:00:48 +04:00
|
|
|
bool
|
2016-01-30 20:05:36 +03:00
|
|
|
WindowIsActive(nsPIDOMWindowInner* aWindow)
|
2011-09-30 11:00:48 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsIDocument* document = aWindow->GetDoc();
|
2013-05-05 11:03:15 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-17 12:18:38 +03:00
|
|
|
#endif // !defined(MOZ_WIDGET_GONK)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2011-09-30 11:00:48 +04:00
|
|
|
|
2011-10-06 02:15:45 +04:00
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
Vibrate(const nsTArray<uint32_t>& pattern, nsPIDOMWindowInner* 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
|
|
|
|
2015-11-17 12:18:38 +03:00
|
|
|
#if !defined(MOZ_WIDGET_GONK)
|
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())) {
|
2014-09-24 17:23:18 +04:00
|
|
|
HAL_LOG("Vibrate: Window is inactive, dropping vibrate.");
|
2011-09-30 11:00:48 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-11-17 12:18:38 +03:00
|
|
|
#endif // !defined(MOZ_WIDGET_GONK)
|
2011-09-30 11:00:48 +04:00
|
|
|
|
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
|
|
|
|
2016-01-04 18:08:21 +03:00
|
|
|
// Don't forward our ID if we are not in the sandbox, because hal_impl
|
2012-11-08 23:35:03 +04:00
|
|
|
// 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
|
2016-01-30 20:05:36 +03:00
|
|
|
CancelVibrate(nsPIDOMWindowInner* window)
|
2011-12-18 01:04:26 +04:00
|
|
|
{
|
|
|
|
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())) {
|
2016-01-04 18:08:21 +03:00
|
|
|
// Don't forward our ID if we are not in the sandbox, because hal_impl
|
2012-11-08 23:35:03 +04:00
|
|
|
// 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) {
|
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;
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void OnNotificationsDisabled() override {
|
2012-03-07 15:03:25 +04:00
|
|
|
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:
|
2016-11-23 14:21:06 +03:00
|
|
|
void EnableNotifications() override {
|
2011-12-18 01:51:44 +04:00
|
|
|
PROXY_IF_SANDBOXED(EnableBatteryNotifications());
|
|
|
|
}
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void DisableNotifications() override {
|
2011-12-18 01:51:44 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableBatteryNotifications());
|
|
|
|
}
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void GetCurrentInformationInternal(BatteryInformation* aInfo) override {
|
2011-12-18 01:51:44 +04:00
|
|
|
PROXY_IF_SANDBOXED(GetCurrentBatteryInformation(aInfo));
|
|
|
|
}
|
2011-11-02 19:14:01 +04:00
|
|
|
};
|
|
|
|
|
2016-02-19 18:56:46 +03:00
|
|
|
static BatteryObserversManager&
|
|
|
|
BatteryObservers()
|
|
|
|
{
|
|
|
|
static BatteryObserversManager sBatteryObservers;
|
|
|
|
AssertMainThread();
|
|
|
|
return sBatteryObservers;
|
|
|
|
}
|
2011-11-02 19:14:01 +04:00
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
class NetworkObserversManager : public CachingObserversManager<NetworkInformation>
|
2012-01-16 17:39:57 +04:00
|
|
|
{
|
|
|
|
protected:
|
2016-11-23 14:21:06 +03:00
|
|
|
void EnableNotifications() override {
|
2012-01-16 17:39:57 +04:00
|
|
|
PROXY_IF_SANDBOXED(EnableNetworkNotifications());
|
|
|
|
}
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void DisableNotifications() override {
|
2012-01-16 17:39:57 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableNetworkNotifications());
|
|
|
|
}
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void GetCurrentInformationInternal(NetworkInformation* aInfo) override {
|
2012-01-16 17:39:57 +04:00
|
|
|
PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-19 19:28:00 +03:00
|
|
|
static NetworkObserversManager&
|
|
|
|
NetworkObservers()
|
|
|
|
{
|
|
|
|
static NetworkObserversManager sNetworkObservers;
|
|
|
|
AssertMainThread();
|
|
|
|
return sNetworkObservers;
|
|
|
|
}
|
2012-01-16 17:39:57 +04:00
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
class WakeLockObserversManager : public ObserversManager<WakeLockInformation>
|
|
|
|
{
|
|
|
|
protected:
|
2016-11-23 14:21:06 +03:00
|
|
|
void EnableNotifications() override {
|
2012-03-07 15:03:25 +04:00
|
|
|
PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
|
|
|
|
}
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void DisableNotifications() override {
|
2012-03-07 15:03:25 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableWakeLockNotifications());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-19 19:37:34 +03:00
|
|
|
static WakeLockObserversManager&
|
|
|
|
WakeLockObservers()
|
|
|
|
{
|
|
|
|
static WakeLockObserversManager sWakeLockObservers;
|
|
|
|
AssertMainThread();
|
|
|
|
return sWakeLockObservers;
|
|
|
|
}
|
2012-03-07 15:03:25 +04:00
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
class ScreenConfigurationObserversManager : public CachingObserversManager<ScreenConfiguration>
|
2012-03-13 20:42:46 +04:00
|
|
|
{
|
|
|
|
protected:
|
2016-11-23 14:21:06 +03:00
|
|
|
void EnableNotifications() override {
|
2012-05-09 01:36:07 +04:00
|
|
|
PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void DisableNotifications() override {
|
2012-05-09 01:36:07 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void GetCurrentInformationInternal(ScreenConfiguration* aInfo) override {
|
2012-05-09 01:36:07 +04:00
|
|
|
PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo));
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-19 19:31:43 +03:00
|
|
|
static ScreenConfigurationObserversManager&
|
|
|
|
ScreenConfigurationObservers()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
static ScreenConfigurationObserversManager sScreenConfigurationObservers;
|
|
|
|
return 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();
|
2016-02-19 18:56:46 +03:00
|
|
|
BatteryObservers().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();
|
2016-02-19 18:56:46 +03:00
|
|
|
BatteryObservers().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();
|
2016-02-19 18:56:46 +03:00
|
|
|
*aInfo = BatteryObservers().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();
|
2016-02-19 18:56:46 +03:00
|
|
|
BatteryObservers().CacheInformation(aInfo);
|
|
|
|
BatteryObservers().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
|
|
|
}
|
|
|
|
|
2014-05-30 07:11:23 +04:00
|
|
|
void SetScreenEnabled(bool aEnabled)
|
2011-12-04 21:07:00 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2014-05-30 07:11:23 +04:00
|
|
|
PROXY_IF_SANDBOXED(SetScreenEnabled(aEnabled));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetKeyLightEnabled()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
RETURN_PROXY_IF_SANDBOXED(GetKeyLightEnabled(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetKeyLightEnabled(bool aEnabled)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(SetKeyLightEnabled(aEnabled));
|
2011-12-04 21:07:00 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-30 07:11:23 +04:00
|
|
|
void SetCpuSleepAllowed(bool aAllowed)
|
2012-04-17 02:35:33 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2014-05-30 07:11:23 +04:00
|
|
|
PROXY_IF_SANDBOXED(SetCpuSleepAllowed(aAllowed));
|
2012-04-17 02:35:33 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-30 07:11:23 +04:00
|
|
|
void SetScreenBrightness(double aBrightness)
|
2011-12-04 21:07:00 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2014-05-30 07:11:23 +04:00
|
|
|
PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(aBrightness, 0.0, 1.0)));
|
2011-12-04 21:07: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:
|
2016-11-23 14:21:06 +03:00
|
|
|
void EnableNotifications() override {
|
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
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void DisableNotifications() override {
|
2012-10-23 11:15:43 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableSystemClockChangeNotifications());
|
2012-09-23 21:00:32 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-19 19:55:05 +03:00
|
|
|
static SystemClockChangeObserversManager&
|
|
|
|
SystemClockChangeObservers()
|
|
|
|
{
|
|
|
|
static SystemClockChangeObserversManager sSystemClockChangeObservers;
|
|
|
|
AssertMainThread();
|
|
|
|
return 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();
|
2016-02-19 19:55:05 +03:00
|
|
|
SystemClockChangeObservers().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();
|
2016-02-19 19:55:05 +03:00
|
|
|
SystemClockChangeObservers().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
|
|
|
{
|
2016-02-19 19:55:05 +03:00
|
|
|
SystemClockChangeObservers().BroadcastInformation(aClockDeltaMS);
|
2012-09-11 10:40:00 +04:00
|
|
|
}
|
2012-10-23 11:15:43 +04:00
|
|
|
|
|
|
|
class SystemTimezoneChangeObserversManager : public ObserversManager<SystemTimezoneChangeInformation>
|
|
|
|
{
|
|
|
|
protected:
|
2016-11-23 14:21:06 +03:00
|
|
|
void EnableNotifications() override {
|
2012-10-23 11:15:43 +04:00
|
|
|
PROXY_IF_SANDBOXED(EnableSystemTimezoneChangeNotifications());
|
|
|
|
}
|
|
|
|
|
2016-11-23 14:21:06 +03:00
|
|
|
void DisableNotifications() override {
|
2012-10-23 11:15:43 +04:00
|
|
|
PROXY_IF_SANDBOXED(DisableSystemTimezoneChangeNotifications());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-19 20:00:10 +03:00
|
|
|
static SystemTimezoneChangeObserversManager&
|
|
|
|
SystemTimezoneChangeObservers()
|
|
|
|
{
|
|
|
|
static SystemTimezoneChangeObserversManager sSystemTimezoneChangeObservers;
|
|
|
|
return sSystemTimezoneChangeObservers;
|
|
|
|
}
|
2012-10-23 11:15:43 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
RegisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2016-02-19 20:00:10 +03:00
|
|
|
SystemTimezoneChangeObservers().AddObserver(aObserver);
|
2012-10-23 11:15:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2016-02-19 20:00:10 +03:00
|
|
|
SystemTimezoneChangeObservers().RemoveObserver(aObserver);
|
2012-10-23 11:15:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifySystemTimezoneChange(const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
|
|
|
|
{
|
2015-06-15 11:25:57 +03:00
|
|
|
nsJSUtils::ResetTimeZone();
|
2016-02-19 20:00:10 +03:00
|
|
|
SystemTimezoneChangeObservers().BroadcastInformation(aSystemTimezoneChangeInfo);
|
2012-10-23 11:15:43 +04:00
|
|
|
}
|
|
|
|
|
2016-01-04 18:08:21 +03: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));
|
|
|
|
}
|
|
|
|
|
2016-01-04 18:08:21 +03:00
|
|
|
void
|
2012-02-17 14:44:00 +04:00
|
|
|
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);
|
2016-01-04 18:08:21 +03:00
|
|
|
|
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();
|
2016-01-04 18:08:21 +03:00
|
|
|
|
2012-02-05 23:51:06 +04:00
|
|
|
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();
|
2016-01-04 18:08:21 +03:00
|
|
|
|
2012-02-05 23:51:06 +04:00
|
|
|
observers.Broadcast(aSensorData);
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:39:57 +04:00
|
|
|
void
|
|
|
|
RegisterNetworkObserver(NetworkObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2016-02-19 19:28:00 +03:00
|
|
|
NetworkObservers().AddObserver(aObserver);
|
2012-01-16 17:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterNetworkObserver(NetworkObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2016-02-19 19:28:00 +03:00
|
|
|
NetworkObservers().RemoveObserver(aObserver);
|
2012-01-16 17:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetCurrentNetworkInformation(NetworkInformation* aInfo)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2016-02-19 19:28:00 +03:00
|
|
|
*aInfo = NetworkObservers().GetCurrentInformation();
|
2012-01-16 17:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyNetworkChange(const NetworkInformation& aInfo)
|
|
|
|
{
|
2016-02-19 19:28:00 +03:00
|
|
|
NetworkObservers().CacheInformation(aInfo);
|
|
|
|
NetworkObservers().BroadcastCachedInformation();
|
2012-01-16 17:39:57 +04:00
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
void
|
|
|
|
RegisterWakeLockObserver(WakeLockObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2016-02-19 19:37:34 +03:00
|
|
|
WakeLockObservers().AddObserver(aObserver);
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterWakeLockObserver(WakeLockObserver* aObserver)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
2016-02-19 19:37:34 +03:00
|
|
|
WakeLockObservers().RemoveObserver(aObserver);
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2016-02-19 19:37:34 +03:00
|
|
|
WakeLockObservers().BroadcastInformation(aInfo);
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
|
|
|
|
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();
|
2016-02-19 19:31:43 +03:00
|
|
|
ScreenConfigurationObservers().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();
|
2016-02-19 19:31:43 +03:00
|
|
|
ScreenConfigurationObservers().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();
|
2016-02-19 19:31:43 +03:00
|
|
|
*aScreenConfiguration = ScreenConfigurationObservers().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
|
|
|
{
|
2016-02-19 19:31:43 +03:00
|
|
|
ScreenConfigurationObservers().CacheInformation(aScreenConfiguration);
|
|
|
|
ScreenConfigurationObservers().BroadcastCachedInformation();
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
2012-03-29 23:43:16 +04:00
|
|
|
bool
|
2015-08-19 00:55:09 +03:00
|
|
|
LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation)
|
2012-03-29 23:43:16 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-20 13:35:24 +04:00
|
|
|
void NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState)
|
|
|
|
{
|
2014-06-03 03:25:00 +04:00
|
|
|
AssertMainThread();
|
2014-01-20 13:35:24 +04:00
|
|
|
PROXY_IF_SANDBOXED(NotifySwitchStateFromInputDevice(aDevice, aState));
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-01-04 18:08:21 +03: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-08-05 09:09:39 +04:00
|
|
|
void
|
2015-02-25 11:37:38 +03:00
|
|
|
SetProcessPriority(int aPid, ProcessPriority aPriority, uint32_t aLRU)
|
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.
|
2015-02-25 11:37:38 +03:00
|
|
|
PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority, aLRU));
|
2012-08-05 09:09:39 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 19:37:00 +04:00
|
|
|
void
|
|
|
|
SetCurrentThreadPriority(hal::ThreadPriority aThreadPriority)
|
|
|
|
{
|
|
|
|
PROXY_IF_SANDBOXED(SetCurrentThreadPriority(aThreadPriority));
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:53:47 +03:00
|
|
|
void
|
|
|
|
SetThreadPriority(PlatformThreadId aThreadId,
|
|
|
|
hal::ThreadPriority aThreadPriority)
|
|
|
|
{
|
|
|
|
PROXY_IF_SANDBOXED(SetThreadPriority(aThreadId, aThreadPriority));
|
|
|
|
}
|
|
|
|
|
2013-02-08 18:32:23 +04:00
|
|
|
// From HalTypes.h.
|
|
|
|
const char*
|
|
|
|
ProcessPriorityToString(ProcessPriority aPriority)
|
|
|
|
{
|
|
|
|
switch (aPriority) {
|
|
|
|
case PROCESS_PRIORITY_MASTER:
|
|
|
|
return "MASTER";
|
2017-02-01 15:34:24 +03:00
|
|
|
case PROCESS_PRIORITY_PREALLOC:
|
|
|
|
return "PREALLOC";
|
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:
|
|
|
|
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 "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:37:00 +04:00
|
|
|
const char *
|
|
|
|
ThreadPriorityToString(ThreadPriority aPriority)
|
|
|
|
{
|
|
|
|
switch (aPriority) {
|
|
|
|
case THREAD_PRIORITY_COMPOSITOR:
|
|
|
|
return "COMPOSITOR";
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-18 05:30:47 +04:00
|
|
|
void FactoryReset(mozilla::dom::FactoryResetReason& aReason)
|
2012-10-04 13:28:34 +04:00
|
|
|
{
|
|
|
|
AssertMainThread();
|
2014-07-18 05:30:47 +04:00
|
|
|
PROXY_IF_SANDBOXED(FactoryReset(aReason));
|
2012-10-04 13:28:34 +04:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-07-01 21:52:00 +04:00
|
|
|
bool IsHeadphoneEventFromInputDev()
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
RETURN_PROXY_IF_SANDBOXED(IsHeadphoneEventFromInputDev(), false);
|
|
|
|
}
|
|
|
|
|
2016-01-04 18:08:21 +03:00
|
|
|
nsresult StartSystemService(const char* aSvcName, const char* aArgs)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
RETURN_PROXY_IF_SANDBOXED(StartSystemService(aSvcName, aArgs), NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StopSystemService(const char* aSvcName)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
PROXY_IF_SANDBOXED(StopSystemService(aSvcName));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemServiceIsRunning(const char* aSvcName)
|
|
|
|
{
|
|
|
|
AssertMainThread();
|
|
|
|
RETURN_PROXY_IF_SANDBOXED(SystemServiceIsRunning(aSvcName), false);
|
|
|
|
}
|
|
|
|
|
2011-10-06 02:15:45 +04:00
|
|
|
} // namespace hal
|
|
|
|
} // namespace mozilla
|