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"
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 extern PRLogModuleInfo
*GetHalLog();
50 #define HAL_LOG(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, msg)
52 typedef Observer
<int64_t> SystemClockChangeObserver
;
53 typedef Observer
<SystemTimezoneChangeInformation
> SystemTimezoneChangeObserver
;
57 namespace MOZ_HAL_NAMESPACE
{
60 * Turn the default vibrator device on/off per the pattern specified
61 * by |pattern|. Each element in the pattern is the number of
62 * milliseconds to turn the vibrator on or off. The first element in
63 * |pattern| is an "on" element, the next is "off", and so on.
65 * If |pattern| is empty, any in-progress vibration is canceled.
67 * Only an active window within an active tab may call Vibrate; calls
68 * from inactive windows and windows on inactive tabs do nothing.
70 * If you're calling hal::Vibrate from the outside world, pass an
71 * nsIDOMWindow* in place of the WindowIdentifier parameter.
72 * The method with WindowIdentifier will be called automatically.
74 void Vibrate(const nsTArray
<uint32_t>& pattern
,
75 nsIDOMWindow
* aWindow
);
76 void Vibrate(const nsTArray
<uint32_t>& pattern
,
77 const hal::WindowIdentifier
&id
);
80 * Cancel a vibration started by the content window identified by
83 * If the window was the last window to start a vibration, the
84 * cancellation request will go through even if the window is not
87 * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside
88 * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called
91 void CancelVibrate(nsIDOMWindow
* aWindow
);
92 void CancelVibrate(const hal::WindowIdentifier
&id
);
95 * Inform the battery backend there is a new battery observer.
96 * @param aBatteryObserver The observer that should be added.
98 void RegisterBatteryObserver(BatteryObserver
* aBatteryObserver
);
101 * Inform the battery backend a battery observer unregistered.
102 * @param aBatteryObserver The observer that should be removed.
104 void UnregisterBatteryObserver(BatteryObserver
* aBatteryObserver
);
107 * Returns the current battery information.
109 void GetCurrentBatteryInformation(hal::BatteryInformation
* aBatteryInfo
);
112 * Notify of a change in the battery state.
113 * @param aBatteryInfo The new battery information.
115 void NotifyBatteryChange(const hal::BatteryInformation
& aBatteryInfo
);
118 * Determine whether the device's screen is currently enabled.
120 bool GetScreenEnabled();
123 * Enable or disable the device's screen.
125 * Note that it may take a few seconds for the screen to turn on or off.
127 void SetScreenEnabled(bool enabled
);
130 * Get the brightness of the device's screen's backlight, on a scale from 0
131 * (very dim) to 1 (full blast).
133 * If the display is currently disabled, this returns the brightness the
134 * backlight will have when the display is re-enabled.
136 double GetScreenBrightness();
139 * Set the brightness of the device's screen's backlight, on a scale from 0
140 * (very dimm) to 1 (full blast). Values larger than 1 are treated like 1, and
141 * values smaller than 0 are treated like 0.
143 * Note that we may reduce the resolution of the given brightness value before
144 * sending it to the screen. Therefore if you call SetScreenBrightness(x)
145 * followed by GetScreenBrightness(), the value returned by
146 * GetScreenBrightness() may not be exactly x.
148 void SetScreenBrightness(double brightness
);
151 * Determine whether the device is allowed to sleep.
153 bool GetCpuSleepAllowed();
156 * Set whether the device is allowed to suspend automatically after
157 * the screen is disabled.
159 void SetCpuSleepAllowed(bool allowed
);
162 * Set the value of a light to a particular color, with a specific flash pattern.
163 * light specifices which light. See Hal.idl for the list of constants
164 * mode specifies user set or based on ambient light sensor
165 * flash specifies whether or how to flash the light
166 * flashOnMS and flashOffMS specify the pattern for XXX flash mode
167 * color specifies the color. If the light doesn't support color, the given color is
168 * transformed into a brightness, or just an on/off if that is all the light is capable of.
169 * returns true if successful and false if failed.
171 bool SetLight(hal::LightType light
, const hal::LightConfiguration
& aConfig
);
173 * GET the value of a light returning a particular color, with a specific flash pattern.
174 * returns true if successful and false if failed.
176 bool GetLight(hal::LightType light
, hal::LightConfiguration
* aConfig
);
180 * Register an observer for the sensor of given type.
182 * The observer will receive data whenever the data generated by the
183 * sensor is avaiable.
185 void RegisterSensorObserver(hal::SensorType aSensor
,
186 hal::ISensorObserver
*aObserver
);
189 * Unregister an observer for the sensor of given type.
191 void UnregisterSensorObserver(hal::SensorType aSensor
,
192 hal::ISensorObserver
*aObserver
);
195 * Post a value generated by a sensor.
197 * This API is internal to hal; clients shouldn't call it directly.
199 void NotifySensorChange(const hal::SensorData
&aSensorData
);
202 * Enable sensor notifications from the backend
204 * This method is only visible from implementation of sensor manager.
205 * Rest of the system should not try this.
207 void EnableSensorNotifications(hal::SensorType aSensor
);
210 * Disable sensor notifications from the backend
212 * This method is only visible from implementation of sensor manager.
213 * Rest of the system should not try this.
215 void DisableSensorNotifications(hal::SensorType aSensor
);
219 * Inform the network backend there is a new network observer.
220 * @param aNetworkObserver The observer that should be added.
222 void RegisterNetworkObserver(NetworkObserver
* aNetworkObserver
);
225 * Inform the network backend a network observer unregistered.
226 * @param aNetworkObserver The observer that should be removed.
228 void UnregisterNetworkObserver(NetworkObserver
* aNetworkObserver
);
231 * Returns the current network information.
233 void GetCurrentNetworkInformation(hal::NetworkInformation
* aNetworkInfo
);
236 * Notify of a change in the network state.
237 * @param aNetworkInfo The new network information.
239 void NotifyNetworkChange(const hal::NetworkInformation
& aNetworkInfo
);
242 * Adjusting system clock.
243 * @param aDeltaMilliseconds The difference compared with current system clock.
245 void AdjustSystemClock(int64_t aDeltaMilliseconds
);
249 * @param aTimezoneSpec The definition can be found in
250 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
252 void SetTimezone(const nsCString
& aTimezoneSpec
);
256 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
258 nsCString
GetTimezone();
261 * Get timezone offset
262 * returns the timezone offset relative to UTC in minutes (DST effect included)
264 int32_t GetTimezoneOffset();
267 * Register observer for system clock changed notification.
268 * @param aObserver The observer that should be added.
270 void RegisterSystemClockChangeObserver(
271 hal::SystemClockChangeObserver
* aObserver
);
274 * Unregister the observer for system clock changed.
275 * @param aObserver The observer that should be removed.
277 void UnregisterSystemClockChangeObserver(
278 hal::SystemClockChangeObserver
* aObserver
);
281 * Notify of a change in the system clock.
282 * @param aClockDeltaMS
284 void NotifySystemClockChange(const int64_t& aClockDeltaMS
);
287 * Register observer for system timezone changed notification.
288 * @param aObserver The observer that should be added.
290 void RegisterSystemTimezoneChangeObserver(
291 hal::SystemTimezoneChangeObserver
* aObserver
);
294 * Unregister the observer for system timezone changed.
295 * @param aObserver The observer that should be removed.
297 void UnregisterSystemTimezoneChangeObserver(
298 hal::SystemTimezoneChangeObserver
* aObserver
);
301 * Notify of a change in the system timezone.
302 * @param aSystemTimezoneChangeInfo
304 void NotifySystemTimezoneChange(
305 const hal::SystemTimezoneChangeInformation
& aSystemTimezoneChangeInfo
);
310 * This API is currently only allowed to be used from the main process.
315 * Power off the device.
317 * This API is currently only allowed to be used from the main process.
322 * Enable wake lock notifications from the backend.
324 * This method is only used by WakeLockObserversManager.
326 void EnableWakeLockNotifications();
329 * Disable wake lock notifications from the backend.
331 * This method is only used by WakeLockObserversManager.
333 void DisableWakeLockNotifications();
336 * Inform the wake lock backend there is a new wake lock observer.
337 * @param aWakeLockObserver The observer that should be added.
339 void RegisterWakeLockObserver(WakeLockObserver
* aObserver
);
342 * Inform the wake lock backend a wake lock observer unregistered.
343 * @param aWakeLockObserver The observer that should be removed.
345 void UnregisterWakeLockObserver(WakeLockObserver
* aObserver
);
348 * Adjust a wake lock's counts on behalf of a given process.
350 * In most cases, you shouldn't need to pass the aProcessID argument; the
351 * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
353 * @param aTopic lock topic
354 * @param aLockAdjust to increase or decrease active locks
355 * @param aHiddenAdjust to increase or decrease hidden locks
356 * @param aProcessID indicates which process we're modifying the wake lock
357 * on behalf of. It is interpreted as
359 * CONTENT_PROCESS_ID_UNKNOWN: The current process
360 * CONTENT_PROCESS_ID_MAIN: The root process
361 * X: The process with ContentChild::GetID() == X
363 void ModifyWakeLock(const nsAString
&aTopic
,
364 hal::WakeLockControl aLockAdjust
,
365 hal::WakeLockControl aHiddenAdjust
,
366 uint64_t aProcessID
= hal::CONTENT_PROCESS_ID_UNKNOWN
);
369 * Query the wake lock numbers of aTopic.
370 * @param aTopic lock topic
371 * @param aWakeLockInfo wake lock numbers
373 void GetWakeLockInfo(const nsAString
&aTopic
, hal::WakeLockInformation
*aWakeLockInfo
);
376 * Notify of a change in the wake lock state.
377 * @param aWakeLockInfo The new wake lock information.
379 void NotifyWakeLockChange(const hal::WakeLockInformation
& aWakeLockInfo
);
382 * Inform the backend there is a new screen configuration observer.
383 * @param aScreenConfigurationObserver The observer that should be added.
385 void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver
* aScreenConfigurationObserver
);
388 * Inform the backend a screen configuration observer unregistered.
389 * @param aScreenConfigurationObserver The observer that should be removed.
391 void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver
* aScreenConfigurationObserver
);
394 * Returns the current screen configuration.
396 void GetCurrentScreenConfiguration(hal::ScreenConfiguration
* aScreenConfiguration
);
399 * Notify of a change in the screen configuration.
400 * @param aScreenConfiguration The new screen orientation.
402 void NotifyScreenConfigurationChange(const hal::ScreenConfiguration
& aScreenConfiguration
);
405 * Lock the screen orientation to the specific orientation.
406 * @return Whether the lock has been accepted.
408 bool LockScreenOrientation(const dom::ScreenOrientation
& aOrientation
);
411 * Unlock the screen orientation.
413 void UnlockScreenOrientation();
416 * Register an observer for the switch of given SwitchDevice.
418 * The observer will receive data whenever the data generated by the
421 void RegisterSwitchObserver(hal::SwitchDevice aDevice
, hal::SwitchObserver
*aSwitchObserver
);
424 * Unregister an observer for the switch of given SwitchDevice.
426 void UnregisterSwitchObserver(hal::SwitchDevice aDevice
, hal::SwitchObserver
*aSwitchObserver
);
429 * Notify the state of the switch.
431 * This API is internal to hal; clients shouldn't call it directly.
433 void NotifySwitchChange(const hal::SwitchEvent
& aEvent
);
436 * Get current switch information.
438 hal::SwitchState
GetCurrentSwitchState(hal::SwitchDevice aDevice
);
441 * Notify switch status change from input device.
443 void NotifySwitchStateFromInputDevice(hal::SwitchDevice aDevice
,
444 hal::SwitchState aState
);
447 * Register an observer that is notified when a programmed alarm
450 * Currently, there can only be 0 or 1 alarm observers.
452 bool RegisterTheOneAlarmObserver(hal::AlarmObserver
* aObserver
);
455 * Unregister the alarm observer. Doing so will implicitly cancel any
458 void UnregisterTheOneAlarmObserver();
461 * Notify that the programmed alarm has expired.
463 * This API is internal to hal; clients shouldn't call it directly.
465 void NotifyAlarmFired();
468 * Program the real-time clock to expire at the time |aSeconds|,
469 * |aNanoseconds|. These specify a point in real time relative to the
470 * UNIX epoch. The alarm will fire at this time point even if the
471 * real-time clock is changed; that is, this alarm respects changes to
472 * the real-time clock. Return true iff the alarm was programmed.
474 * The alarm can be reprogrammed at any time.
476 * This API is currently only allowed to be used from non-sandboxed
479 bool SetAlarm(int32_t aSeconds
, int32_t aNanoseconds
);
482 * Set the priority of the given process. A process's priority is a two-tuple
483 * consisting of a hal::ProcessPriority value and a hal::ProcessCPUPriority
486 * Two processes with the same ProcessCPUPriority value don't necessarily have
487 * the same CPU priority; the CPU priority we assign to a process is a function
488 * of its ProcessPriority and ProcessCPUPriority.
490 * Exactly what this does will vary between platforms. On *nix we might give
491 * background processes higher nice values. On other platforms, we might
492 * ignore this call entirely.
494 void SetProcessPriority(int aPid
,
495 hal::ProcessPriority aPriority
,
496 hal::ProcessCPUPriority aCPUPriority
,
500 * Register an observer for the FM radio.
502 void RegisterFMRadioObserver(hal::FMRadioObserver
* aRadioObserver
);
505 * Unregister the observer for the FM radio.
507 void UnregisterFMRadioObserver(hal::FMRadioObserver
* aRadioObserver
);
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 * Enable the FM radio and configure it according to the settings in aInfo.
518 void EnableFMRadio(const hal::FMRadioSettings
& aInfo
);
521 * Disable the FM radio.
523 void DisableFMRadio();
526 * Seek to an available FM radio station.
529 void FMRadioSeek(const hal::FMRadioSeekDirection
& aDirection
);
532 * Get the current FM radio settings.
534 void GetFMRadioSettings(hal::FMRadioSettings
* aInfo
);
537 * Set the FM radio's frequency.
539 void SetFMRadioFrequency(const uint32_t frequency
);
542 * Get the FM radio's frequency.
544 uint32_t GetFMRadioFrequency();
547 * Get FM radio power state
552 * Get FM radio signal strength
554 uint32_t GetFMRadioSignalStrength();
557 * Cancel FM radio seeking
559 void CancelFMRadioSeek();
562 * Get FM radio band settings by country.
564 hal::FMRadioSettings
GetFMBandSettings(hal::FMRadioCountry aCountry
);
567 * Start a watchdog to compulsively shutdown the system if it hangs.
568 * @param aMode Specify how to shutdown the system.
569 * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
571 * This API is currently only allowed to be used from the main process.
573 void StartForceQuitWatchdog(hal::ShutdownMode aMode
, int32_t aTimeoutSecs
);
576 * Perform Factory Reset to wipe out all user data.
581 * Start monitoring the status of gamepads attached to the system.
583 void StartMonitoringGamepadStatus();
586 * Stop monitoring the status of gamepads attached to the system.
588 void StopMonitoringGamepadStatus();
591 * Start monitoring disk space for low space situations.
593 * This API is currently only allowed to be used from the main process.
595 void StartDiskSpaceWatcher();
598 * Stop monitoring disk space for low space situations.
600 * This API is currently only allowed to be used from the main process.
602 void StopDiskSpaceWatcher();
605 * Get total system memory of device being run on in bytes.
607 * Returns 0 if we are unable to determine this information from /proc/meminfo.
609 uint32_t GetTotalSystemMemory();
611 } // namespace MOZ_HAL_NAMESPACE
612 } // namespace mozilla
614 #ifdef MOZ_DEFINED_HAL_NAMESPACE
615 # undef MOZ_DEFINED_HAL_NAMESPACE
616 # undef MOZ_HAL_NAMESPACE
619 #endif // mozilla_Hal_h