Backed out changeset ad0d9f62c29c (bug 206659) for B2G desktop mochitest orange.
[gecko.git] / hal / Hal.h
blob50932bdcaf301549a85b08e33e5a43ae48f54af4
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/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.
34 class nsIDOMWindow;
36 #ifndef MOZ_HAL_NAMESPACE
37 # define MOZ_HAL_NAMESPACE hal
38 # define MOZ_DEFINED_HAL_NAMESPACE 1
39 #endif
41 namespace mozilla {
43 namespace hal {
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;
55 } // namespace hal
57 namespace MOZ_HAL_NAMESPACE {
59 /**
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);
79 /**
80 * Cancel a vibration started by the content window identified by
81 * WindowIdentifier.
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
85 * active.
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
89 * automatically.
91 void CancelVibrate(nsIDOMWindow* aWindow);
92 void CancelVibrate(const hal::WindowIdentifier &id);
94 /**
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);
248 * Set timezone
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);
255 * Get timezone
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);
308 * Reboot the device.
310 * This API is currently only allowed to be used from the main process.
312 void Reboot();
315 * Power off the device.
317 * This API is currently only allowed to be used from the main process.
319 void PowerOff();
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
419 * given switch.
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 * 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);
494 * Register an observer for the FM radio.
496 void RegisterFMRadioObserver(hal::FMRadioObserver* aRadioObserver);
499 * Unregister the observer for the FM radio.
501 void UnregisterFMRadioObserver(hal::FMRadioObserver* aRadioObserver);
504 * Notify observers that a call to EnableFMRadio, DisableFMRadio, or FMRadioSeek
505 * has completed, and indicate what the call returned.
507 void NotifyFMRadioStatus(const hal::FMRadioOperationInformation& aRadioState);
510 * Enable the FM radio and configure it according to the settings in aInfo.
512 void EnableFMRadio(const hal::FMRadioSettings& aInfo);
515 * Disable the FM radio.
517 void DisableFMRadio();
520 * Seek to an available FM radio station.
523 void FMRadioSeek(const hal::FMRadioSeekDirection& aDirection);
526 * Get the current FM radio settings.
528 void GetFMRadioSettings(hal::FMRadioSettings* aInfo);
531 * Set the FM radio's frequency.
533 void SetFMRadioFrequency(const uint32_t frequency);
536 * Get the FM radio's frequency.
538 uint32_t GetFMRadioFrequency();
541 * Get FM radio power state
543 bool IsFMRadioOn();
546 * Get FM radio signal strength
548 uint32_t GetFMRadioSignalStrength();
551 * Cancel FM radio seeking
553 void CancelFMRadioSeek();
556 * Get FM radio band settings by country.
558 hal::FMRadioSettings GetFMBandSettings(hal::FMRadioCountry aCountry);
561 * Start a watchdog to compulsively shutdown the system if it hangs.
562 * @param aMode Specify how to shutdown the system.
563 * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
565 * This API is currently only allowed to be used from the main process.
567 void StartForceQuitWatchdog(hal::ShutdownMode aMode, int32_t aTimeoutSecs);
570 * Perform Factory Reset to wipe out all user data.
572 void FactoryReset();
575 * Start monitoring the status of gamepads attached to the system.
577 void StartMonitoringGamepadStatus();
580 * Stop monitoring the status of gamepads attached to the system.
582 void StopMonitoringGamepadStatus();
585 * Start monitoring disk space for low space situations.
587 * This API is currently only allowed to be used from the main process.
589 void StartDiskSpaceWatcher();
592 * Stop monitoring disk space for low space situations.
594 * This API is currently only allowed to be used from the main process.
596 void StopDiskSpaceWatcher();
599 * Get total system memory of device being run on in bytes.
601 * Returns 0 if we are unable to determine this information from /proc/meminfo.
603 uint32_t GetTotalSystemMemory();
605 } // namespace MOZ_HAL_NAMESPACE
606 } // namespace mozilla
608 #ifdef MOZ_DEFINED_HAL_NAMESPACE
609 # undef MOZ_DEFINED_HAL_NAMESPACE
610 # undef MOZ_HAL_NAMESPACE
611 #endif
613 #endif // mozilla_Hal_h