1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et ft=cpp : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "HalSandbox.h"
10 #include "nsThreadUtils.h"
11 #include "nsXULAppAPI.h"
12 #include "mozilla/Observer.h"
13 #include "nsIDocument.h"
14 #include "nsIDOMDocument.h"
15 #include "nsPIDOMWindow.h"
16 #include "nsIDOMWindow.h"
17 #include "mozilla/Services.h"
18 #include "nsIWebNavigation.h"
19 #include "nsITabChild.h"
20 #include "nsIDocShell.h"
21 #include "mozilla/StaticPtr.h"
22 #include "mozilla/ClearOnShutdown.h"
23 #include "WindowIdentifier.h"
24 #include "mozilla/dom/ScreenOrientation.h"
25 #include "mozilla/dom/ContentChild.h"
26 #include "mozilla/dom/ContentParent.h"
30 #define getpid _getpid
33 using namespace mozilla::services
;
34 using namespace mozilla::dom
;
36 #define PROXY_IF_SANDBOXED(_call) \
39 if (!hal_sandbox::HalChildDestroyed()) { \
47 #define RETURN_PROXY_IF_SANDBOXED(_call, defValue)\
50 if (hal_sandbox::HalChildDestroyed()) { \
53 return hal_sandbox::_call; \
55 return hal_impl::_call; \
65 static PRLogModuleInfo
*sHalLog
;
67 sHalLog
= PR_NewLogModule("hal");
77 MOZ_ASSERT(NS_IsMainThread());
83 return GeckoProcessType_Content
== XRE_GetProcessType();
89 MOZ_ASSERT(GeckoProcessType_Default
== XRE_GetProcessType());
93 WindowIsActive(nsIDOMWindow
* aWindow
)
95 nsCOMPtr
<nsPIDOMWindow
> window
= do_QueryInterface(aWindow
);
96 NS_ENSURE_TRUE(window
, false);
98 nsIDocument
* document
= window
->GetDoc();
99 NS_ENSURE_TRUE(document
, false);
101 return !document
->Hidden();
104 StaticAutoPtr
<WindowIdentifier::IDArrayType
> gLastIDToVibrate
;
106 void InitLastIDToVibrate()
108 gLastIDToVibrate
= new WindowIdentifier::IDArrayType();
109 ClearOnShutdown(&gLastIDToVibrate
);
112 } // anonymous namespace
115 Vibrate(const nsTArray
<uint32_t>& pattern
, nsIDOMWindow
* window
)
117 Vibrate(pattern
, WindowIdentifier(window
));
121 Vibrate(const nsTArray
<uint32_t>& pattern
, const WindowIdentifier
&id
)
125 // Only active windows may start vibrations. If |id| hasn't gone
126 // through the IPC layer -- that is, if our caller is the outside
127 // world, not hal_proxy -- check whether the window is active. If
128 // |id| has gone through IPC, don't check the window's visibility;
129 // only the window corresponding to the bottommost process has its
130 // visibility state set correctly.
131 if (!id
.HasTraveledThroughIPC() && !WindowIsActive(id
.GetWindow())) {
132 HAL_LOG(("Vibrate: Window is inactive, dropping vibrate."));
137 if (!gLastIDToVibrate
) {
138 InitLastIDToVibrate();
140 *gLastIDToVibrate
= id
.AsArray();
143 // Don't forward our ID if we are not in the sandbox, because hal_impl
144 // doesn't need it, and we don't want it to be tempted to read it. The
145 // empty identifier will assert if it's used.
146 PROXY_IF_SANDBOXED(Vibrate(pattern
, InSandbox() ? id
: WindowIdentifier()));
150 CancelVibrate(nsIDOMWindow
* window
)
152 CancelVibrate(WindowIdentifier(window
));
156 CancelVibrate(const WindowIdentifier
&id
)
160 // Although only active windows may start vibrations, a window may
161 // cancel its own vibration even if it's no longer active.
163 // After a window is marked as inactive, it sends a CancelVibrate
164 // request. We want this request to cancel a playing vibration
165 // started by that window, so we certainly don't want to reject the
166 // cancellation request because the window is now inactive.
168 // But it could be the case that, after this window became inactive,
169 // some other window came along and started a vibration. We don't
170 // want this window's cancellation request to cancel that window's
171 // actively-playing vibration!
173 // To solve this problem, we keep track of the id of the last window
174 // to start a vibration, and only accepts cancellation requests from
175 // the same window. All other cancellation requests are ignored.
177 if (InSandbox() || (gLastIDToVibrate
&& *gLastIDToVibrate
== id
.AsArray())) {
178 // Don't forward our ID if we are not in the sandbox, because hal_impl
179 // doesn't need it, and we don't want it to be tempted to read it. The
180 // empty identifier will assert if it's used.
181 PROXY_IF_SANDBOXED(CancelVibrate(InSandbox() ? id
: WindowIdentifier()));
185 template <class InfoType
>
186 class ObserversManager
189 void AddObserver(Observer
<InfoType
>* aObserver
) {
191 mObservers
= new mozilla::ObserverList
<InfoType
>();
194 mObservers
->AddObserver(aObserver
);
196 if (mObservers
->Length() == 1) {
197 EnableNotifications();
201 void RemoveObserver(Observer
<InfoType
>* aObserver
) {
202 bool removed
= mObservers
&& mObservers
->RemoveObserver(aObserver
);
204 NS_WARNING("RemoveObserver() called for unregistered observer");
208 if (mObservers
->Length() == 0) {
209 DisableNotifications();
211 OnNotificationsDisabled();
214 mObservers
= nullptr;
218 void BroadcastInformation(const InfoType
& aInfo
) {
219 // It is possible for mObservers to be nullptr here on some platforms,
220 // because a call to BroadcastInformation gets queued up asynchronously
221 // while RemoveObserver is running (and before the notifications are
222 // disabled). The queued call can then get run after mObservers has
223 // been nulled out. See bug 757025.
227 mObservers
->Broadcast(aInfo
);
231 virtual void EnableNotifications() = 0;
232 virtual void DisableNotifications() = 0;
233 virtual void OnNotificationsDisabled() {}
236 mozilla::ObserverList
<InfoType
>* mObservers
;
239 template <class InfoType
>
240 class CachingObserversManager
: public ObserversManager
<InfoType
>
243 InfoType
GetCurrentInformation() {
244 if (mHasValidCache
) {
248 GetCurrentInformationInternal(&mInfo
);
249 mHasValidCache
= true;
253 void CacheInformation(const InfoType
& aInfo
) {
254 mHasValidCache
= true;
258 void BroadcastCachedInformation() {
259 this->BroadcastInformation(mInfo
);
263 virtual void GetCurrentInformationInternal(InfoType
*) = 0;
265 virtual void OnNotificationsDisabled() {
266 mHasValidCache
= false;
274 class BatteryObserversManager
: public CachingObserversManager
<BatteryInformation
>
277 void EnableNotifications() {
278 PROXY_IF_SANDBOXED(EnableBatteryNotifications());
281 void DisableNotifications() {
282 PROXY_IF_SANDBOXED(DisableBatteryNotifications());
285 void GetCurrentInformationInternal(BatteryInformation
* aInfo
) {
286 PROXY_IF_SANDBOXED(GetCurrentBatteryInformation(aInfo
));
290 static BatteryObserversManager sBatteryObservers
;
292 class NetworkObserversManager
: public CachingObserversManager
<NetworkInformation
>
295 void EnableNotifications() {
296 PROXY_IF_SANDBOXED(EnableNetworkNotifications());
299 void DisableNotifications() {
300 PROXY_IF_SANDBOXED(DisableNetworkNotifications());
303 void GetCurrentInformationInternal(NetworkInformation
* aInfo
) {
304 PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo
));
308 static NetworkObserversManager sNetworkObservers
;
310 class WakeLockObserversManager
: public ObserversManager
<WakeLockInformation
>
313 void EnableNotifications() {
314 PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
317 void DisableNotifications() {
318 PROXY_IF_SANDBOXED(DisableWakeLockNotifications());
322 static WakeLockObserversManager sWakeLockObservers
;
324 class ScreenConfigurationObserversManager
: public CachingObserversManager
<ScreenConfiguration
>
327 void EnableNotifications() {
328 PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
331 void DisableNotifications() {
332 PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
335 void GetCurrentInformationInternal(ScreenConfiguration
* aInfo
) {
336 PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo
));
340 static ScreenConfigurationObserversManager sScreenConfigurationObservers
;
343 RegisterBatteryObserver(BatteryObserver
* aObserver
)
346 sBatteryObservers
.AddObserver(aObserver
);
350 UnregisterBatteryObserver(BatteryObserver
* aObserver
)
353 sBatteryObservers
.RemoveObserver(aObserver
);
357 GetCurrentBatteryInformation(BatteryInformation
* aInfo
)
360 *aInfo
= sBatteryObservers
.GetCurrentInformation();
364 NotifyBatteryChange(const BatteryInformation
& aInfo
)
367 sBatteryObservers
.CacheInformation(aInfo
);
368 sBatteryObservers
.BroadcastCachedInformation();
371 bool GetScreenEnabled()
374 RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false);
377 void SetScreenEnabled(bool enabled
)
380 PROXY_IF_SANDBOXED(SetScreenEnabled(enabled
));
383 bool GetCpuSleepAllowed()
385 // Generally for interfaces that are accessible by normal web content
386 // we should cache the result and be notified on state changes, like
387 // what the battery API does. But since this is only used by
388 // privileged interface, the synchronous getter is OK here.
390 RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed(), true);
393 void SetCpuSleepAllowed(bool allowed
)
396 PROXY_IF_SANDBOXED(SetCpuSleepAllowed(allowed
));
399 double GetScreenBrightness()
402 RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness(), 0);
405 void SetScreenBrightness(double brightness
)
408 PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(brightness
, 0.0, 1.0)));
411 bool SetLight(LightType light
, const LightConfiguration
& aConfig
)
414 RETURN_PROXY_IF_SANDBOXED(SetLight(light
, aConfig
), false);
417 bool GetLight(LightType light
, LightConfiguration
* aConfig
)
420 RETURN_PROXY_IF_SANDBOXED(GetLight(light
, aConfig
), false);
423 class SystemClockChangeObserversManager
: public ObserversManager
<int64_t>
426 void EnableNotifications() {
427 PROXY_IF_SANDBOXED(EnableSystemClockChangeNotifications());
430 void DisableNotifications() {
431 PROXY_IF_SANDBOXED(DisableSystemClockChangeNotifications());
435 static SystemClockChangeObserversManager sSystemClockChangeObservers
;
438 RegisterSystemClockChangeObserver(SystemClockChangeObserver
* aObserver
)
441 sSystemClockChangeObservers
.AddObserver(aObserver
);
445 UnregisterSystemClockChangeObserver(SystemClockChangeObserver
* aObserver
)
448 sSystemClockChangeObservers
.RemoveObserver(aObserver
);
452 NotifySystemClockChange(const int64_t& aClockDeltaMS
)
454 sSystemClockChangeObservers
.BroadcastInformation(aClockDeltaMS
);
457 class SystemTimezoneChangeObserversManager
: public ObserversManager
<SystemTimezoneChangeInformation
>
460 void EnableNotifications() {
461 PROXY_IF_SANDBOXED(EnableSystemTimezoneChangeNotifications());
464 void DisableNotifications() {
465 PROXY_IF_SANDBOXED(DisableSystemTimezoneChangeNotifications());
469 static SystemTimezoneChangeObserversManager sSystemTimezoneChangeObservers
;
472 RegisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver
* aObserver
)
475 sSystemTimezoneChangeObservers
.AddObserver(aObserver
);
479 UnregisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver
* aObserver
)
482 sSystemTimezoneChangeObservers
.RemoveObserver(aObserver
);
486 NotifySystemTimezoneChange(const SystemTimezoneChangeInformation
& aSystemTimezoneChangeInfo
)
488 sSystemTimezoneChangeObservers
.BroadcastInformation(aSystemTimezoneChangeInfo
);
492 AdjustSystemClock(int64_t aDeltaMilliseconds
)
495 PROXY_IF_SANDBOXED(AdjustSystemClock(aDeltaMilliseconds
));
499 SetTimezone(const nsCString
& aTimezoneSpec
)
502 PROXY_IF_SANDBOXED(SetTimezone(aTimezoneSpec
));
509 RETURN_PROXY_IF_SANDBOXED(GetTimezoneOffset(), 0);
516 RETURN_PROXY_IF_SANDBOXED(GetTimezone(), nsCString(""));
520 EnableSensorNotifications(SensorType aSensor
) {
522 PROXY_IF_SANDBOXED(EnableSensorNotifications(aSensor
));
526 DisableSensorNotifications(SensorType aSensor
) {
528 PROXY_IF_SANDBOXED(DisableSensorNotifications(aSensor
));
531 typedef mozilla::ObserverList
<SensorData
> SensorObserverList
;
532 static SensorObserverList
* gSensorObservers
= nullptr;
534 static SensorObserverList
&
535 GetSensorObservers(SensorType sensor_type
) {
536 MOZ_ASSERT(sensor_type
< NUM_SENSOR_TYPE
);
538 if(!gSensorObservers
) {
539 gSensorObservers
= new SensorObserverList
[NUM_SENSOR_TYPE
];
541 return gSensorObservers
[sensor_type
];
545 RegisterSensorObserver(SensorType aSensor
, ISensorObserver
*aObserver
) {
546 SensorObserverList
&observers
= GetSensorObservers(aSensor
);
550 observers
.AddObserver(aObserver
);
551 if(observers
.Length() == 1) {
552 EnableSensorNotifications(aSensor
);
557 UnregisterSensorObserver(SensorType aSensor
, ISensorObserver
*aObserver
) {
560 if (!gSensorObservers
) {
564 SensorObserverList
&observers
= GetSensorObservers(aSensor
);
565 if (!observers
.RemoveObserver(aObserver
) || observers
.Length() > 0) {
568 DisableSensorNotifications(aSensor
);
570 // Destroy sSensorObservers only if all observer lists are empty.
571 for (int i
= 0; i
< NUM_SENSOR_TYPE
; i
++) {
572 if (gSensorObservers
[i
].Length() > 0) {
576 delete [] gSensorObservers
;
577 gSensorObservers
= nullptr;
581 NotifySensorChange(const SensorData
&aSensorData
) {
582 SensorObserverList
&observers
= GetSensorObservers(aSensorData
.sensor());
586 observers
.Broadcast(aSensorData
);
590 RegisterNetworkObserver(NetworkObserver
* aObserver
)
593 sNetworkObservers
.AddObserver(aObserver
);
597 UnregisterNetworkObserver(NetworkObserver
* aObserver
)
600 sNetworkObservers
.RemoveObserver(aObserver
);
604 GetCurrentNetworkInformation(NetworkInformation
* aInfo
)
607 *aInfo
= sNetworkObservers
.GetCurrentInformation();
611 NotifyNetworkChange(const NetworkInformation
& aInfo
)
613 sNetworkObservers
.CacheInformation(aInfo
);
614 sNetworkObservers
.BroadcastCachedInformation();
621 PROXY_IF_SANDBOXED(Reboot());
628 PROXY_IF_SANDBOXED(PowerOff());
631 void StartForceQuitWatchdog(ShutdownMode aMode
, int32_t aTimeoutSecs
)
635 PROXY_IF_SANDBOXED(StartForceQuitWatchdog(aMode
, aTimeoutSecs
));
638 void StartMonitoringGamepadStatus()
640 PROXY_IF_SANDBOXED(StartMonitoringGamepadStatus());
643 void StopMonitoringGamepadStatus()
645 PROXY_IF_SANDBOXED(StopMonitoringGamepadStatus());
649 RegisterWakeLockObserver(WakeLockObserver
* aObserver
)
652 sWakeLockObservers
.AddObserver(aObserver
);
656 UnregisterWakeLockObserver(WakeLockObserver
* aObserver
)
659 sWakeLockObservers
.RemoveObserver(aObserver
);
663 ModifyWakeLock(const nsAString
& aTopic
,
664 WakeLockControl aLockAdjust
,
665 WakeLockControl aHiddenAdjust
,
666 uint64_t aProcessID
/* = CONTENT_PROCESS_ID_UNKNOWN */)
670 if (aProcessID
== CONTENT_PROCESS_ID_UNKNOWN
) {
671 aProcessID
= InSandbox() ? ContentChild::GetSingleton()->GetID() :
672 CONTENT_PROCESS_ID_MAIN
;
675 PROXY_IF_SANDBOXED(ModifyWakeLock(aTopic
, aLockAdjust
,
676 aHiddenAdjust
, aProcessID
));
680 GetWakeLockInfo(const nsAString
& aTopic
, WakeLockInformation
* aWakeLockInfo
)
683 PROXY_IF_SANDBOXED(GetWakeLockInfo(aTopic
, aWakeLockInfo
));
687 NotifyWakeLockChange(const WakeLockInformation
& aInfo
)
690 sWakeLockObservers
.BroadcastInformation(aInfo
);
694 RegisterScreenConfigurationObserver(ScreenConfigurationObserver
* aObserver
)
697 sScreenConfigurationObservers
.AddObserver(aObserver
);
701 UnregisterScreenConfigurationObserver(ScreenConfigurationObserver
* aObserver
)
704 sScreenConfigurationObservers
.RemoveObserver(aObserver
);
708 GetCurrentScreenConfiguration(ScreenConfiguration
* aScreenConfiguration
)
711 *aScreenConfiguration
= sScreenConfigurationObservers
.GetCurrentInformation();
715 NotifyScreenConfigurationChange(const ScreenConfiguration
& aScreenConfiguration
)
717 sScreenConfigurationObservers
.CacheInformation(aScreenConfiguration
);
718 sScreenConfigurationObservers
.BroadcastCachedInformation();
722 LockScreenOrientation(const dom::ScreenOrientation
& aOrientation
)
725 RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation
), false);
729 UnlockScreenOrientation()
732 PROXY_IF_SANDBOXED(UnlockScreenOrientation());
736 EnableSwitchNotifications(SwitchDevice aDevice
) {
738 PROXY_IF_SANDBOXED(EnableSwitchNotifications(aDevice
));
742 DisableSwitchNotifications(SwitchDevice aDevice
) {
744 PROXY_IF_SANDBOXED(DisableSwitchNotifications(aDevice
));
747 SwitchState
GetCurrentSwitchState(SwitchDevice aDevice
)
750 RETURN_PROXY_IF_SANDBOXED(GetCurrentSwitchState(aDevice
), SWITCH_STATE_UNKNOWN
);
753 void NotifySwitchStateFromInputDevice(SwitchDevice aDevice
, SwitchState aState
)
755 PROXY_IF_SANDBOXED(NotifySwitchStateFromInputDevice(aDevice
, aState
));
758 typedef mozilla::ObserverList
<SwitchEvent
> SwitchObserverList
;
760 static SwitchObserverList
*sSwitchObserverLists
= nullptr;
762 static SwitchObserverList
&
763 GetSwitchObserverList(SwitchDevice aDevice
) {
764 MOZ_ASSERT(0 <= aDevice
&& aDevice
< NUM_SWITCH_DEVICE
);
765 if (sSwitchObserverLists
== nullptr) {
766 sSwitchObserverLists
= new SwitchObserverList
[NUM_SWITCH_DEVICE
];
768 return sSwitchObserverLists
[aDevice
];
772 ReleaseObserversIfNeeded() {
773 for (int i
= 0; i
< NUM_SWITCH_DEVICE
; i
++) {
774 if (sSwitchObserverLists
[i
].Length() != 0)
778 //The length of every list is 0, no observer in the list.
779 delete [] sSwitchObserverLists
;
780 sSwitchObserverLists
= nullptr;
784 RegisterSwitchObserver(SwitchDevice aDevice
, SwitchObserver
*aObserver
)
787 SwitchObserverList
& observer
= GetSwitchObserverList(aDevice
);
788 observer
.AddObserver(aObserver
);
789 if (observer
.Length() == 1) {
790 EnableSwitchNotifications(aDevice
);
795 UnregisterSwitchObserver(SwitchDevice aDevice
, SwitchObserver
*aObserver
)
799 if (!sSwitchObserverLists
) {
803 SwitchObserverList
& observer
= GetSwitchObserverList(aDevice
);
804 if (!observer
.RemoveObserver(aObserver
) || observer
.Length() > 0) {
808 DisableSwitchNotifications(aDevice
);
809 ReleaseObserversIfNeeded();
813 NotifySwitchChange(const SwitchEvent
& aEvent
)
815 // When callback this notification, main thread may call unregister function
816 // first. We should check if this pointer is valid.
817 if (!sSwitchObserverLists
)
820 SwitchObserverList
& observer
= GetSwitchObserverList(aEvent
.device());
821 observer
.Broadcast(aEvent
);
824 static AlarmObserver
* sAlarmObserver
;
827 RegisterTheOneAlarmObserver(AlarmObserver
* aObserver
)
829 MOZ_ASSERT(!InSandbox());
830 MOZ_ASSERT(!sAlarmObserver
);
832 sAlarmObserver
= aObserver
;
833 RETURN_PROXY_IF_SANDBOXED(EnableAlarm(), false);
837 UnregisterTheOneAlarmObserver()
839 if (sAlarmObserver
) {
840 sAlarmObserver
= nullptr;
841 PROXY_IF_SANDBOXED(DisableAlarm());
848 if (sAlarmObserver
) {
849 sAlarmObserver
->Notify(void_t());
854 SetAlarm(int32_t aSeconds
, int32_t aNanoseconds
)
856 // It's pointless to program an alarm nothing is going to observe ...
857 MOZ_ASSERT(sAlarmObserver
);
858 RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds
, aNanoseconds
), false);
862 SetProcessPriority(int aPid
,
863 ProcessPriority aPriority
,
864 ProcessCPUPriority aCPUPriority
,
865 uint32_t aBackgroundLRU
)
867 // n.b. The sandboxed implementation crashes; SetProcessPriority works only
868 // from the main process.
869 MOZ_ASSERT(aBackgroundLRU
== 0 || aPriority
== PROCESS_PRIORITY_BACKGROUND
);
870 PROXY_IF_SANDBOXED(SetProcessPriority(aPid
, aPriority
, aCPUPriority
,
875 SetCurrentThreadPriority(hal::ThreadPriority aThreadPriority
)
877 PROXY_IF_SANDBOXED(SetCurrentThreadPriority(aThreadPriority
));
882 ProcessPriorityToString(ProcessPriority aPriority
)
885 case PROCESS_PRIORITY_MASTER
:
887 case PROCESS_PRIORITY_PREALLOC
:
889 case PROCESS_PRIORITY_FOREGROUND_HIGH
:
890 return "FOREGROUND_HIGH";
891 case PROCESS_PRIORITY_FOREGROUND
:
893 case PROCESS_PRIORITY_FOREGROUND_KEYBOARD
:
894 return "FOREGROUND_KEYBOARD";
895 case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE
:
896 return "BACKGROUND_PERCEIVABLE";
897 case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN
:
898 return "BACKGROUND_HOMESCREEN";
899 case PROCESS_PRIORITY_BACKGROUND
:
901 case PROCESS_PRIORITY_UNKNOWN
:
910 ThreadPriorityToString(ThreadPriority aPriority
)
913 case THREAD_PRIORITY_COMPOSITOR
:
923 ProcessPriorityToString(ProcessPriority aPriority
,
924 ProcessCPUPriority aCPUPriority
)
926 // Sorry this is ugly. At least it's all in one place.
928 // We intentionally fall through if aCPUPriority is invalid; we won't hit any
929 // of the if statements further down, so it's OK.
932 case PROCESS_PRIORITY_MASTER
:
933 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
934 return "MASTER:CPU_NORMAL";
936 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
937 return "MASTER:CPU_LOW";
939 case PROCESS_PRIORITY_PREALLOC
:
940 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
941 return "PREALLOC:CPU_NORMAL";
943 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
944 return "PREALLOC:CPU_LOW";
946 case PROCESS_PRIORITY_FOREGROUND_HIGH
:
947 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
948 return "FOREGROUND_HIGH:CPU_NORMAL";
950 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
951 return "FOREGROUND_HIGH:CPU_LOW";
953 case PROCESS_PRIORITY_FOREGROUND
:
954 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
955 return "FOREGROUND:CPU_NORMAL";
957 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
958 return "FOREGROUND:CPU_LOW";
960 case PROCESS_PRIORITY_FOREGROUND_KEYBOARD
:
961 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
962 return "FOREGROUND_KEYBOARD:CPU_NORMAL";
964 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
965 return "FOREGROUND_KEYBOARD:CPU_LOW";
967 case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE
:
968 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
969 return "BACKGROUND_PERCEIVABLE:CPU_NORMAL";
971 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
972 return "BACKGROUND_PERCEIVABLE:CPU_LOW";
974 case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN
:
975 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
976 return "BACKGROUND_HOMESCREEN:CPU_NORMAL";
978 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
979 return "BACKGROUND_HOMESCREEN:CPU_LOW";
981 case PROCESS_PRIORITY_BACKGROUND
:
982 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
983 return "BACKGROUND:CPU_NORMAL";
985 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
986 return "BACKGROUND:CPU_LOW";
988 case PROCESS_PRIORITY_UNKNOWN
:
989 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
990 return "UNKNOWN:CPU_NORMAL";
992 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
993 return "UNKNOWN:CPU_LOW";
996 // Fall through. (|default| is here to silence warnings.)
1004 static StaticAutoPtr
<ObserverList
<FMRadioOperationInformation
> > sFMRadioObservers
;
1007 InitializeFMRadioObserver()
1009 if (!sFMRadioObservers
) {
1010 sFMRadioObservers
= new ObserverList
<FMRadioOperationInformation
>;
1011 ClearOnShutdown(&sFMRadioObservers
);
1016 RegisterFMRadioObserver(FMRadioObserver
* aFMRadioObserver
) {
1018 InitializeFMRadioObserver();
1019 sFMRadioObservers
->AddObserver(aFMRadioObserver
);
1023 UnregisterFMRadioObserver(FMRadioObserver
* aFMRadioObserver
) {
1025 InitializeFMRadioObserver();
1026 sFMRadioObservers
->RemoveObserver(aFMRadioObserver
);
1030 NotifyFMRadioStatus(const FMRadioOperationInformation
& aFMRadioState
) {
1031 InitializeFMRadioObserver();
1032 sFMRadioObservers
->Broadcast(aFMRadioState
);
1036 EnableFMRadio(const FMRadioSettings
& aInfo
) {
1038 PROXY_IF_SANDBOXED(EnableFMRadio(aInfo
));
1044 PROXY_IF_SANDBOXED(DisableFMRadio());
1048 FMRadioSeek(const FMRadioSeekDirection
& aDirection
) {
1050 PROXY_IF_SANDBOXED(FMRadioSeek(aDirection
));
1054 GetFMRadioSettings(FMRadioSettings
* aInfo
) {
1056 PROXY_IF_SANDBOXED(GetFMRadioSettings(aInfo
));
1060 SetFMRadioFrequency(const uint32_t aFrequency
) {
1062 PROXY_IF_SANDBOXED(SetFMRadioFrequency(aFrequency
));
1066 GetFMRadioFrequency() {
1068 RETURN_PROXY_IF_SANDBOXED(GetFMRadioFrequency(), 0);
1074 RETURN_PROXY_IF_SANDBOXED(IsFMRadioOn(), false);
1078 GetFMRadioSignalStrength() {
1080 RETURN_PROXY_IF_SANDBOXED(GetFMRadioSignalStrength(), 0);
1084 CancelFMRadioSeek() {
1086 PROXY_IF_SANDBOXED(CancelFMRadioSeek());
1090 GetFMBandSettings(FMRadioCountry aCountry
) {
1091 FMRadioSettings settings
;
1094 case FM_RADIO_COUNTRY_US
:
1095 case FM_RADIO_COUNTRY_EU
:
1096 settings
.upperLimit() = 108000;
1097 settings
.lowerLimit() = 87800;
1098 settings
.spaceType() = 200;
1099 settings
.preEmphasis() = 75;
1101 case FM_RADIO_COUNTRY_JP_STANDARD
:
1102 settings
.upperLimit() = 76000;
1103 settings
.lowerLimit() = 90000;
1104 settings
.spaceType() = 100;
1105 settings
.preEmphasis() = 50;
1107 case FM_RADIO_COUNTRY_CY
:
1108 case FM_RADIO_COUNTRY_DE
:
1109 case FM_RADIO_COUNTRY_DK
:
1110 case FM_RADIO_COUNTRY_ES
:
1111 case FM_RADIO_COUNTRY_FI
:
1112 case FM_RADIO_COUNTRY_FR
:
1113 case FM_RADIO_COUNTRY_HU
:
1114 case FM_RADIO_COUNTRY_IR
:
1115 case FM_RADIO_COUNTRY_IT
:
1116 case FM_RADIO_COUNTRY_KW
:
1117 case FM_RADIO_COUNTRY_LT
:
1118 case FM_RADIO_COUNTRY_ML
:
1119 case FM_RADIO_COUNTRY_NO
:
1120 case FM_RADIO_COUNTRY_OM
:
1121 case FM_RADIO_COUNTRY_PG
:
1122 case FM_RADIO_COUNTRY_NL
:
1123 case FM_RADIO_COUNTRY_CZ
:
1124 case FM_RADIO_COUNTRY_UK
:
1125 case FM_RADIO_COUNTRY_RW
:
1126 case FM_RADIO_COUNTRY_SN
:
1127 case FM_RADIO_COUNTRY_SI
:
1128 case FM_RADIO_COUNTRY_ZA
:
1129 case FM_RADIO_COUNTRY_SE
:
1130 case FM_RADIO_COUNTRY_CH
:
1131 case FM_RADIO_COUNTRY_TW
:
1132 case FM_RADIO_COUNTRY_UA
:
1133 settings
.upperLimit() = 108000;
1134 settings
.lowerLimit() = 87500;
1135 settings
.spaceType() = 100;
1136 settings
.preEmphasis() = 50;
1138 case FM_RADIO_COUNTRY_VA
:
1139 case FM_RADIO_COUNTRY_MA
:
1140 case FM_RADIO_COUNTRY_TR
:
1141 settings
.upperLimit() = 10800;
1142 settings
.lowerLimit() = 87500;
1143 settings
.spaceType() = 100;
1144 settings
.preEmphasis() = 75;
1146 case FM_RADIO_COUNTRY_AU
:
1147 case FM_RADIO_COUNTRY_BD
:
1148 settings
.upperLimit() = 108000;
1149 settings
.lowerLimit() = 87500;
1150 settings
.spaceType() = 200;
1151 settings
.preEmphasis() = 75;
1153 case FM_RADIO_COUNTRY_AW
:
1154 case FM_RADIO_COUNTRY_BS
:
1155 case FM_RADIO_COUNTRY_CO
:
1156 case FM_RADIO_COUNTRY_KR
:
1157 settings
.upperLimit() = 108000;
1158 settings
.lowerLimit() = 88000;
1159 settings
.spaceType() = 200;
1160 settings
.preEmphasis() = 75;
1162 case FM_RADIO_COUNTRY_EC
:
1163 settings
.upperLimit() = 108000;
1164 settings
.lowerLimit() = 88000;
1165 settings
.spaceType() = 200;
1166 settings
.preEmphasis() = 0;
1168 case FM_RADIO_COUNTRY_GM
:
1169 settings
.upperLimit() = 108000;
1170 settings
.lowerLimit() = 88000;
1171 settings
.spaceType() = 0;
1172 settings
.preEmphasis() = 75;
1174 case FM_RADIO_COUNTRY_QA
:
1175 settings
.upperLimit() = 108000;
1176 settings
.lowerLimit() = 88000;
1177 settings
.spaceType() = 200;
1178 settings
.preEmphasis() = 50;
1180 case FM_RADIO_COUNTRY_SG
:
1181 settings
.upperLimit() = 108000;
1182 settings
.lowerLimit() = 88000;
1183 settings
.spaceType() = 200;
1184 settings
.preEmphasis() = 50;
1186 case FM_RADIO_COUNTRY_IN
:
1187 settings
.upperLimit() = 100000;
1188 settings
.lowerLimit() = 108000;
1189 settings
.spaceType() = 100;
1190 settings
.preEmphasis() = 50;
1192 case FM_RADIO_COUNTRY_NZ
:
1193 settings
.upperLimit() = 100000;
1194 settings
.lowerLimit() = 88000;
1195 settings
.spaceType() = 50;
1196 settings
.preEmphasis() = 50;
1198 case FM_RADIO_COUNTRY_USER_DEFINED
:
1210 PROXY_IF_SANDBOXED(FactoryReset());
1214 StartDiskSpaceWatcher()
1216 AssertMainProcess();
1218 PROXY_IF_SANDBOXED(StartDiskSpaceWatcher());
1222 StopDiskSpaceWatcher()
1224 AssertMainProcess();
1226 PROXY_IF_SANDBOXED(StopDiskSpaceWatcher());
1230 GetTotalSystemMemory()
1232 return hal_impl::GetTotalSystemMemory();
1237 } // namespace mozilla