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/. */
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"
16 #include "mozilla/dom/MozPowerManagerBinding.h"
17 #include "mozilla/dom/battery/Types.h"
18 #include "mozilla/dom/network/Types.h"
19 #include "mozilla/dom/power/Types.h"
20 #include "mozilla/hal_sandbox/PHal.h"
21 #include "mozilla/dom/ScreenOrientation.h"
22 #include "mozilla/HalScreenConfiguration.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.
36 #ifndef MOZ_HAL_NAMESPACE
37 # define MOZ_HAL_NAMESPACE hal
38 # define MOZ_DEFINED_HAL_NAMESPACE 1
45 typedef Observer
<void_t
> AlarmObserver
;
47 class WindowIdentifier
;
49 typedef Observer
<int64_t> SystemClockChangeObserver
;
50 typedef Observer
<SystemTimezoneChangeInformation
> SystemTimezoneChangeObserver
;
54 namespace MOZ_HAL_NAMESPACE
{
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 nsIDOMWindow
* aWindow
);
73 void Vibrate(const nsTArray
<uint32_t>& pattern
,
74 const hal::WindowIdentifier
&id
);
77 * Cancel a vibration started by the content window identified by
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
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
88 void CancelVibrate(nsIDOMWindow
* aWindow
);
89 void CancelVibrate(const hal::WindowIdentifier
&id
);
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
);
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
);
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
);
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
);
299 * This API is currently only allowed to be used from the main process.
304 * Power off the device.
306 * This API is currently only allowed to be used from the main process.
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 bool LockScreenOrientation(const dom::ScreenOrientation
& 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
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
439 * Currently, there can only be 0 or 1 alarm observers.
441 bool RegisterTheOneAlarmObserver(hal::AlarmObserver
* aObserver
);
444 * Unregister the alarm observer. Doing so will implicitly cancel any
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
468 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
,
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 * Register an observer for the FM radio.
492 void RegisterFMRadioObserver(hal::FMRadioObserver
* aRadioObserver
);
495 * Unregister the observer for the FM radio.
497 void UnregisterFMRadioObserver(hal::FMRadioObserver
* aRadioObserver
);
500 * Register an observer for the FM radio.
502 void RegisterFMRadioRDSObserver(hal::FMRadioRDSObserver
* aRDSObserver
);
505 * Unregister the observer for the FM radio.
507 void UnregisterFMRadioRDSObserver(hal::FMRadioRDSObserver
* aRDSObserver
);
510 * Notify observers that a call to EnableFMRadio, DisableFMRadio, or FMRadioSeek
511 * has completed, and indicate what the call returned.
513 void NotifyFMRadioStatus(const hal::FMRadioOperationInformation
& aRadioState
);
516 * Notify observers of new RDS data
517 * This can be called on any thread.
519 void NotifyFMRadioRDSGroup(const hal::FMRadioRDSGroup
& aRDSGroup
);
522 * Enable the FM radio and configure it according to the settings in aInfo.
524 void EnableFMRadio(const hal::FMRadioSettings
& aInfo
);
527 * Disable the FM radio.
529 void DisableFMRadio();
532 * Seek to an available FM radio station.
534 * This can be called off main thread, but all calls must be completed
535 * before calling DisableFMRadio.
537 void FMRadioSeek(const hal::FMRadioSeekDirection
& aDirection
);
540 * Get the current FM radio settings.
542 void GetFMRadioSettings(hal::FMRadioSettings
* aInfo
);
545 * Set the FM radio's frequency.
547 * This can be called off main thread, but all calls must be completed
548 * before calling DisableFMRadio.
550 void SetFMRadioFrequency(const uint32_t frequency
);
553 * Get the FM radio's frequency.
555 uint32_t GetFMRadioFrequency();
558 * Get FM radio power state
563 * Get FM radio signal strength
565 uint32_t GetFMRadioSignalStrength();
568 * Cancel FM radio seeking
570 void CancelFMRadioSeek();
573 * Get FM radio band settings by country.
575 hal::FMRadioSettings
GetFMBandSettings(hal::FMRadioCountry aCountry
);
578 * Enable RDS data reception
580 bool EnableRDS(uint32_t aMask
);
583 * Disable RDS data reception
588 * Start a watchdog to compulsively shutdown the system if it hangs.
589 * @param aMode Specify how to shutdown the system.
590 * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
592 * This API is currently only allowed to be used from the main process.
594 void StartForceQuitWatchdog(hal::ShutdownMode aMode
, int32_t aTimeoutSecs
);
597 * Perform Factory Reset to wipe out all user data.
599 void FactoryReset(mozilla::dom::FactoryResetReason
& aReason
);
602 * Start monitoring the status of gamepads attached to the system.
604 void StartMonitoringGamepadStatus();
607 * Stop monitoring the status of gamepads attached to the system.
609 void StopMonitoringGamepadStatus();
612 * Start monitoring disk space for low space situations.
614 * This API is currently only allowed to be used from the main process.
616 void StartDiskSpaceWatcher();
619 * Stop monitoring disk space for low space situations.
621 * This API is currently only allowed to be used from the main process.
623 void StopDiskSpaceWatcher();
626 * Get total system memory of device being run on in bytes.
628 * Returns 0 if we are unable to determine this information from /proc/meminfo.
630 uint32_t GetTotalSystemMemory();
633 * Get the level of total system memory on device in MiB.
634 * (round the value up to the next power of two)
636 * Returns 0 if we are unable to determine this information from /proc/meminfo.
638 uint32_t GetTotalSystemMemoryLevel();
641 * Determine whether the headphone switch event is from input device
643 bool IsHeadphoneEventFromInputDev();
645 } // namespace MOZ_HAL_NAMESPACE
646 } // namespace mozilla
648 #ifdef MOZ_DEFINED_HAL_NAMESPACE
649 # undef MOZ_DEFINED_HAL_NAMESPACE
650 # undef MOZ_HAL_NAMESPACE
653 #endif // mozilla_Hal_h