Bumping manifests a=b2g-bump
[gecko.git] / hal / Hal.h
blob26eaff07ba9880d2ef7dd9f4205adf3812afb6a9
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 "mozilla/hal_sandbox/PHal.h"
11 #include "mozilla/HalTypes.h"
12 #include "base/basictypes.h"
13 #include "mozilla/Observer.h"
14 #include "mozilla/Types.h"
15 #include "nsTArray.h"
16 #include "prlog.h"
17 #include "mozilla/dom/MozPowerManagerBinding.h"
18 #include "mozilla/dom/battery/Types.h"
19 #include "mozilla/dom/network/Types.h"
20 #include "mozilla/dom/power/Types.h"
21 #include "mozilla/hal_sandbox/PHal.h"
22 #include "mozilla/dom/ScreenOrientation.h"
23 #include "mozilla/HalScreenConfiguration.h"
26 * Hal.h contains the public Hal API.
28 * By default, this file defines its functions in the hal namespace, but if
29 * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace.
31 * This is used by HalImpl.h and HalSandbox.h, which define copies of all the
32 * functions here in the hal_impl and hal_sandbox namespaces.
35 class nsIDOMWindow;
37 #ifndef MOZ_HAL_NAMESPACE
38 # define MOZ_HAL_NAMESPACE hal
39 # define MOZ_DEFINED_HAL_NAMESPACE 1
40 #endif
42 namespace mozilla {
44 namespace hal {
46 typedef Observer<void_t> AlarmObserver;
48 class WindowIdentifier;
50 extern PRLogModuleInfo *GetHalLog();
51 #define HAL_LOG(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, msg)
52 #define HAL_ERR(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_ERROR, msg)
54 typedef Observer<int64_t> SystemClockChangeObserver;
55 typedef Observer<SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;
57 } // namespace hal
59 namespace MOZ_HAL_NAMESPACE {
61 /**
62 * Turn the default vibrator device on/off per the pattern specified
63 * by |pattern|. Each element in the pattern is the number of
64 * milliseconds to turn the vibrator on or off. The first element in
65 * |pattern| is an "on" element, the next is "off", and so on.
67 * If |pattern| is empty, any in-progress vibration is canceled.
69 * Only an active window within an active tab may call Vibrate; calls
70 * from inactive windows and windows on inactive tabs do nothing.
72 * If you're calling hal::Vibrate from the outside world, pass an
73 * nsIDOMWindow* in place of the WindowIdentifier parameter.
74 * The method with WindowIdentifier will be called automatically.
76 void Vibrate(const nsTArray<uint32_t>& pattern,
77 nsIDOMWindow* aWindow);
78 void Vibrate(const nsTArray<uint32_t>& pattern,
79 const hal::WindowIdentifier &id);
81 /**
82 * Cancel a vibration started by the content window identified by
83 * WindowIdentifier.
85 * If the window was the last window to start a vibration, the
86 * cancellation request will go through even if the window is not
87 * active.
89 * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside
90 * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called
91 * automatically.
93 void CancelVibrate(nsIDOMWindow* aWindow);
94 void CancelVibrate(const hal::WindowIdentifier &id);
96 /**
97 * Inform the battery backend there is a new battery observer.
98 * @param aBatteryObserver The observer that should be added.
100 void RegisterBatteryObserver(BatteryObserver* aBatteryObserver);
103 * Inform the battery backend a battery observer unregistered.
104 * @param aBatteryObserver The observer that should be removed.
106 void UnregisterBatteryObserver(BatteryObserver* aBatteryObserver);
109 * Returns the current battery information.
111 void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
114 * Notify of a change in the battery state.
115 * @param aBatteryInfo The new battery information.
117 void NotifyBatteryChange(const hal::BatteryInformation& aBatteryInfo);
120 * Determine whether the device's screen is currently enabled.
122 bool GetScreenEnabled();
125 * Enable or disable the device's screen.
127 * Note that it may take a few seconds for the screen to turn on or off.
129 void SetScreenEnabled(bool aEnabled);
132 * Determine whether the device's keypad/button backlight is currently enabled.
134 bool GetKeyLightEnabled();
137 * Enable or disable the device's keypad/button backlight.
139 void SetKeyLightEnabled(bool aEnabled);
142 * Get the brightness of the device's screen's backlight, on a scale from 0
143 * (very dim) to 1 (full blast).
145 * If the display is currently disabled, this returns the brightness the
146 * backlight will have when the display is re-enabled.
148 double GetScreenBrightness();
151 * Set the brightness of the device's screen's backlight, on a scale from 0
152 * (very dimm) to 1 (full blast). Values larger than 1 are treated like 1, and
153 * values smaller than 0 are treated like 0.
155 * Note that we may reduce the resolution of the given brightness value before
156 * sending it to the screen. Therefore if you call SetScreenBrightness(x)
157 * followed by GetScreenBrightness(), the value returned by
158 * GetScreenBrightness() may not be exactly x.
160 void SetScreenBrightness(double aBrightness);
163 * Determine whether the device is allowed to sleep.
165 bool GetCpuSleepAllowed();
168 * Set whether the device is allowed to suspend automatically after
169 * the screen is disabled.
171 void SetCpuSleepAllowed(bool aAllowed);
174 * Register an observer for the sensor of given type.
176 * The observer will receive data whenever the data generated by the
177 * sensor is avaiable.
179 void RegisterSensorObserver(hal::SensorType aSensor,
180 hal::ISensorObserver *aObserver);
183 * Unregister an observer for the sensor of given type.
185 void UnregisterSensorObserver(hal::SensorType aSensor,
186 hal::ISensorObserver *aObserver);
189 * Post a value generated by a sensor.
191 * This API is internal to hal; clients shouldn't call it directly.
193 void NotifySensorChange(const hal::SensorData &aSensorData);
196 * Enable sensor notifications from the backend
198 * This method is only visible from implementation of sensor manager.
199 * Rest of the system should not try this.
201 void EnableSensorNotifications(hal::SensorType aSensor);
204 * Disable sensor notifications from the backend
206 * This method is only visible from implementation of sensor manager.
207 * Rest of the system should not try this.
209 void DisableSensorNotifications(hal::SensorType aSensor);
213 * Inform the network backend there is a new network observer.
214 * @param aNetworkObserver The observer that should be added.
216 void RegisterNetworkObserver(NetworkObserver* aNetworkObserver);
219 * Inform the network backend a network observer unregistered.
220 * @param aNetworkObserver The observer that should be removed.
222 void UnregisterNetworkObserver(NetworkObserver* aNetworkObserver);
225 * Returns the current network information.
227 void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
230 * Notify of a change in the network state.
231 * @param aNetworkInfo The new network information.
233 void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
236 * Adjusting system clock.
237 * @param aDeltaMilliseconds The difference compared with current system clock.
239 void AdjustSystemClock(int64_t aDeltaMilliseconds);
242 * Set timezone
243 * @param aTimezoneSpec The definition can be found in
244 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
246 void SetTimezone(const nsCString& aTimezoneSpec);
249 * Get timezone
250 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
252 nsCString GetTimezone();
255 * Get timezone offset
256 * returns the timezone offset relative to UTC in minutes (DST effect included)
258 int32_t GetTimezoneOffset();
261 * Register observer for system clock changed notification.
262 * @param aObserver The observer that should be added.
264 void RegisterSystemClockChangeObserver(
265 hal::SystemClockChangeObserver* aObserver);
268 * Unregister the observer for system clock changed.
269 * @param aObserver The observer that should be removed.
271 void UnregisterSystemClockChangeObserver(
272 hal::SystemClockChangeObserver* aObserver);
275 * Notify of a change in the system clock.
276 * @param aClockDeltaMS
278 void NotifySystemClockChange(const int64_t& aClockDeltaMS);
281 * Register observer for system timezone changed notification.
282 * @param aObserver The observer that should be added.
284 void RegisterSystemTimezoneChangeObserver(
285 hal::SystemTimezoneChangeObserver* aObserver);
288 * Unregister the observer for system timezone changed.
289 * @param aObserver The observer that should be removed.
291 void UnregisterSystemTimezoneChangeObserver(
292 hal::SystemTimezoneChangeObserver* aObserver);
295 * Notify of a change in the system timezone.
296 * @param aSystemTimezoneChangeInfo
298 void NotifySystemTimezoneChange(
299 const hal::SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo);
302 * Reboot the device.
304 * This API is currently only allowed to be used from the main process.
306 void Reboot();
309 * Power off the device.
311 * This API is currently only allowed to be used from the main process.
313 void PowerOff();
316 * Enable wake lock notifications from the backend.
318 * This method is only used by WakeLockObserversManager.
320 void EnableWakeLockNotifications();
323 * Disable wake lock notifications from the backend.
325 * This method is only used by WakeLockObserversManager.
327 void DisableWakeLockNotifications();
330 * Inform the wake lock backend there is a new wake lock observer.
331 * @param aWakeLockObserver The observer that should be added.
333 void RegisterWakeLockObserver(WakeLockObserver* aObserver);
336 * Inform the wake lock backend a wake lock observer unregistered.
337 * @param aWakeLockObserver The observer that should be removed.
339 void UnregisterWakeLockObserver(WakeLockObserver* aObserver);
342 * Adjust a wake lock's counts on behalf of a given process.
344 * In most cases, you shouldn't need to pass the aProcessID argument; the
345 * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
347 * @param aTopic lock topic
348 * @param aLockAdjust to increase or decrease active locks
349 * @param aHiddenAdjust to increase or decrease hidden locks
350 * @param aProcessID indicates which process we're modifying the wake lock
351 * on behalf of. It is interpreted as
353 * CONTENT_PROCESS_ID_UNKNOWN: The current process
354 * CONTENT_PROCESS_ID_MAIN: The root process
355 * X: The process with ContentChild::GetID() == X
357 void ModifyWakeLock(const nsAString &aTopic,
358 hal::WakeLockControl aLockAdjust,
359 hal::WakeLockControl aHiddenAdjust,
360 uint64_t aProcessID = hal::CONTENT_PROCESS_ID_UNKNOWN);
363 * Query the wake lock numbers of aTopic.
364 * @param aTopic lock topic
365 * @param aWakeLockInfo wake lock numbers
367 void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLockInfo);
370 * Notify of a change in the wake lock state.
371 * @param aWakeLockInfo The new wake lock information.
373 void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
376 * Inform the backend there is a new screen configuration observer.
377 * @param aScreenConfigurationObserver The observer that should be added.
379 void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
382 * Inform the backend a screen configuration observer unregistered.
383 * @param aScreenConfigurationObserver The observer that should be removed.
385 void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
388 * Returns the current screen configuration.
390 void GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration);
393 * Notify of a change in the screen configuration.
394 * @param aScreenConfiguration The new screen orientation.
396 void NotifyScreenConfigurationChange(const hal::ScreenConfiguration& aScreenConfiguration);
399 * Lock the screen orientation to the specific orientation.
400 * @return Whether the lock has been accepted.
402 bool LockScreenOrientation(const dom::ScreenOrientation& aOrientation);
405 * Unlock the screen orientation.
407 void UnlockScreenOrientation();
410 * Register an observer for the switch of given SwitchDevice.
412 * The observer will receive data whenever the data generated by the
413 * given switch.
415 void RegisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
418 * Unregister an observer for the switch of given SwitchDevice.
420 void UnregisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
423 * Notify the state of the switch.
425 * This API is internal to hal; clients shouldn't call it directly.
427 void NotifySwitchChange(const hal::SwitchEvent& aEvent);
430 * Get current switch information.
432 hal::SwitchState GetCurrentSwitchState(hal::SwitchDevice aDevice);
435 * Notify switch status change from input device.
437 void NotifySwitchStateFromInputDevice(hal::SwitchDevice aDevice,
438 hal::SwitchState aState);
441 * Register an observer that is notified when a programmed alarm
442 * expires.
444 * Currently, there can only be 0 or 1 alarm observers.
446 bool RegisterTheOneAlarmObserver(hal::AlarmObserver* aObserver);
449 * Unregister the alarm observer. Doing so will implicitly cancel any
450 * programmed alarm.
452 void UnregisterTheOneAlarmObserver();
455 * Notify that the programmed alarm has expired.
457 * This API is internal to hal; clients shouldn't call it directly.
459 void NotifyAlarmFired();
462 * Program the real-time clock to expire at the time |aSeconds|,
463 * |aNanoseconds|. These specify a point in real time relative to the
464 * UNIX epoch. The alarm will fire at this time point even if the
465 * real-time clock is changed; that is, this alarm respects changes to
466 * the real-time clock. Return true iff the alarm was programmed.
468 * The alarm can be reprogrammed at any time.
470 * This API is currently only allowed to be used from non-sandboxed
471 * contexts.
473 bool SetAlarm(int32_t aSeconds, int32_t aNanoseconds);
476 * Set the priority of the given process. A process's priority is a two-tuple
477 * consisting of a hal::ProcessPriority value and a hal::ProcessCPUPriority
478 * value.
480 * Two processes with the same ProcessCPUPriority value don't necessarily have
481 * the same CPU priority; the CPU priority we assign to a process is a function
482 * of its ProcessPriority and ProcessCPUPriority.
484 * Exactly what this does will vary between platforms. On *nix we might give
485 * background processes higher nice values. On other platforms, we might
486 * ignore this call entirely.
488 void SetProcessPriority(int aPid,
489 hal::ProcessPriority aPriority,
490 hal::ProcessCPUPriority aCPUPriority,
491 uint32_t aLRU = 0);
495 * Set the current thread's priority to appropriate platform-specific value for
496 * given functionality. Instead of providing arbitrary priority numbers you
497 * must specify a type of function like THREAD_PRIORITY_COMPOSITOR.
499 void SetCurrentThreadPriority(hal::ThreadPriority aThreadPriority);
502 * Register an observer for the FM radio.
504 void RegisterFMRadioObserver(hal::FMRadioObserver* aRadioObserver);
507 * Unregister the observer for the FM radio.
509 void UnregisterFMRadioObserver(hal::FMRadioObserver* aRadioObserver);
512 * Notify observers that a call to EnableFMRadio, DisableFMRadio, or FMRadioSeek
513 * has completed, and indicate what the call returned.
515 void NotifyFMRadioStatus(const hal::FMRadioOperationInformation& aRadioState);
518 * Enable the FM radio and configure it according to the settings in aInfo.
520 void EnableFMRadio(const hal::FMRadioSettings& aInfo);
523 * Disable the FM radio.
525 void DisableFMRadio();
528 * Seek to an available FM radio station.
530 * This can be called off main thread, but all calls must be completed
531 * before calling DisableFMRadio.
533 void FMRadioSeek(const hal::FMRadioSeekDirection& aDirection);
536 * Get the current FM radio settings.
538 void GetFMRadioSettings(hal::FMRadioSettings* aInfo);
541 * Set the FM radio's frequency.
543 * This can be called off main thread, but all calls must be completed
544 * before calling DisableFMRadio.
546 void SetFMRadioFrequency(const uint32_t frequency);
549 * Get the FM radio's frequency.
551 uint32_t GetFMRadioFrequency();
554 * Get FM radio power state
556 bool IsFMRadioOn();
559 * Get FM radio signal strength
561 uint32_t GetFMRadioSignalStrength();
564 * Cancel FM radio seeking
566 void CancelFMRadioSeek();
569 * Get FM radio band settings by country.
571 hal::FMRadioSettings GetFMBandSettings(hal::FMRadioCountry aCountry);
574 * Start a watchdog to compulsively shutdown the system if it hangs.
575 * @param aMode Specify how to shutdown the system.
576 * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
578 * This API is currently only allowed to be used from the main process.
580 void StartForceQuitWatchdog(hal::ShutdownMode aMode, int32_t aTimeoutSecs);
583 * Perform Factory Reset to wipe out all user data.
585 void FactoryReset(mozilla::dom::FactoryResetReason& aReason);
588 * Start monitoring the status of gamepads attached to the system.
590 void StartMonitoringGamepadStatus();
593 * Stop monitoring the status of gamepads attached to the system.
595 void StopMonitoringGamepadStatus();
598 * Start monitoring disk space for low space situations.
600 * This API is currently only allowed to be used from the main process.
602 void StartDiskSpaceWatcher();
605 * Stop monitoring disk space for low space situations.
607 * This API is currently only allowed to be used from the main process.
609 void StopDiskSpaceWatcher();
612 * Get total system memory of device being run on in bytes.
614 * Returns 0 if we are unable to determine this information from /proc/meminfo.
616 uint32_t GetTotalSystemMemory();
619 * Get the level of total system memory on device in MiB.
620 * (round the value up to the next power of two)
622 * Returns 0 if we are unable to determine this information from /proc/meminfo.
624 uint32_t GetTotalSystemMemoryLevel();
627 * Determine whether the headphone switch event is from input device
629 bool IsHeadphoneEventFromInputDev();
631 } // namespace MOZ_HAL_NAMESPACE
632 } // namespace mozilla
634 #ifdef MOZ_DEFINED_HAL_NAMESPACE
635 # undef MOZ_DEFINED_HAL_NAMESPACE
636 # undef MOZ_HAL_NAMESPACE
637 #endif
639 #endif // mozilla_Hal_h