Bug 1339559 - Identify script that resulted in non-structured-clonable data r=kmag
[gecko.git] / hal / Hal.h
blobe45bbcde243f2ac44fc673a32fbcaa4668e89fed
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/. */
7 #ifndef mozilla_Hal_h
8 #define mozilla_Hal_h
10 #include "base/basictypes.h"
11 #include "base/platform_thread.h"
12 #include "nsTArray.h"
13 #include "mozilla/dom/battery/Types.h"
14 #include "mozilla/dom/MozPowerManagerBinding.h"
15 #include "mozilla/dom/network/Types.h"
16 #include "mozilla/dom/power/Types.h"
17 #include "mozilla/dom/ScreenOrientation.h"
18 #include "mozilla/hal_sandbox/PHal.h"
19 #include "mozilla/HalScreenConfiguration.h"
20 #include "mozilla/HalTypes.h"
21 #include "mozilla/Observer.h"
22 #include "mozilla/Types.h"
25 * Hal.h contains the public Hal API.
27 * By default, this file defines its functions in the hal namespace, but if
28 * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace.
30 * This is used by HalImpl.h and HalSandbox.h, which define copies of all the
31 * functions here in the hal_impl and hal_sandbox namespaces.
34 class nsPIDOMWindowInner;
36 #ifndef MOZ_HAL_NAMESPACE
37 # define MOZ_HAL_NAMESPACE hal
38 # define MOZ_DEFINED_HAL_NAMESPACE 1
39 #endif
41 namespace mozilla {
43 namespace hal {
45 typedef Observer<void_t> AlarmObserver;
47 class WindowIdentifier;
49 typedef Observer<int64_t> SystemClockChangeObserver;
50 typedef Observer<SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;
52 } // namespace hal
54 namespace MOZ_HAL_NAMESPACE {
56 /**
57 * Turn the default vibrator device on/off per the pattern specified
58 * by |pattern|. Each element in the pattern is the number of
59 * milliseconds to turn the vibrator on or off. The first element in
60 * |pattern| is an "on" element, the next is "off", and so on.
62 * If |pattern| is empty, any in-progress vibration is canceled.
64 * Only an active window within an active tab may call Vibrate; calls
65 * from inactive windows and windows on inactive tabs do nothing.
67 * If you're calling hal::Vibrate from the outside world, pass an
68 * nsIDOMWindow* in place of the WindowIdentifier parameter.
69 * The method with WindowIdentifier will be called automatically.
71 void Vibrate(const nsTArray<uint32_t>& pattern,
72 nsPIDOMWindowInner* aWindow);
73 void Vibrate(const nsTArray<uint32_t>& pattern,
74 const hal::WindowIdentifier &id);
76 /**
77 * Cancel a vibration started by the content window identified by
78 * WindowIdentifier.
80 * If the window was the last window to start a vibration, the
81 * cancellation request will go through even if the window is not
82 * active.
84 * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside
85 * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called
86 * automatically.
88 void CancelVibrate(nsPIDOMWindowInner* aWindow);
89 void CancelVibrate(const hal::WindowIdentifier &id);
91 /**
92 * Inform the battery backend there is a new battery observer.
93 * @param aBatteryObserver The observer that should be added.
95 void RegisterBatteryObserver(BatteryObserver* aBatteryObserver);
97 /**
98 * Inform the battery backend a battery observer unregistered.
99 * @param aBatteryObserver The observer that should be removed.
101 void UnregisterBatteryObserver(BatteryObserver* aBatteryObserver);
104 * Returns the current battery information.
106 void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
109 * Notify of a change in the battery state.
110 * @param aBatteryInfo The new battery information.
112 void NotifyBatteryChange(const hal::BatteryInformation& aBatteryInfo);
115 * Determine whether the device's screen is currently enabled.
117 bool GetScreenEnabled();
120 * Enable or disable the device's screen.
122 * Note that it may take a few seconds for the screen to turn on or off.
124 void SetScreenEnabled(bool aEnabled);
127 * Determine whether the device's keypad/button backlight is currently enabled.
129 bool GetKeyLightEnabled();
132 * Enable or disable the device's keypad/button backlight.
134 void SetKeyLightEnabled(bool aEnabled);
137 * Get the brightness of the device's screen's backlight, on a scale from 0
138 * (very dim) to 1 (full blast).
140 * If the display is currently disabled, this returns the brightness the
141 * backlight will have when the display is re-enabled.
143 double GetScreenBrightness();
146 * Set the brightness of the device's screen's backlight, on a scale from 0
147 * (very dimm) to 1 (full blast). Values larger than 1 are treated like 1, and
148 * values smaller than 0 are treated like 0.
150 * Note that we may reduce the resolution of the given brightness value before
151 * sending it to the screen. Therefore if you call SetScreenBrightness(x)
152 * followed by GetScreenBrightness(), the value returned by
153 * GetScreenBrightness() may not be exactly x.
155 void SetScreenBrightness(double aBrightness);
158 * Determine whether the device is allowed to sleep.
160 bool GetCpuSleepAllowed();
163 * Set whether the device is allowed to suspend automatically after
164 * the screen is disabled.
166 void SetCpuSleepAllowed(bool aAllowed);
169 * Register an observer for the sensor of given type.
171 * The observer will receive data whenever the data generated by the
172 * sensor is avaiable.
174 void RegisterSensorObserver(hal::SensorType aSensor,
175 hal::ISensorObserver *aObserver);
178 * Unregister an observer for the sensor of given type.
180 void UnregisterSensorObserver(hal::SensorType aSensor,
181 hal::ISensorObserver *aObserver);
184 * Post a value generated by a sensor.
186 * This API is internal to hal; clients shouldn't call it directly.
188 void NotifySensorChange(const hal::SensorData &aSensorData);
191 * Enable sensor notifications from the backend
193 * This method is only visible from implementation of sensor manager.
194 * Rest of the system should not try this.
196 void EnableSensorNotifications(hal::SensorType aSensor);
199 * Disable sensor notifications from the backend
201 * This method is only visible from implementation of sensor manager.
202 * Rest of the system should not try this.
204 void DisableSensorNotifications(hal::SensorType aSensor);
208 * Inform the network backend there is a new network observer.
209 * @param aNetworkObserver The observer that should be added.
211 void RegisterNetworkObserver(NetworkObserver* aNetworkObserver);
214 * Inform the network backend a network observer unregistered.
215 * @param aNetworkObserver The observer that should be removed.
217 void UnregisterNetworkObserver(NetworkObserver* aNetworkObserver);
220 * Returns the current network information.
222 void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
225 * Notify of a change in the network state.
226 * @param aNetworkInfo The new network information.
228 void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
231 * Adjusting system clock.
232 * @param aDeltaMilliseconds The difference compared with current system clock.
234 void AdjustSystemClock(int64_t aDeltaMilliseconds);
237 * Set timezone
238 * @param aTimezoneSpec The definition can be found in
239 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
241 void SetTimezone(const nsCString& aTimezoneSpec);
244 * Get timezone
245 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
247 nsCString GetTimezone();
250 * Get timezone offset
251 * returns the timezone offset relative to UTC in minutes (DST effect included)
253 int32_t GetTimezoneOffset();
256 * Register observer for system clock changed notification.
257 * @param aObserver The observer that should be added.
259 void RegisterSystemClockChangeObserver(
260 hal::SystemClockChangeObserver* aObserver);
263 * Unregister the observer for system clock changed.
264 * @param aObserver The observer that should be removed.
266 void UnregisterSystemClockChangeObserver(
267 hal::SystemClockChangeObserver* aObserver);
270 * Notify of a change in the system clock.
271 * @param aClockDeltaMS
273 void NotifySystemClockChange(const int64_t& aClockDeltaMS);
276 * Register observer for system timezone changed notification.
277 * @param aObserver The observer that should be added.
279 void RegisterSystemTimezoneChangeObserver(
280 hal::SystemTimezoneChangeObserver* aObserver);
283 * Unregister the observer for system timezone changed.
284 * @param aObserver The observer that should be removed.
286 void UnregisterSystemTimezoneChangeObserver(
287 hal::SystemTimezoneChangeObserver* aObserver);
290 * Notify of a change in the system timezone.
291 * @param aSystemTimezoneChangeInfo
293 void NotifySystemTimezoneChange(
294 const hal::SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo);
297 * Reboot the device.
299 * This API is currently only allowed to be used from the main process.
301 void Reboot();
304 * Power off the device.
306 * This API is currently only allowed to be used from the main process.
308 void PowerOff();
311 * Enable wake lock notifications from the backend.
313 * This method is only used by WakeLockObserversManager.
315 void EnableWakeLockNotifications();
318 * Disable wake lock notifications from the backend.
320 * This method is only used by WakeLockObserversManager.
322 void DisableWakeLockNotifications();
325 * Inform the wake lock backend there is a new wake lock observer.
326 * @param aWakeLockObserver The observer that should be added.
328 void RegisterWakeLockObserver(WakeLockObserver* aObserver);
331 * Inform the wake lock backend a wake lock observer unregistered.
332 * @param aWakeLockObserver The observer that should be removed.
334 void UnregisterWakeLockObserver(WakeLockObserver* aObserver);
337 * Adjust a wake lock's counts on behalf of a given process.
339 * In most cases, you shouldn't need to pass the aProcessID argument; the
340 * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
342 * @param aTopic lock topic
343 * @param aLockAdjust to increase or decrease active locks
344 * @param aHiddenAdjust to increase or decrease hidden locks
345 * @param aProcessID indicates which process we're modifying the wake lock
346 * on behalf of. It is interpreted as
348 * CONTENT_PROCESS_ID_UNKNOWN: The current process
349 * CONTENT_PROCESS_ID_MAIN: The root process
350 * X: The process with ContentChild::GetID() == X
352 void ModifyWakeLock(const nsAString &aTopic,
353 hal::WakeLockControl aLockAdjust,
354 hal::WakeLockControl aHiddenAdjust,
355 uint64_t aProcessID = hal::CONTENT_PROCESS_ID_UNKNOWN);
358 * Query the wake lock numbers of aTopic.
359 * @param aTopic lock topic
360 * @param aWakeLockInfo wake lock numbers
362 void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLockInfo);
365 * Notify of a change in the wake lock state.
366 * @param aWakeLockInfo The new wake lock information.
368 void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
371 * Inform the backend there is a new screen configuration observer.
372 * @param aScreenConfigurationObserver The observer that should be added.
374 void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
377 * Inform the backend a screen configuration observer unregistered.
378 * @param aScreenConfigurationObserver The observer that should be removed.
380 void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
383 * Returns the current screen configuration.
385 void GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration);
388 * Notify of a change in the screen configuration.
389 * @param aScreenConfiguration The new screen orientation.
391 void NotifyScreenConfigurationChange(const hal::ScreenConfiguration& aScreenConfiguration);
394 * Lock the screen orientation to the specific orientation.
395 * @return Whether the lock has been accepted.
397 MOZ_MUST_USE bool LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation);
400 * Unlock the screen orientation.
402 void UnlockScreenOrientation();
405 * Register an observer for the switch of given SwitchDevice.
407 * The observer will receive data whenever the data generated by the
408 * given switch.
410 void RegisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
413 * Unregister an observer for the switch of given SwitchDevice.
415 void UnregisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
418 * Notify the state of the switch.
420 * This API is internal to hal; clients shouldn't call it directly.
422 void NotifySwitchChange(const hal::SwitchEvent& aEvent);
425 * Get current switch information.
427 hal::SwitchState GetCurrentSwitchState(hal::SwitchDevice aDevice);
430 * Notify switch status change from input device.
432 void NotifySwitchStateFromInputDevice(hal::SwitchDevice aDevice,
433 hal::SwitchState aState);
436 * Register an observer that is notified when a programmed alarm
437 * expires.
439 * Currently, there can only be 0 or 1 alarm observers.
441 MOZ_MUST_USE bool RegisterTheOneAlarmObserver(hal::AlarmObserver* aObserver);
444 * Unregister the alarm observer. Doing so will implicitly cancel any
445 * programmed alarm.
447 void UnregisterTheOneAlarmObserver();
450 * Notify that the programmed alarm has expired.
452 * This API is internal to hal; clients shouldn't call it directly.
454 void NotifyAlarmFired();
457 * Program the real-time clock to expire at the time |aSeconds|,
458 * |aNanoseconds|. These specify a point in real time relative to the
459 * UNIX epoch. The alarm will fire at this time point even if the
460 * real-time clock is changed; that is, this alarm respects changes to
461 * the real-time clock. Return true iff the alarm was programmed.
463 * The alarm can be reprogrammed at any time.
465 * This API is currently only allowed to be used from non-sandboxed
466 * contexts.
468 MOZ_MUST_USE bool SetAlarm(int32_t aSeconds, int32_t aNanoseconds);
471 * Set the priority of the given process.
473 * Exactly what this does will vary between platforms. On *nix we might give
474 * background processes higher nice values. On other platforms, we might
475 * ignore this call entirely.
477 void SetProcessPriority(int aPid,
478 hal::ProcessPriority aPriority,
479 uint32_t aLRU = 0);
483 * Set the current thread's priority to appropriate platform-specific value for
484 * given functionality. Instead of providing arbitrary priority numbers you
485 * must specify a type of function like THREAD_PRIORITY_COMPOSITOR.
487 void SetCurrentThreadPriority(hal::ThreadPriority aThreadPriority);
490 * Set a thread priority to appropriate platform-specific value for
491 * given functionality. Instead of providing arbitrary priority numbers you
492 * must specify a type of function like THREAD_PRIORITY_COMPOSITOR.
494 void SetThreadPriority(PlatformThreadId aThreadId,
495 hal::ThreadPriority aThreadPriority);
498 * Start a watchdog to compulsively shutdown the system if it hangs.
499 * @param aMode Specify how to shutdown the system.
500 * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
502 * This API is currently only allowed to be used from the main process.
504 void StartForceQuitWatchdog(hal::ShutdownMode aMode, int32_t aTimeoutSecs);
507 * Perform Factory Reset to wipe out all user data.
509 void FactoryReset(mozilla::dom::FactoryResetReason& aReason);
512 * Start monitoring disk space for low space situations.
514 * This API is currently only allowed to be used from the main process.
516 void StartDiskSpaceWatcher();
519 * Stop monitoring disk space for low space situations.
521 * This API is currently only allowed to be used from the main process.
523 void StopDiskSpaceWatcher();
526 * Get total system memory of device being run on in bytes.
528 * Returns 0 if we are unable to determine this information from /proc/meminfo.
530 uint32_t GetTotalSystemMemory();
533 * Determine whether the headphone switch event is from input device
535 bool IsHeadphoneEventFromInputDev();
538 * Start the system service with the specified name and arguments.
540 nsresult StartSystemService(const char* aSvcName, const char* aArgs);
543 * Stop the system service with the specified name.
545 void StopSystemService(const char* aSvcName);
548 * Determine whether the system service with the specified name is running.
550 bool SystemServiceIsRunning(const char* aSvcName);
552 } // namespace MOZ_HAL_NAMESPACE
553 } // namespace mozilla
555 #ifdef MOZ_DEFINED_HAL_NAMESPACE
556 # undef MOZ_DEFINED_HAL_NAMESPACE
557 # undef MOZ_HAL_NAMESPACE
558 #endif
560 #endif // mozilla_Hal_h