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/Types.h"
16 #include "mozilla/dom/battery/Types.h"
17 #include "mozilla/dom/network/Types.h"
18 #include "mozilla/dom/power/Types.h"
19 #include "mozilla/hal_sandbox/PHal.h"
20 #include "mozilla/dom/ScreenOrientation.h"
23 * Hal.h contains the public Hal API.
25 * By default, this file defines its functions in the hal namespace, but if
26 * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace.
28 * This is used by HalImpl.h and HalSandbox.h, which define copies of all the
29 * functions here in the hal_impl and hal_sandbox namespaces.
34 #ifndef MOZ_HAL_NAMESPACE
35 # define MOZ_HAL_NAMESPACE hal
36 # define MOZ_DEFINED_HAL_NAMESPACE 1
46 typedef Observer
<void_t
> AlarmObserver
;
47 typedef Observer
<ScreenConfiguration
> ScreenConfigurationObserver
;
49 class WindowIdentifier
;
51 extern PRLogModuleInfo
*GetHalLog();
52 #define HAL_LOG(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, msg)
54 typedef Observer
<int64_t> SystemClockChangeObserver
;
55 typedef Observer
<SystemTimezoneChangeInformation
> SystemTimezoneChangeObserver
;
59 namespace MOZ_HAL_NAMESPACE
{
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
);
82 * Cancel a vibration started by the content window identified by
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
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
93 void CancelVibrate(nsIDOMWindow
* aWindow
);
94 void CancelVibrate(const hal::WindowIdentifier
&id
);
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 enabled
);
132 * Get the brightness of the device's screen's backlight, on a scale from 0
133 * (very dim) to 1 (full blast).
135 * If the display is currently disabled, this returns the brightness the
136 * backlight will have when the display is re-enabled.
138 double GetScreenBrightness();
141 * Set the brightness of the device's screen's backlight, on a scale from 0
142 * (very dimm) to 1 (full blast). Values larger than 1 are treated like 1, and
143 * values smaller than 0 are treated like 0.
145 * Note that we may reduce the resolution of the given brightness value before
146 * sending it to the screen. Therefore if you call SetScreenBrightness(x)
147 * followed by GetScreenBrightness(), the value returned by
148 * GetScreenBrightness() may not be exactly x.
150 void SetScreenBrightness(double brightness
);
153 * Determine whether the device is allowed to sleep.
155 bool GetCpuSleepAllowed();
158 * Set whether the device is allowed to suspend automatically after
159 * the screen is disabled.
161 void SetCpuSleepAllowed(bool allowed
);
164 * Set the value of a light to a particular color, with a specific flash pattern.
165 * light specifices which light. See Hal.idl for the list of constants
166 * mode specifies user set or based on ambient light sensor
167 * flash specifies whether or how to flash the light
168 * flashOnMS and flashOffMS specify the pattern for XXX flash mode
169 * color specifies the color. If the light doesn't support color, the given color is
170 * transformed into a brightness, or just an on/off if that is all the light is capable of.
171 * returns true if successful and false if failed.
173 bool SetLight(hal::LightType light
, const hal::LightConfiguration
& aConfig
);
175 * GET the value of a light returning a particular color, with a specific flash pattern.
176 * returns true if successful and false if failed.
178 bool GetLight(hal::LightType light
, hal::LightConfiguration
* aConfig
);
182 * Register an observer for the sensor of given type.
184 * The observer will receive data whenever the data generated by the
185 * sensor is avaiable.
187 void RegisterSensorObserver(hal::SensorType aSensor
,
188 hal::ISensorObserver
*aObserver
);
191 * Unregister an observer for the sensor of given type.
193 void UnregisterSensorObserver(hal::SensorType aSensor
,
194 hal::ISensorObserver
*aObserver
);
197 * Post a value generated by a sensor.
199 * This API is internal to hal; clients shouldn't call it directly.
201 void NotifySensorChange(const hal::SensorData
&aSensorData
);
204 * Enable 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 EnableSensorNotifications(hal::SensorType aSensor
);
212 * Disable sensor notifications from the backend
214 * This method is only visible from implementation of sensor manager.
215 * Rest of the system should not try this.
217 void DisableSensorNotifications(hal::SensorType aSensor
);
221 * Inform the network backend there is a new network observer.
222 * @param aNetworkObserver The observer that should be added.
224 void RegisterNetworkObserver(NetworkObserver
* aNetworkObserver
);
227 * Inform the network backend a network observer unregistered.
228 * @param aNetworkObserver The observer that should be removed.
230 void UnregisterNetworkObserver(NetworkObserver
* aNetworkObserver
);
233 * Returns the current network information.
235 void GetCurrentNetworkInformation(hal::NetworkInformation
* aNetworkInfo
);
238 * Notify of a change in the network state.
239 * @param aNetworkInfo The new network information.
241 void NotifyNetworkChange(const hal::NetworkInformation
& aNetworkInfo
);
244 * Adjusting system clock.
245 * @param aDeltaMilliseconds The difference compared with current system clock.
247 void AdjustSystemClock(int64_t aDeltaMilliseconds
);
251 * @param aTimezoneSpec The definition can be found in
252 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
254 void SetTimezone(const nsCString
& aTimezoneSpec
);
258 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
260 nsCString
GetTimezone();
263 * Register observer for system clock changed notification.
264 * @param aObserver The observer that should be added.
266 void RegisterSystemClockChangeObserver(
267 hal::SystemClockChangeObserver
* aObserver
);
270 * Unregister the observer for system clock changed.
271 * @param aObserver The observer that should be removed.
273 void UnregisterSystemClockChangeObserver(
274 hal::SystemClockChangeObserver
* aObserver
);
277 * Notify of a change in the system clock.
278 * @param aClockDeltaMS
280 void NotifySystemClockChange(const int64_t& aClockDeltaMS
);
283 * Register observer for system timezone changed notification.
284 * @param aObserver The observer that should be added.
286 void RegisterSystemTimezoneChangeObserver(
287 hal::SystemTimezoneChangeObserver
* aObserver
);
290 * Unregister the observer for system timezone changed.
291 * @param aObserver The observer that should be removed.
293 void UnregisterSystemTimezoneChangeObserver(
294 hal::SystemTimezoneChangeObserver
* aObserver
);
297 * Notify of a change in the system timezone.
298 * @param aSystemTimezoneChangeInfo
300 void NotifySystemTimezoneChange(
301 const hal::SystemTimezoneChangeInformation
& aSystemTimezoneChangeInfo
);
306 * This API is currently only allowed to be used from the main process.
311 * Power off the device.
313 * This API is currently only allowed to be used from the main process.
318 * Enable wake lock notifications from the backend.
320 * This method is only used by WakeLockObserversManager.
322 void EnableWakeLockNotifications();
325 * Disable wake lock notifications from the backend.
327 * This method is only used by WakeLockObserversManager.
329 void DisableWakeLockNotifications();
332 * Inform the wake lock backend there is a new wake lock observer.
333 * @param aWakeLockObserver The observer that should be added.
335 void RegisterWakeLockObserver(WakeLockObserver
* aObserver
);
338 * Inform the wake lock backend a wake lock observer unregistered.
339 * @param aWakeLockObserver The observer that should be removed.
341 void UnregisterWakeLockObserver(WakeLockObserver
* aObserver
);
344 * Adjust a wake lock's counts on behalf of a given process.
346 * In most cases, you shouldn't need to pass the aProcessID argument; the
347 * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
349 * @param aTopic lock topic
350 * @param aLockAdjust to increase or decrease active locks
351 * @param aHiddenAdjust to increase or decrease hidden locks
352 * @param aProcessID indicates which process we're modifying the wake lock
353 * on behalf of. It is interpreted as
355 * CONTENT_PROCESS_ID_UNKNOWN: The current process
356 * CONTENT_PROCESS_ID_MAIN: The root process
357 * X: The process with ContentChild::GetID() == X
359 void ModifyWakeLock(const nsAString
&aTopic
,
360 hal::WakeLockControl aLockAdjust
,
361 hal::WakeLockControl aHiddenAdjust
,
362 uint64_t aProcessID
= hal::CONTENT_PROCESS_ID_UNKNOWN
);
365 * Query the wake lock numbers of aTopic.
366 * @param aTopic lock topic
367 * @param aWakeLockInfo wake lock numbers
369 void GetWakeLockInfo(const nsAString
&aTopic
, hal::WakeLockInformation
*aWakeLockInfo
);
372 * Notify of a change in the wake lock state.
373 * @param aWakeLockInfo The new wake lock information.
375 void NotifyWakeLockChange(const hal::WakeLockInformation
& aWakeLockInfo
);
378 * Inform the backend there is a new screen configuration observer.
379 * @param aScreenConfigurationObserver The observer that should be added.
381 void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver
* aScreenConfigurationObserver
);
384 * Inform the backend a screen configuration observer unregistered.
385 * @param aScreenConfigurationObserver The observer that should be removed.
387 void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver
* aScreenConfigurationObserver
);
390 * Returns the current screen configuration.
392 void GetCurrentScreenConfiguration(hal::ScreenConfiguration
* aScreenConfiguration
);
395 * Notify of a change in the screen configuration.
396 * @param aScreenConfiguration The new screen orientation.
398 void NotifyScreenConfigurationChange(const hal::ScreenConfiguration
& aScreenConfiguration
);
401 * Lock the screen orientation to the specific orientation.
402 * @return Whether the lock has been accepted.
404 bool LockScreenOrientation(const dom::ScreenOrientation
& aOrientation
);
407 * Unlock the screen orientation.
409 void UnlockScreenOrientation();
412 * Register an observer for the switch of given SwitchDevice.
414 * The observer will receive data whenever the data generated by the
417 void RegisterSwitchObserver(hal::SwitchDevice aDevice
, hal::SwitchObserver
*aSwitchObserver
);
420 * Unregister an observer for the switch of given SwitchDevice.
422 void UnregisterSwitchObserver(hal::SwitchDevice aDevice
, hal::SwitchObserver
*aSwitchObserver
);
425 * Notify the state of the switch.
427 * This API is internal to hal; clients shouldn't call it directly.
429 void NotifySwitchChange(const hal::SwitchEvent
& aEvent
);
432 * Get current switch information.
434 hal::SwitchState
GetCurrentSwitchState(hal::SwitchDevice aDevice
);
437 * Register an observer that is notified when a programmed alarm
440 * Currently, there can only be 0 or 1 alarm observers.
442 bool RegisterTheOneAlarmObserver(hal::AlarmObserver
* aObserver
);
445 * Unregister the alarm observer. Doing so will implicitly cancel any
448 void UnregisterTheOneAlarmObserver();
451 * Notify that the programmed alarm has expired.
453 * This API is internal to hal; clients shouldn't call it directly.
455 void NotifyAlarmFired();
458 * Program the real-time clock to expire at the time |aSeconds|,
459 * |aNanoseconds|. These specify a point in real time relative to the
460 * UNIX epoch. The alarm will fire at this time point even if the
461 * real-time clock is changed; that is, this alarm respects changes to
462 * the real-time clock. Return true iff the alarm was programmed.
464 * The alarm can be reprogrammed at any time.
466 * This API is currently only allowed to be used from non-sandboxed
469 bool SetAlarm(int32_t aSeconds
, int32_t aNanoseconds
);
472 * Set the priority of the given process. A process's priority is a two-tuple
473 * consisting of a hal::ProcessPriority value and a hal::ProcessCPUPriority
476 * Two processes with the same ProcessCPUPriority value don't necessarily have
477 * the same CPU priority; the CPU priority we assign to a process is a function
478 * of its ProcessPriority and ProcessCPUPriority.
480 * Exactly what this does will vary between platforms. On *nix we might give
481 * background processes higher nice values. On other platforms, we might
482 * ignore this call entirely.
484 void SetProcessPriority(int aPid
,
485 hal::ProcessPriority aPriority
,
486 hal::ProcessCPUPriority aCPUPriority
);
489 * Register an observer for the FM radio.
491 void RegisterFMRadioObserver(hal::FMRadioObserver
* aRadioObserver
);
494 * Unregister the observer for the FM radio.
496 void UnregisterFMRadioObserver(hal::FMRadioObserver
* aRadioObserver
);
499 * Notify observers that a call to EnableFMRadio, DisableFMRadio, or FMRadioSeek
500 * has completed, and indicate what the call returned.
502 void NotifyFMRadioStatus(const hal::FMRadioOperationInformation
& aRadioState
);
505 * Enable the FM radio and configure it according to the settings in aInfo.
507 void EnableFMRadio(const hal::FMRadioSettings
& aInfo
);
510 * Disable the FM radio.
512 void DisableFMRadio();
515 * Seek to an available FM radio station.
518 void FMRadioSeek(const hal::FMRadioSeekDirection
& aDirection
);
521 * Get the current FM radio settings.
523 void GetFMRadioSettings(hal::FMRadioSettings
* aInfo
);
526 * Set the FM radio's frequency.
528 void SetFMRadioFrequency(const uint32_t frequency
);
531 * Get the FM radio's frequency.
533 uint32_t GetFMRadioFrequency();
536 * Get FM radio power state
541 * Get FM radio signal strength
543 uint32_t GetFMRadioSignalStrength();
546 * Cancel FM radio seeking
548 void CancelFMRadioSeek();
551 * Get FM radio band settings by country.
553 hal::FMRadioSettings
GetFMBandSettings(hal::FMRadioCountry aCountry
);
556 * Start a watchdog to compulsively shutdown the system if it hangs.
557 * @param aMode Specify how to shutdown the system.
558 * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
560 * This API is currently only allowed to be used from the main process.
562 void StartForceQuitWatchdog(hal::ShutdownMode aMode
, int32_t aTimeoutSecs
);
565 * Perform Factory Reset to wipe out all user data.
570 * Start monitoring the status of gamepads attached to the system.
572 void StartMonitoringGamepadStatus();
575 * Stop monitoring the status of gamepads attached to the system.
577 void StopMonitoringGamepadStatus();
580 * Start monitoring disk space for low space situations.
582 * This API is currently only allowed to be used from the main process.
584 void StartDiskSpaceWatcher();
587 * Stop monitoring disk space for low space situations.
589 * This API is currently only allowed to be used from the main process.
591 void StopDiskSpaceWatcher();
593 } // namespace MOZ_HAL_NAMESPACE
594 } // namespace mozilla
596 #ifdef MOZ_DEFINED_HAL_NAMESPACE
597 # undef MOZ_DEFINED_HAL_NAMESPACE
598 # undef MOZ_HAL_NAMESPACE
601 #endif // mozilla_Hal_h