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"
|
2018-08-31 23:29:30 +03:00
|
|
|
#include "HalWakeLockInternal.h"
|
2016-02-15 09:33:00 +03:00
|
|
|
#include "nsIDOMWindow.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2016-02-15 09:33:00 +03:00
|
|
|
#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"
|
2012-11-17 19:05:18 +04:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2016-02-15 09:33:00 +03:00
|
|
|
#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 {
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
static bool sInitialized = false;
|
|
|
|
|
2016-01-28 21:35:00 +03:00
|
|
|
mozilla::LogModule* GetHalLog() {
|
|
|
|
static mozilla::LazyLogModule sHalLog("hal");
|
2012-10-30 03:32:10 +04:00
|
|
|
return sHalLog;
|
|
|
|
}
|
2011-09-30 11:00:48 +04:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2011-10-06 02:15:45 +04:00
|
|
|
void AssertMainThread() { MOZ_ASSERT(NS_IsMainThread()); }
|
|
|
|
|
|
|
|
bool InSandbox() { return GeckoProcessType_Content == XRE_GetProcessType(); }
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
bool WindowIsActive(nsPIDOMWindowInner* aWindow) {
|
2019-01-02 16:05:23 +03:00
|
|
|
dom::Document* document = aWindow->GetDoc();
|
2013-05-05 11:03:15 +04:00
|
|
|
NS_ENSURE_TRUE(document, false);
|
|
|
|
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
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
static void RecordLastIDToVibrate(const WindowIdentifier& aId) {
|
|
|
|
if (!InSandbox()) {
|
|
|
|
*gLastIDToVibrate = aId.AsArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool MayCancelVibration(const WindowIdentifier& aId) {
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
return InSandbox() || (*gLastIDToVibrate == aId.AsArray());
|
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
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void Vibrate(const nsTArray<uint32_t>& pattern, nsPIDOMWindowInner* window) {
|
2011-12-18 01:04:26 +04:00
|
|
|
Vibrate(pattern, WindowIdentifier(window));
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
|
|
|
|
2012-05-25 11:18:30 +04:00
|
|
|
void 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())) {
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
RecordLastIDToVibrate(id);
|
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
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void 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();
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
if (MayCancelVibration(id)) {
|
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) {
|
2018-08-31 23:29:30 +03:00
|
|
|
mObservers.AddObserver(aObserver);
|
2018-07-02 13:14:18 +03:00
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
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) {
|
2018-08-31 23:29:30 +03:00
|
|
|
bool removed = mObservers.RemoveObserver(aObserver);
|
2012-09-07 01:58:36 +04:00
|
|
|
if (!removed) {
|
2012-03-14 22:18:26 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-11-02 19:14:01 +04:00
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
if (mObservers.Length() == 0) {
|
2011-12-18 01:51:44 +04:00
|
|
|
DisableNotifications();
|
2012-03-07 15:03:25 +04:00
|
|
|
OnNotificationsDisabled();
|
2011-11-02 19:14:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
void BroadcastInformation(const InfoType& aInfo) {
|
2018-08-31 23:29:30 +03:00
|
|
|
mObservers.Broadcast(aInfo);
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-08-31 23:29:30 +03:00
|
|
|
~ObserversManager() { MOZ_ASSERT(mObservers.Length() == 0); }
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
virtual void EnableNotifications() = 0;
|
|
|
|
virtual void DisableNotifications() = 0;
|
|
|
|
virtual void OnNotificationsDisabled() {}
|
|
|
|
|
|
|
|
private:
|
2018-08-31 23:29:30 +03:00
|
|
|
mozilla::ObserverList<InfoType> mObservers;
|
2012-03-07 15:03:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
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() { 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 { mHasValidCache = false; }
|
2012-03-07 15:03:25 +04:00
|
|
|
|
2011-11-02 19:14:01 +04:00
|
|
|
private:
|
2011-12-18 01:51:44 +04:00
|
|
|
InfoType mInfo;
|
|
|
|
bool mHasValidCache;
|
|
|
|
};
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
class BatteryObserversManager final
|
|
|
|
: 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
|
|
|
};
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
class NetworkObserversManager final
|
|
|
|
: 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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
class WakeLockObserversManager final
|
|
|
|
: public ObserversManager<WakeLockInformation> {
|
2012-03-07 15:03:25 +04:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
class ScreenConfigurationObserversManager final
|
|
|
|
: 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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
typedef mozilla::ObserverList<SensorData> SensorObserverList;
|
|
|
|
StaticAutoPtr<SensorObserverList> sSensorObservers[NUM_SENSOR_TYPE];
|
|
|
|
|
|
|
|
static SensorObserverList* GetSensorObservers(SensorType sensor_type) {
|
2016-02-19 19:31:43 +03:00
|
|
|
AssertMainThread();
|
2018-08-31 23:29:30 +03:00
|
|
|
MOZ_ASSERT(sensor_type < NUM_SENSOR_TYPE);
|
2012-03-13 20:42:46 +04:00
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
if (!sSensorObservers[sensor_type]) {
|
|
|
|
sSensorObservers[sensor_type] = new SensorObserverList();
|
|
|
|
}
|
|
|
|
|
|
|
|
return sSensorObservers[sensor_type];
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MOZ_IMPL_HAL_OBSERVER(name_) \
|
|
|
|
StaticAutoPtr<name_##ObserversManager> s##name_##Observers; \
|
|
|
|
\
|
|
|
|
static name_##ObserversManager* name_##Observers() { \
|
|
|
|
AssertMainThread(); \
|
|
|
|
\
|
|
|
|
if (!s##name_##Observers) { \
|
|
|
|
MOZ_ASSERT(sInitialized); \
|
|
|
|
s##name_##Observers = new name_##ObserversManager(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
return s##name_##Observers; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void Register##name_##Observer(name_##Observer* aObserver) { \
|
|
|
|
AssertMainThread(); \
|
|
|
|
name_##Observers()->AddObserver(aObserver); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void Unregister##name_##Observer(name_##Observer* aObserver) { \
|
|
|
|
AssertMainThread(); \
|
|
|
|
name_##Observers()->RemoveObserver(aObserver); \
|
2018-08-13 04:57:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_IMPL_HAL_OBSERVER(Battery)
|
2011-11-02 19:14:01 +04:00
|
|
|
|
2011-12-18 01:51:44 +04:00
|
|
|
void GetCurrentBatteryInformation(BatteryInformation* aInfo) {
|
2018-08-31 23:29:30 +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) {
|
2018-08-31 23:29:30 +03:00
|
|
|
BatteryObservers()->CacheInformation(aInfo);
|
|
|
|
BatteryObservers()->BroadcastCachedInformation();
|
2011-11-02 19:14:01 +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));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterSensorObserver(SensorType aSensor, ISensorObserver* aObserver) {
|
2018-08-31 23:29:30 +03:00
|
|
|
SensorObserverList* observers = GetSensorObservers(aSensor);
|
2016-01-04 18:08:21 +03:00
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
observers->AddObserver(aObserver);
|
|
|
|
if (observers->Length() == 1) {
|
2012-02-05 23:51:06 +04:00
|
|
|
EnableSensorNotifications(aSensor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterSensorObserver(SensorType aSensor, ISensorObserver* aObserver) {
|
2018-08-31 23:29:30 +03:00
|
|
|
SensorObserverList* observers = GetSensorObservers(aSensor);
|
|
|
|
if (!observers->RemoveObserver(aObserver) || observers->Length() > 0) {
|
2012-05-21 14:12:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
DisableSensorNotifications(aSensor);
|
2012-02-05 23:51:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifySensorChange(const SensorData& aSensorData) {
|
2018-08-31 23:29:30 +03:00
|
|
|
SensorObserverList* observers = GetSensorObservers(aSensorData.sensor());
|
2012-02-05 23:51:06 +04:00
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
observers->Broadcast(aSensorData);
|
2012-02-05 23:51:06 +04:00
|
|
|
}
|
|
|
|
|
2018-08-13 04:57:50 +03:00
|
|
|
MOZ_IMPL_HAL_OBSERVER(Network)
|
2012-01-16 17:39:57 +04:00
|
|
|
|
|
|
|
void GetCurrentNetworkInformation(NetworkInformation* aInfo) {
|
2018-08-31 23:29:30 +03:00
|
|
|
*aInfo = NetworkObservers()->GetCurrentInformation();
|
2012-01-16 17:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyNetworkChange(const NetworkInformation& aInfo) {
|
2018-08-31 23:29:30 +03:00
|
|
|
NetworkObservers()->CacheInformation(aInfo);
|
|
|
|
NetworkObservers()->BroadcastCachedInformation();
|
2012-01-16 17:39:57 +04:00
|
|
|
}
|
|
|
|
|
2018-08-13 04:57:50 +03:00
|
|
|
MOZ_IMPL_HAL_OBSERVER(WakeLock)
|
2012-03-07 15:03:25 +04:00
|
|
|
|
2012-11-17 19:05:18 +04:00
|
|
|
void ModifyWakeLock(const nsAString& aTopic, 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();
|
2018-08-31 23:29:30 +03:00
|
|
|
WakeLockObservers()->BroadcastInformation(aInfo);
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
|
|
|
|
2018-08-13 04:57:50 +03:00
|
|
|
MOZ_IMPL_HAL_OBSERVER(ScreenConfiguration)
|
2012-03-13 20:42:46 +04:00
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
void GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) {
|
2018-08-31 23:29:30 +03:00
|
|
|
*aScreenConfiguration =
|
|
|
|
ScreenConfigurationObservers()->GetCurrentInformation();
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
void NotifyScreenConfigurationChange(
|
|
|
|
const ScreenConfiguration& aScreenConfiguration) {
|
2018-08-31 23:29:30 +03:00
|
|
|
ScreenConfigurationObservers()->CacheInformation(aScreenConfiguration);
|
|
|
|
ScreenConfigurationObservers()->BroadcastCachedInformation();
|
2012-03-13 20:42:46 +04:00
|
|
|
}
|
|
|
|
|
2018-08-29 23:54:56 +03:00
|
|
|
bool LockScreenOrientation(const ScreenOrientation& 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());
|
|
|
|
}
|
|
|
|
|
2017-06-07 10:59:00 +03:00
|
|
|
bool SetProcessPrioritySupported() {
|
|
|
|
RETURN_PROXY_IF_SANDBOXED(SetProcessPrioritySupported(), false);
|
|
|
|
}
|
|
|
|
|
2017-05-26 18:50:17 +03:00
|
|
|
void SetProcessPriority(int aPid, ProcessPriority aPriority) {
|
2013-05-10 00:27:06 +04:00
|
|
|
// n.b. The sandboxed implementation crashes; SetProcessPriority works only
|
|
|
|
// from the main process.
|
2017-05-26 18:50:17 +03:00
|
|
|
PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority));
|
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";
|
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 "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 23:29:30 +03:00
|
|
|
void Init() {
|
|
|
|
MOZ_ASSERT(!sInitialized);
|
|
|
|
|
|
|
|
if (!InSandbox()) {
|
|
|
|
gLastIDToVibrate = new WindowIdentifier::IDArrayType();
|
|
|
|
}
|
|
|
|
|
|
|
|
WakeLockInit();
|
|
|
|
|
|
|
|
sInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown() {
|
|
|
|
MOZ_ASSERT(sInitialized);
|
|
|
|
|
|
|
|
gLastIDToVibrate = nullptr;
|
|
|
|
|
|
|
|
sBatteryObservers = nullptr;
|
|
|
|
sNetworkObservers = nullptr;
|
|
|
|
sWakeLockObservers = nullptr;
|
|
|
|
sScreenConfigurationObservers = nullptr;
|
|
|
|
|
|
|
|
for (auto& sensorObserver : sSensorObservers) {
|
|
|
|
sensorObserver = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
sInitialized = false;
|
|
|
|
}
|
|
|
|
|
2011-10-06 02:15:45 +04:00
|
|
|
} // namespace hal
|
|
|
|
} // namespace mozilla
|