michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et ft=cpp : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_Hal_h michael@0: #define mozilla_Hal_h michael@0: michael@0: #include "mozilla/hal_sandbox/PHal.h" michael@0: #include "mozilla/HalTypes.h" michael@0: #include "base/basictypes.h" michael@0: #include "mozilla/Observer.h" michael@0: #include "mozilla/Types.h" michael@0: #include "nsTArray.h" michael@0: #include "prlog.h" michael@0: #include "mozilla/dom/battery/Types.h" michael@0: #include "mozilla/dom/network/Types.h" michael@0: #include "mozilla/dom/power/Types.h" michael@0: #include "mozilla/hal_sandbox/PHal.h" michael@0: #include "mozilla/dom/ScreenOrientation.h" michael@0: #include "mozilla/HalScreenConfiguration.h" michael@0: michael@0: /* michael@0: * Hal.h contains the public Hal API. michael@0: * michael@0: * By default, this file defines its functions in the hal namespace, but if michael@0: * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace. michael@0: * michael@0: * This is used by HalImpl.h and HalSandbox.h, which define copies of all the michael@0: * functions here in the hal_impl and hal_sandbox namespaces. michael@0: */ michael@0: michael@0: class nsIDOMWindow; michael@0: michael@0: #ifndef MOZ_HAL_NAMESPACE michael@0: # define MOZ_HAL_NAMESPACE hal michael@0: # define MOZ_DEFINED_HAL_NAMESPACE 1 michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace hal { michael@0: michael@0: typedef Observer AlarmObserver; michael@0: michael@0: class WindowIdentifier; michael@0: michael@0: extern PRLogModuleInfo *GetHalLog(); michael@0: #define HAL_LOG(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, msg) michael@0: michael@0: typedef Observer SystemClockChangeObserver; michael@0: typedef Observer SystemTimezoneChangeObserver; michael@0: michael@0: } // namespace hal michael@0: michael@0: namespace MOZ_HAL_NAMESPACE { michael@0: michael@0: /** michael@0: * Turn the default vibrator device on/off per the pattern specified michael@0: * by |pattern|. Each element in the pattern is the number of michael@0: * milliseconds to turn the vibrator on or off. The first element in michael@0: * |pattern| is an "on" element, the next is "off", and so on. michael@0: * michael@0: * If |pattern| is empty, any in-progress vibration is canceled. michael@0: * michael@0: * Only an active window within an active tab may call Vibrate; calls michael@0: * from inactive windows and windows on inactive tabs do nothing. michael@0: * michael@0: * If you're calling hal::Vibrate from the outside world, pass an michael@0: * nsIDOMWindow* in place of the WindowIdentifier parameter. michael@0: * The method with WindowIdentifier will be called automatically. michael@0: */ michael@0: void Vibrate(const nsTArray& pattern, michael@0: nsIDOMWindow* aWindow); michael@0: void Vibrate(const nsTArray& pattern, michael@0: const hal::WindowIdentifier &id); michael@0: michael@0: /** michael@0: * Cancel a vibration started by the content window identified by michael@0: * WindowIdentifier. michael@0: * michael@0: * If the window was the last window to start a vibration, the michael@0: * cancellation request will go through even if the window is not michael@0: * active. michael@0: * michael@0: * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside michael@0: * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called michael@0: * automatically. michael@0: */ michael@0: void CancelVibrate(nsIDOMWindow* aWindow); michael@0: void CancelVibrate(const hal::WindowIdentifier &id); michael@0: michael@0: /** michael@0: * Inform the battery backend there is a new battery observer. michael@0: * @param aBatteryObserver The observer that should be added. michael@0: */ michael@0: void RegisterBatteryObserver(BatteryObserver* aBatteryObserver); michael@0: michael@0: /** michael@0: * Inform the battery backend a battery observer unregistered. michael@0: * @param aBatteryObserver The observer that should be removed. michael@0: */ michael@0: void UnregisterBatteryObserver(BatteryObserver* aBatteryObserver); michael@0: michael@0: /** michael@0: * Returns the current battery information. michael@0: */ michael@0: void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo); michael@0: michael@0: /** michael@0: * Notify of a change in the battery state. michael@0: * @param aBatteryInfo The new battery information. michael@0: */ michael@0: void NotifyBatteryChange(const hal::BatteryInformation& aBatteryInfo); michael@0: michael@0: /** michael@0: * Determine whether the device's screen is currently enabled. michael@0: */ michael@0: bool GetScreenEnabled(); michael@0: michael@0: /** michael@0: * Enable or disable the device's screen. michael@0: * michael@0: * Note that it may take a few seconds for the screen to turn on or off. michael@0: */ michael@0: void SetScreenEnabled(bool enabled); michael@0: michael@0: /** michael@0: * Get the brightness of the device's screen's backlight, on a scale from 0 michael@0: * (very dim) to 1 (full blast). michael@0: * michael@0: * If the display is currently disabled, this returns the brightness the michael@0: * backlight will have when the display is re-enabled. michael@0: */ michael@0: double GetScreenBrightness(); michael@0: michael@0: /** michael@0: * Set the brightness of the device's screen's backlight, on a scale from 0 michael@0: * (very dimm) to 1 (full blast). Values larger than 1 are treated like 1, and michael@0: * values smaller than 0 are treated like 0. michael@0: * michael@0: * Note that we may reduce the resolution of the given brightness value before michael@0: * sending it to the screen. Therefore if you call SetScreenBrightness(x) michael@0: * followed by GetScreenBrightness(), the value returned by michael@0: * GetScreenBrightness() may not be exactly x. michael@0: */ michael@0: void SetScreenBrightness(double brightness); michael@0: michael@0: /** michael@0: * Determine whether the device is allowed to sleep. michael@0: */ michael@0: bool GetCpuSleepAllowed(); michael@0: michael@0: /** michael@0: * Set whether the device is allowed to suspend automatically after michael@0: * the screen is disabled. michael@0: */ michael@0: void SetCpuSleepAllowed(bool allowed); michael@0: michael@0: /** michael@0: * Set the value of a light to a particular color, with a specific flash pattern. michael@0: * light specifices which light. See Hal.idl for the list of constants michael@0: * mode specifies user set or based on ambient light sensor michael@0: * flash specifies whether or how to flash the light michael@0: * flashOnMS and flashOffMS specify the pattern for XXX flash mode michael@0: * color specifies the color. If the light doesn't support color, the given color is michael@0: * transformed into a brightness, or just an on/off if that is all the light is capable of. michael@0: * returns true if successful and false if failed. michael@0: */ michael@0: bool SetLight(hal::LightType light, const hal::LightConfiguration& aConfig); michael@0: /** michael@0: * GET the value of a light returning a particular color, with a specific flash pattern. michael@0: * returns true if successful and false if failed. michael@0: */ michael@0: bool GetLight(hal::LightType light, hal::LightConfiguration* aConfig); michael@0: michael@0: michael@0: /** michael@0: * Register an observer for the sensor of given type. michael@0: * michael@0: * The observer will receive data whenever the data generated by the michael@0: * sensor is avaiable. michael@0: */ michael@0: void RegisterSensorObserver(hal::SensorType aSensor, michael@0: hal::ISensorObserver *aObserver); michael@0: michael@0: /** michael@0: * Unregister an observer for the sensor of given type. michael@0: */ michael@0: void UnregisterSensorObserver(hal::SensorType aSensor, michael@0: hal::ISensorObserver *aObserver); michael@0: michael@0: /** michael@0: * Post a value generated by a sensor. michael@0: * michael@0: * This API is internal to hal; clients shouldn't call it directly. michael@0: */ michael@0: void NotifySensorChange(const hal::SensorData &aSensorData); michael@0: michael@0: /** michael@0: * Enable sensor notifications from the backend michael@0: * michael@0: * This method is only visible from implementation of sensor manager. michael@0: * Rest of the system should not try this. michael@0: */ michael@0: void EnableSensorNotifications(hal::SensorType aSensor); michael@0: michael@0: /** michael@0: * Disable sensor notifications from the backend michael@0: * michael@0: * This method is only visible from implementation of sensor manager. michael@0: * Rest of the system should not try this. michael@0: */ michael@0: void DisableSensorNotifications(hal::SensorType aSensor); michael@0: michael@0: michael@0: /** michael@0: * Inform the network backend there is a new network observer. michael@0: * @param aNetworkObserver The observer that should be added. michael@0: */ michael@0: void RegisterNetworkObserver(NetworkObserver* aNetworkObserver); michael@0: michael@0: /** michael@0: * Inform the network backend a network observer unregistered. michael@0: * @param aNetworkObserver The observer that should be removed. michael@0: */ michael@0: void UnregisterNetworkObserver(NetworkObserver* aNetworkObserver); michael@0: michael@0: /** michael@0: * Returns the current network information. michael@0: */ michael@0: void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo); michael@0: michael@0: /** michael@0: * Notify of a change in the network state. michael@0: * @param aNetworkInfo The new network information. michael@0: */ michael@0: void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo); michael@0: michael@0: /** michael@0: * Adjusting system clock. michael@0: * @param aDeltaMilliseconds The difference compared with current system clock. michael@0: */ michael@0: void AdjustSystemClock(int64_t aDeltaMilliseconds); michael@0: michael@0: /** michael@0: * Set timezone michael@0: * @param aTimezoneSpec The definition can be found in michael@0: * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones michael@0: */ michael@0: void SetTimezone(const nsCString& aTimezoneSpec); michael@0: michael@0: /** michael@0: * Get timezone michael@0: * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones michael@0: */ michael@0: nsCString GetTimezone(); michael@0: michael@0: /** michael@0: * Get timezone offset michael@0: * returns the timezone offset relative to UTC in minutes (DST effect included) michael@0: */ michael@0: int32_t GetTimezoneOffset(); michael@0: michael@0: /** michael@0: * Register observer for system clock changed notification. michael@0: * @param aObserver The observer that should be added. michael@0: */ michael@0: void RegisterSystemClockChangeObserver( michael@0: hal::SystemClockChangeObserver* aObserver); michael@0: michael@0: /** michael@0: * Unregister the observer for system clock changed. michael@0: * @param aObserver The observer that should be removed. michael@0: */ michael@0: void UnregisterSystemClockChangeObserver( michael@0: hal::SystemClockChangeObserver* aObserver); michael@0: michael@0: /** michael@0: * Notify of a change in the system clock. michael@0: * @param aClockDeltaMS michael@0: */ michael@0: void NotifySystemClockChange(const int64_t& aClockDeltaMS); michael@0: michael@0: /** michael@0: * Register observer for system timezone changed notification. michael@0: * @param aObserver The observer that should be added. michael@0: */ michael@0: void RegisterSystemTimezoneChangeObserver( michael@0: hal::SystemTimezoneChangeObserver* aObserver); michael@0: michael@0: /** michael@0: * Unregister the observer for system timezone changed. michael@0: * @param aObserver The observer that should be removed. michael@0: */ michael@0: void UnregisterSystemTimezoneChangeObserver( michael@0: hal::SystemTimezoneChangeObserver* aObserver); michael@0: michael@0: /** michael@0: * Notify of a change in the system timezone. michael@0: * @param aSystemTimezoneChangeInfo michael@0: */ michael@0: void NotifySystemTimezoneChange( michael@0: const hal::SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo); michael@0: michael@0: /** michael@0: * Reboot the device. michael@0: * michael@0: * This API is currently only allowed to be used from the main process. michael@0: */ michael@0: void Reboot(); michael@0: michael@0: /** michael@0: * Power off the device. michael@0: * michael@0: * This API is currently only allowed to be used from the main process. michael@0: */ michael@0: void PowerOff(); michael@0: michael@0: /** michael@0: * Enable wake lock notifications from the backend. michael@0: * michael@0: * This method is only used by WakeLockObserversManager. michael@0: */ michael@0: void EnableWakeLockNotifications(); michael@0: michael@0: /** michael@0: * Disable wake lock notifications from the backend. michael@0: * michael@0: * This method is only used by WakeLockObserversManager. michael@0: */ michael@0: void DisableWakeLockNotifications(); michael@0: michael@0: /** michael@0: * Inform the wake lock backend there is a new wake lock observer. michael@0: * @param aWakeLockObserver The observer that should be added. michael@0: */ michael@0: void RegisterWakeLockObserver(WakeLockObserver* aObserver); michael@0: michael@0: /** michael@0: * Inform the wake lock backend a wake lock observer unregistered. michael@0: * @param aWakeLockObserver The observer that should be removed. michael@0: */ michael@0: void UnregisterWakeLockObserver(WakeLockObserver* aObserver); michael@0: michael@0: /** michael@0: * Adjust a wake lock's counts on behalf of a given process. michael@0: * michael@0: * In most cases, you shouldn't need to pass the aProcessID argument; the michael@0: * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want. michael@0: * michael@0: * @param aTopic lock topic michael@0: * @param aLockAdjust to increase or decrease active locks michael@0: * @param aHiddenAdjust to increase or decrease hidden locks michael@0: * @param aProcessID indicates which process we're modifying the wake lock michael@0: * on behalf of. It is interpreted as michael@0: * michael@0: * CONTENT_PROCESS_ID_UNKNOWN: The current process michael@0: * CONTENT_PROCESS_ID_MAIN: The root process michael@0: * X: The process with ContentChild::GetID() == X michael@0: */ michael@0: void ModifyWakeLock(const nsAString &aTopic, michael@0: hal::WakeLockControl aLockAdjust, michael@0: hal::WakeLockControl aHiddenAdjust, michael@0: uint64_t aProcessID = hal::CONTENT_PROCESS_ID_UNKNOWN); michael@0: michael@0: /** michael@0: * Query the wake lock numbers of aTopic. michael@0: * @param aTopic lock topic michael@0: * @param aWakeLockInfo wake lock numbers michael@0: */ michael@0: void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLockInfo); michael@0: michael@0: /** michael@0: * Notify of a change in the wake lock state. michael@0: * @param aWakeLockInfo The new wake lock information. michael@0: */ michael@0: void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo); michael@0: michael@0: /** michael@0: * Inform the backend there is a new screen configuration observer. michael@0: * @param aScreenConfigurationObserver The observer that should be added. michael@0: */ michael@0: void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver); michael@0: michael@0: /** michael@0: * Inform the backend a screen configuration observer unregistered. michael@0: * @param aScreenConfigurationObserver The observer that should be removed. michael@0: */ michael@0: void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver); michael@0: michael@0: /** michael@0: * Returns the current screen configuration. michael@0: */ michael@0: void GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration); michael@0: michael@0: /** michael@0: * Notify of a change in the screen configuration. michael@0: * @param aScreenConfiguration The new screen orientation. michael@0: */ michael@0: void NotifyScreenConfigurationChange(const hal::ScreenConfiguration& aScreenConfiguration); michael@0: michael@0: /** michael@0: * Lock the screen orientation to the specific orientation. michael@0: * @return Whether the lock has been accepted. michael@0: */ michael@0: bool LockScreenOrientation(const dom::ScreenOrientation& aOrientation); michael@0: michael@0: /** michael@0: * Unlock the screen orientation. michael@0: */ michael@0: void UnlockScreenOrientation(); michael@0: michael@0: /** michael@0: * Register an observer for the switch of given SwitchDevice. michael@0: * michael@0: * The observer will receive data whenever the data generated by the michael@0: * given switch. michael@0: */ michael@0: void RegisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver); michael@0: michael@0: /** michael@0: * Unregister an observer for the switch of given SwitchDevice. michael@0: */ michael@0: void UnregisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver); michael@0: michael@0: /** michael@0: * Notify the state of the switch. michael@0: * michael@0: * This API is internal to hal; clients shouldn't call it directly. michael@0: */ michael@0: void NotifySwitchChange(const hal::SwitchEvent& aEvent); michael@0: michael@0: /** michael@0: * Get current switch information. michael@0: */ michael@0: hal::SwitchState GetCurrentSwitchState(hal::SwitchDevice aDevice); michael@0: michael@0: /** michael@0: * Notify switch status change from input device. michael@0: */ michael@0: void NotifySwitchStateFromInputDevice(hal::SwitchDevice aDevice, michael@0: hal::SwitchState aState); michael@0: michael@0: /** michael@0: * Register an observer that is notified when a programmed alarm michael@0: * expires. michael@0: * michael@0: * Currently, there can only be 0 or 1 alarm observers. michael@0: */ michael@0: bool RegisterTheOneAlarmObserver(hal::AlarmObserver* aObserver); michael@0: michael@0: /** michael@0: * Unregister the alarm observer. Doing so will implicitly cancel any michael@0: * programmed alarm. michael@0: */ michael@0: void UnregisterTheOneAlarmObserver(); michael@0: michael@0: /** michael@0: * Notify that the programmed alarm has expired. michael@0: * michael@0: * This API is internal to hal; clients shouldn't call it directly. michael@0: */ michael@0: void NotifyAlarmFired(); michael@0: michael@0: /** michael@0: * Program the real-time clock to expire at the time |aSeconds|, michael@0: * |aNanoseconds|. These specify a point in real time relative to the michael@0: * UNIX epoch. The alarm will fire at this time point even if the michael@0: * real-time clock is changed; that is, this alarm respects changes to michael@0: * the real-time clock. Return true iff the alarm was programmed. michael@0: * michael@0: * The alarm can be reprogrammed at any time. michael@0: * michael@0: * This API is currently only allowed to be used from non-sandboxed michael@0: * contexts. michael@0: */ michael@0: bool SetAlarm(int32_t aSeconds, int32_t aNanoseconds); michael@0: michael@0: /** michael@0: * Set the priority of the given process. A process's priority is a two-tuple michael@0: * consisting of a hal::ProcessPriority value and a hal::ProcessCPUPriority michael@0: * value. michael@0: * michael@0: * Two processes with the same ProcessCPUPriority value don't necessarily have michael@0: * the same CPU priority; the CPU priority we assign to a process is a function michael@0: * of its ProcessPriority and ProcessCPUPriority. michael@0: * michael@0: * Exactly what this does will vary between platforms. On *nix we might give michael@0: * background processes higher nice values. On other platforms, we might michael@0: * ignore this call entirely. michael@0: */ michael@0: void SetProcessPriority(int aPid, michael@0: hal::ProcessPriority aPriority, michael@0: hal::ProcessCPUPriority aCPUPriority, michael@0: uint32_t aLRU = 0); michael@0: michael@0: /** michael@0: * Register an observer for the FM radio. michael@0: */ michael@0: void RegisterFMRadioObserver(hal::FMRadioObserver* aRadioObserver); michael@0: michael@0: /** michael@0: * Unregister the observer for the FM radio. michael@0: */ michael@0: void UnregisterFMRadioObserver(hal::FMRadioObserver* aRadioObserver); michael@0: michael@0: /** michael@0: * Notify observers that a call to EnableFMRadio, DisableFMRadio, or FMRadioSeek michael@0: * has completed, and indicate what the call returned. michael@0: */ michael@0: void NotifyFMRadioStatus(const hal::FMRadioOperationInformation& aRadioState); michael@0: michael@0: /** michael@0: * Enable the FM radio and configure it according to the settings in aInfo. michael@0: */ michael@0: void EnableFMRadio(const hal::FMRadioSettings& aInfo); michael@0: michael@0: /** michael@0: * Disable the FM radio. michael@0: */ michael@0: void DisableFMRadio(); michael@0: michael@0: /** michael@0: * Seek to an available FM radio station. michael@0: * michael@0: */ michael@0: void FMRadioSeek(const hal::FMRadioSeekDirection& aDirection); michael@0: michael@0: /** michael@0: * Get the current FM radio settings. michael@0: */ michael@0: void GetFMRadioSettings(hal::FMRadioSettings* aInfo); michael@0: michael@0: /** michael@0: * Set the FM radio's frequency. michael@0: */ michael@0: void SetFMRadioFrequency(const uint32_t frequency); michael@0: michael@0: /** michael@0: * Get the FM radio's frequency. michael@0: */ michael@0: uint32_t GetFMRadioFrequency(); michael@0: michael@0: /** michael@0: * Get FM radio power state michael@0: */ michael@0: bool IsFMRadioOn(); michael@0: michael@0: /** michael@0: * Get FM radio signal strength michael@0: */ michael@0: uint32_t GetFMRadioSignalStrength(); michael@0: michael@0: /** michael@0: * Cancel FM radio seeking michael@0: */ michael@0: void CancelFMRadioSeek(); michael@0: michael@0: /** michael@0: * Get FM radio band settings by country. michael@0: */ michael@0: hal::FMRadioSettings GetFMBandSettings(hal::FMRadioCountry aCountry); michael@0: michael@0: /** michael@0: * Start a watchdog to compulsively shutdown the system if it hangs. michael@0: * @param aMode Specify how to shutdown the system. michael@0: * @param aTimeoutSecs Specify the delayed seconds to shutdown the system. michael@0: * michael@0: * This API is currently only allowed to be used from the main process. michael@0: */ michael@0: void StartForceQuitWatchdog(hal::ShutdownMode aMode, int32_t aTimeoutSecs); michael@0: michael@0: /** michael@0: * Perform Factory Reset to wipe out all user data. michael@0: */ michael@0: void FactoryReset(); michael@0: michael@0: /** michael@0: * Start monitoring the status of gamepads attached to the system. michael@0: */ michael@0: void StartMonitoringGamepadStatus(); michael@0: michael@0: /** michael@0: * Stop monitoring the status of gamepads attached to the system. michael@0: */ michael@0: void StopMonitoringGamepadStatus(); michael@0: michael@0: /** michael@0: * Start monitoring disk space for low space situations. michael@0: * michael@0: * This API is currently only allowed to be used from the main process. michael@0: */ michael@0: void StartDiskSpaceWatcher(); michael@0: michael@0: /** michael@0: * Stop monitoring disk space for low space situations. michael@0: * michael@0: * This API is currently only allowed to be used from the main process. michael@0: */ michael@0: void StopDiskSpaceWatcher(); michael@0: michael@0: /** michael@0: * Get total system memory of device being run on in bytes. michael@0: * michael@0: * Returns 0 if we are unable to determine this information from /proc/meminfo. michael@0: */ michael@0: uint32_t GetTotalSystemMemory(); michael@0: michael@0: } // namespace MOZ_HAL_NAMESPACE michael@0: } // namespace mozilla michael@0: michael@0: #ifdef MOZ_DEFINED_HAL_NAMESPACE michael@0: # undef MOZ_DEFINED_HAL_NAMESPACE michael@0: # undef MOZ_HAL_NAMESPACE michael@0: #endif michael@0: michael@0: #endif // mozilla_Hal_h