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/dom/ContentParent.h"
20 #include "mozilla/hal_sandbox/PHal.h"
21 #include "mozilla/dom/ScreenOrientation.h"
24 * Hal.h contains the public Hal API.
26 * By default, this file defines its functions in the hal namespace, but if
27 * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace.
29 * This is used by HalImpl.h and HalSandbox.h, which define copies of all the
30 * functions here in the hal_impl and hal_sandbox namespaces.
35 #ifndef MOZ_HAL_NAMESPACE
36 # define MOZ_HAL_NAMESPACE hal
37 # define MOZ_DEFINED_HAL_NAMESPACE 1
47 typedef Observer
<void_t
> AlarmObserver
;
48 typedef Observer
<ScreenConfiguration
> ScreenConfigurationObserver
;
50 class WindowIdentifier
;
52 extern PRLogModuleInfo
*GetHalLog();
53 #define HAL_LOG(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, msg)
55 typedef Observer
<int64_t> SystemClockChangeObserver
;
56 typedef Observer
<SystemTimezoneChangeInformation
> SystemTimezoneChangeObserver
;
60 namespace MOZ_HAL_NAMESPACE
{
63 * Turn the default vibrator device on/off per the pattern specified
64 * by |pattern|. Each element in the pattern is the number of
65 * milliseconds to turn the vibrator on or off. The first element in
66 * |pattern| is an "on" element, the next is "off", and so on.
68 * If |pattern| is empty, any in-progress vibration is canceled.
70 * Only an active window within an active tab may call Vibrate; calls
71 * from inactive windows and windows on inactive tabs do nothing.
73 * If you're calling hal::Vibrate from the outside world, pass an
74 * nsIDOMWindow* in place of the WindowIdentifier parameter.
75 * The method with WindowIdentifier will be called automatically.
77 void Vibrate(const nsTArray
<uint32_t>& pattern
,
78 nsIDOMWindow
* aWindow
);
79 void Vibrate(const nsTArray
<uint32_t>& pattern
,
80 const hal::WindowIdentifier
&id
);
83 * Cancel a vibration started by the content window identified by
86 * If the window was the last window to start a vibration, the
87 * cancellation request will go through even if the window is not
90 * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside
91 * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called
94 void CancelVibrate(nsIDOMWindow
* aWindow
);
95 void CancelVibrate(const hal::WindowIdentifier
&id
);
98 * Inform the battery backend there is a new battery observer.
99 * @param aBatteryObserver The observer that should be added.
101 void RegisterBatteryObserver(BatteryObserver
* aBatteryObserver
);
104 * Inform the battery backend a battery observer unregistered.
105 * @param aBatteryObserver The observer that should be removed.
107 void UnregisterBatteryObserver(BatteryObserver
* aBatteryObserver
);
110 * Returns the current battery information.
112 void GetCurrentBatteryInformation(hal::BatteryInformation
* aBatteryInfo
);
115 * Notify of a change in the battery state.
116 * @param aBatteryInfo The new battery information.
118 void NotifyBatteryChange(const hal::BatteryInformation
& aBatteryInfo
);
121 * Determine whether the device's screen is currently enabled.
123 bool GetScreenEnabled();
126 * Enable or disable the device's screen.
128 * Note that it may take a few seconds for the screen to turn on or off.
130 void SetScreenEnabled(bool enabled
);
133 * Get the brightness of the device's screen's backlight, on a scale from 0
134 * (very dim) to 1 (full blast).
136 * If the display is currently disabled, this returns the brightness the
137 * backlight will have when the display is re-enabled.
139 double GetScreenBrightness();
142 * Set the brightness of the device's screen's backlight, on a scale from 0
143 * (very dimm) to 1 (full blast). Values larger than 1 are treated like 1, and
144 * values smaller than 0 are treated like 0.
146 * Note that we may reduce the resolution of the given brightness value before
147 * sending it to the screen. Therefore if you call SetScreenBrightness(x)
148 * followed by GetScreenBrightness(), the value returned by
149 * GetScreenBrightness() may not be exactly x.
151 void SetScreenBrightness(double brightness
);
154 * Determine whether the device is allowed to sleep.
156 bool GetCpuSleepAllowed();
159 * Set whether the device is allowed to suspend automatically after
160 * the screen is disabled.
162 void SetCpuSleepAllowed(bool allowed
);
165 * Set the value of a light to a particular color, with a specific flash pattern.
166 * light specifices which light. See Hal.idl for the list of constants
167 * mode specifies user set or based on ambient light sensor
168 * flash specifies whether or how to flash the light
169 * flashOnMS and flashOffMS specify the pattern for XXX flash mode
170 * color specifies the color. If the light doesn't support color, the given color is
171 * transformed into a brightness, or just an on/off if that is all the light is capable of.
172 * returns true if successful and false if failed.
174 bool SetLight(hal::LightType light
, const hal::LightConfiguration
& aConfig
);
176 * GET the value of a light returning a particular color, with a specific flash pattern.
177 * returns true if successful and false if failed.
179 bool GetLight(hal::LightType light
, hal::LightConfiguration
* aConfig
);
183 * Register an observer for the sensor of given type.
185 * The observer will receive data whenever the data generated by the
186 * sensor is avaiable.
188 void RegisterSensorObserver(hal::SensorType aSensor
,
189 hal::ISensorObserver
*aObserver
);
192 * Unregister an observer for the sensor of given type.
194 void UnregisterSensorObserver(hal::SensorType aSensor
,
195 hal::ISensorObserver
*aObserver
);
198 * Post a value generated by a sensor.
200 * This API is internal to hal; clients shouldn't call it directly.
202 void NotifySensorChange(const hal::SensorData
&aSensorData
);
205 * Enable sensor notifications from the backend
207 * This method is only visible from implementation of sensor manager.
208 * Rest of the system should not try this.
210 void EnableSensorNotifications(hal::SensorType aSensor
);
213 * Disable sensor notifications from the backend
215 * This method is only visible from implementation of sensor manager.
216 * Rest of the system should not try this.
218 void DisableSensorNotifications(hal::SensorType aSensor
);
222 * Inform the network backend there is a new network observer.
223 * @param aNetworkObserver The observer that should be added.
225 void RegisterNetworkObserver(NetworkObserver
* aNetworkObserver
);
228 * Inform the network backend a network observer unregistered.
229 * @param aNetworkObserver The observer that should be removed.
231 void UnregisterNetworkObserver(NetworkObserver
* aNetworkObserver
);
234 * Returns the current network information.
236 void GetCurrentNetworkInformation(hal::NetworkInformation
* aNetworkInfo
);
239 * Notify of a change in the network state.
240 * @param aNetworkInfo The new network information.
242 void NotifyNetworkChange(const hal::NetworkInformation
& aNetworkInfo
);
245 * Adjusting system clock.
246 * @param aDeltaMilliseconds The difference compared with current system clock.
248 void AdjustSystemClock(int64_t aDeltaMilliseconds
);
252 * @param aTimezoneSpec The definition can be found in
253 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
255 void SetTimezone(const nsCString
& aTimezoneSpec
);
259 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
261 nsCString
GetTimezone();
264 * Register observer for system clock changed notification.
265 * @param aObserver The observer that should be added.
267 void RegisterSystemClockChangeObserver(
268 hal::SystemClockChangeObserver
* aObserver
);
271 * Unregister the observer for system clock changed.
272 * @param aObserver The observer that should be removed.
274 void UnregisterSystemClockChangeObserver(
275 hal::SystemClockChangeObserver
* aObserver
);
278 * Notify of a change in the system clock.
279 * @param aClockDeltaMS
281 void NotifySystemClockChange(const int64_t& aClockDeltaMS
);
284 * Register observer for system timezone changed notification.
285 * @param aObserver The observer that should be added.
287 void RegisterSystemTimezoneChangeObserver(
288 hal::SystemTimezoneChangeObserver
* aObserver
);
291 * Unregister the observer for system timezone changed.
292 * @param aObserver The observer that should be removed.
294 void UnregisterSystemTimezoneChangeObserver(
295 hal::SystemTimezoneChangeObserver
* aObserver
);
298 * Notify of a change in the system timezone.
299 * @param aSystemTimezoneChangeInfo
301 void NotifySystemTimezoneChange(
302 const hal::SystemTimezoneChangeInformation
& aSystemTimezoneChangeInfo
);
307 * This API is currently only allowed to be used from the main process.
312 * Power off the device.
314 * This API is currently only allowed to be used from the main process.
319 * Enable wake lock notifications from the backend.
321 * This method is only used by WakeLockObserversManager.
323 void EnableWakeLockNotifications();
326 * Disable wake lock notifications from the backend.
328 * This method is only used by WakeLockObserversManager.
330 void DisableWakeLockNotifications();
333 * Inform the wake lock backend there is a new wake lock observer.
334 * @param aWakeLockObserver The observer that should be added.
336 void RegisterWakeLockObserver(WakeLockObserver
* aObserver
);
339 * Inform the wake lock backend a wake lock observer unregistered.
340 * @param aWakeLockObserver The observer that should be removed.
342 void UnregisterWakeLockObserver(WakeLockObserver
* aObserver
);
345 * Adjust a wake lock's counts on behalf of a given process.
347 * In most cases, you shouldn't need to pass the aProcessID argument; the
348 * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
350 * @param aTopic lock topic
351 * @param aLockAdjust to increase or decrease active locks
352 * @param aHiddenAdjust to increase or decrease hidden locks
353 * @param aProcessID indicates which process we're modifying the wake lock
354 * on behalf of. It is interpreted as
356 * CONTENT_PROCESS_ID_UNKNOWN: The current process
357 * CONTENT_PROCESS_ID_MAIN: The root process
358 * X: The process with ContentChild::GetID() == X
360 void ModifyWakeLock(const nsAString
&aTopic
,
361 hal::WakeLockControl aLockAdjust
,
362 hal::WakeLockControl aHiddenAdjust
,
363 uint64_t aProcessID
= hal::CONTENT_PROCESS_ID_UNKNOWN
);
366 * Query the wake lock numbers of aTopic.
367 * @param aTopic lock topic
368 * @param aWakeLockInfo wake lock numbers
370 void GetWakeLockInfo(const nsAString
&aTopic
, hal::WakeLockInformation
*aWakeLockInfo
);
373 * Notify of a change in the wake lock state.
374 * @param aWakeLockInfo The new wake lock information.
376 void NotifyWakeLockChange(const hal::WakeLockInformation
& aWakeLockInfo
);
379 * Inform the backend there is a new screen configuration observer.
380 * @param aScreenConfigurationObserver The observer that should be added.
382 void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver
* aScreenConfigurationObserver
);
385 * Inform the backend a screen configuration observer unregistered.
386 * @param aScreenConfigurationObserver The observer that should be removed.
388 void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver
* aScreenConfigurationObserver
);
391 * Returns the current screen configuration.
393 void GetCurrentScreenConfiguration(hal::ScreenConfiguration
* aScreenConfiguration
);
396 * Notify of a change in the screen configuration.
397 * @param aScreenConfiguration The new screen orientation.
399 void NotifyScreenConfigurationChange(const hal::ScreenConfiguration
& aScreenConfiguration
);
402 * Lock the screen orientation to the specific orientation.
403 * @return Whether the lock has been accepted.
405 bool LockScreenOrientation(const dom::ScreenOrientation
& aOrientation
);
408 * Unlock the screen orientation.
410 void UnlockScreenOrientation();
413 * Register an observer for the switch of given SwitchDevice.
415 * The observer will receive data whenever the data generated by the
418 void RegisterSwitchObserver(hal::SwitchDevice aDevice
, hal::SwitchObserver
*aSwitchObserver
);
421 * Unregister an observer for the switch of given SwitchDevice.
423 void UnregisterSwitchObserver(hal::SwitchDevice aDevice
, hal::SwitchObserver
*aSwitchObserver
);
426 * Notify the state of the switch.
428 * This API is internal to hal; clients shouldn't call it directly.
430 void NotifySwitchChange(const hal::SwitchEvent
& aEvent
);
433 * Get current switch information.
435 hal::SwitchState
GetCurrentSwitchState(hal::SwitchDevice aDevice
);
438 * Register an observer that is notified when a programmed alarm
441 * Currently, there can only be 0 or 1 alarm observers.
443 bool RegisterTheOneAlarmObserver(hal::AlarmObserver
* aObserver
);
446 * Unregister the alarm observer. Doing so will implicitly cancel any
449 void UnregisterTheOneAlarmObserver();
452 * Notify that the programmed alarm has expired.
454 * This API is internal to hal; clients shouldn't call it directly.
456 void NotifyAlarmFired();
459 * Program the real-time clock to expire at the time |aSeconds|,
460 * |aNanoseconds|. These specify a point in real time relative to the
461 * UNIX epoch. The alarm will fire at this time point even if the
462 * real-time clock is changed; that is, this alarm respects changes to
463 * the real-time clock. Return true iff the alarm was programmed.
465 * The alarm can be reprogrammed at any time.
467 * This API is currently only allowed to be used from non-sandboxed
470 bool SetAlarm(int32_t aSeconds
, int32_t aNanoseconds
);
473 * Set the priority of the given process. A process's priority is a two-tuple
474 * consisting of a hal::ProcessPriority value and a hal::ProcessCPUPriority
477 * Two processes with the same ProcessCPUPriority value don't necessarily have
478 * the same CPU priority; the CPU priority we assign to a process is a function
479 * of its ProcessPriority and ProcessCPUPriority.
481 * Exactly what this does will vary between platforms. On *nix we might give
482 * background processes higher nice values. On other platforms, we might
483 * ignore this call entirely.
485 void SetProcessPriority(int aPid
,
486 hal::ProcessPriority aPriority
,
487 hal::ProcessCPUPriority aCPUPriority
);
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 * Notify observers that a call to EnableFMRadio, DisableFMRadio, or FMRadioSeek
501 * has completed, and indicate what the call returned.
503 void NotifyFMRadioStatus(const hal::FMRadioOperationInformation
& aRadioState
);
506 * Enable the FM radio and configure it according to the settings in aInfo.
508 void EnableFMRadio(const hal::FMRadioSettings
& aInfo
);
511 * Disable the FM radio.
513 void DisableFMRadio();
516 * Seek to an available FM radio station.
519 void FMRadioSeek(const hal::FMRadioSeekDirection
& aDirection
);
522 * Get the current FM radio settings.
524 void GetFMRadioSettings(hal::FMRadioSettings
* aInfo
);
527 * Set the FM radio's frequency.
529 void SetFMRadioFrequency(const uint32_t frequency
);
532 * Get the FM radio's frequency.
534 uint32_t GetFMRadioFrequency();
537 * Get FM radio power state
542 * Get FM radio signal strength
544 uint32_t GetFMRadioSignalStrength();
547 * Cancel FM radio seeking
549 void CancelFMRadioSeek();
552 * Get FM radio band settings by country.
554 hal::FMRadioSettings
GetFMBandSettings(hal::FMRadioCountry aCountry
);
557 * Start a watchdog to compulsively shutdown the system if it hangs.
558 * @param aMode Specify how to shutdown the system.
559 * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
561 * This API is currently only allowed to be used from the main process.
563 void StartForceQuitWatchdog(hal::ShutdownMode aMode
, int32_t aTimeoutSecs
);
566 * Perform Factory Reset to wipe out all user data.
571 * Start monitoring the status of gamepads attached to the system.
573 void StartMonitoringGamepadStatus();
576 * Stop monitoring the status of gamepads attached to the system.
578 void StopMonitoringGamepadStatus();
581 * Start monitoring disk space for low space situations.
583 * This API is currently only allowed to be used from the main process.
585 void StartDiskSpaceWatcher();
588 * Stop monitoring disk space for low space situations.
590 * This API is currently only allowed to be used from the main process.
592 void StopDiskSpaceWatcher();
594 } // namespace MOZ_HAL_NAMESPACE
595 } // namespace mozilla
597 #ifdef MOZ_DEFINED_HAL_NAMESPACE
598 # undef MOZ_DEFINED_HAL_NAMESPACE
599 # undef MOZ_HAL_NAMESPACE
602 #endif // mozilla_Hal_h