Hal.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_Hal_h
  6. #define mozilla_Hal_h
  7. #include "base/basictypes.h"
  8. #include "base/platform_thread.h"
  9. #include "nsTArray.h"
  10. #include "mozilla/dom/MozPowerManagerBinding.h"
  11. #include "mozilla/dom/network/Types.h"
  12. #include "mozilla/dom/power/Types.h"
  13. #include "mozilla/dom/ScreenOrientation.h"
  14. #include "mozilla/hal_sandbox/PHal.h"
  15. #include "mozilla/HalScreenConfiguration.h"
  16. #include "mozilla/HalTypes.h"
  17. #include "mozilla/Types.h"
  18. /*
  19. * Hal.h contains the public Hal API.
  20. *
  21. * By default, this file defines its functions in the hal namespace, but if
  22. * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace.
  23. *
  24. * This is used by HalImpl.h and HalSandbox.h, which define copies of all the
  25. * functions here in the hal_impl and hal_sandbox namespaces.
  26. */
  27. class nsPIDOMWindowInner;
  28. #ifndef MOZ_HAL_NAMESPACE
  29. # define MOZ_HAL_NAMESPACE hal
  30. # define MOZ_DEFINED_HAL_NAMESPACE 1
  31. #endif
  32. namespace mozilla {
  33. namespace hal {
  34. typedef Observer<void_t> AlarmObserver;
  35. class WindowIdentifier;
  36. typedef Observer<int64_t> SystemClockChangeObserver;
  37. typedef Observer<SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;
  38. } // namespace hal
  39. namespace MOZ_HAL_NAMESPACE {
  40. /**
  41. * Determine whether the device's screen is currently enabled.
  42. */
  43. bool GetScreenEnabled();
  44. /**
  45. * Enable or disable the device's screen.
  46. *
  47. * Note that it may take a few seconds for the screen to turn on or off.
  48. */
  49. void SetScreenEnabled(bool aEnabled);
  50. /**
  51. * Determine whether the device's keypad/button backlight is currently enabled.
  52. */
  53. bool GetKeyLightEnabled();
  54. /**
  55. * Enable or disable the device's keypad/button backlight.
  56. */
  57. void SetKeyLightEnabled(bool aEnabled);
  58. /**
  59. * Get the brightness of the device's screen's backlight, on a scale from 0
  60. * (very dim) to 1 (full blast).
  61. *
  62. * If the display is currently disabled, this returns the brightness the
  63. * backlight will have when the display is re-enabled.
  64. */
  65. double GetScreenBrightness();
  66. /**
  67. * Set the brightness of the device's screen's backlight, on a scale from 0
  68. * (very dimm) to 1 (full blast). Values larger than 1 are treated like 1, and
  69. * values smaller than 0 are treated like 0.
  70. *
  71. * Note that we may reduce the resolution of the given brightness value before
  72. * sending it to the screen. Therefore if you call SetScreenBrightness(x)
  73. * followed by GetScreenBrightness(), the value returned by
  74. * GetScreenBrightness() may not be exactly x.
  75. */
  76. void SetScreenBrightness(double aBrightness);
  77. /**
  78. * Determine whether the device is allowed to sleep.
  79. */
  80. bool GetCpuSleepAllowed();
  81. /**
  82. * Set whether the device is allowed to suspend automatically after
  83. * the screen is disabled.
  84. */
  85. void SetCpuSleepAllowed(bool aAllowed);
  86. /**
  87. * Register an observer for the sensor of given type.
  88. *
  89. * The observer will receive data whenever the data generated by the
  90. * sensor is avaiable.
  91. */
  92. void RegisterSensorObserver(hal::SensorType aSensor,
  93. hal::ISensorObserver *aObserver);
  94. /**
  95. * Unregister an observer for the sensor of given type.
  96. */
  97. void UnregisterSensorObserver(hal::SensorType aSensor,
  98. hal::ISensorObserver *aObserver);
  99. /**
  100. * Post a value generated by a sensor.
  101. *
  102. * This API is internal to hal; clients shouldn't call it directly.
  103. */
  104. void NotifySensorChange(const hal::SensorData &aSensorData);
  105. /**
  106. * Enable sensor notifications from the backend
  107. *
  108. * This method is only visible from implementation of sensor manager.
  109. * Rest of the system should not try this.
  110. */
  111. void EnableSensorNotifications(hal::SensorType aSensor);
  112. /**
  113. * Disable sensor notifications from the backend
  114. *
  115. * This method is only visible from implementation of sensor manager.
  116. * Rest of the system should not try this.
  117. */
  118. void DisableSensorNotifications(hal::SensorType aSensor);
  119. /**
  120. * Inform the network backend there is a new network observer.
  121. * @param aNetworkObserver The observer that should be added.
  122. */
  123. void RegisterNetworkObserver(NetworkObserver* aNetworkObserver);
  124. /**
  125. * Inform the network backend a network observer unregistered.
  126. * @param aNetworkObserver The observer that should be removed.
  127. */
  128. void UnregisterNetworkObserver(NetworkObserver* aNetworkObserver);
  129. /**
  130. * Returns the current network information.
  131. */
  132. void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
  133. /**
  134. * Notify of a change in the network state.
  135. * @param aNetworkInfo The new network information.
  136. */
  137. void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
  138. /**
  139. * Adjusting system clock.
  140. * @param aDeltaMilliseconds The difference compared with current system clock.
  141. */
  142. void AdjustSystemClock(int64_t aDeltaMilliseconds);
  143. /**
  144. * Set timezone
  145. * @param aTimezoneSpec The definition can be found in
  146. * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  147. */
  148. void SetTimezone(const nsCString& aTimezoneSpec);
  149. /**
  150. * Get timezone
  151. * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  152. */
  153. nsCString GetTimezone();
  154. /**
  155. * Get timezone offset
  156. * returns the timezone offset relative to UTC in minutes (DST effect included)
  157. */
  158. int32_t GetTimezoneOffset();
  159. /**
  160. * Register observer for system clock changed notification.
  161. * @param aObserver The observer that should be added.
  162. */
  163. void RegisterSystemClockChangeObserver(
  164. hal::SystemClockChangeObserver* aObserver);
  165. /**
  166. * Unregister the observer for system clock changed.
  167. * @param aObserver The observer that should be removed.
  168. */
  169. void UnregisterSystemClockChangeObserver(
  170. hal::SystemClockChangeObserver* aObserver);
  171. /**
  172. * Notify of a change in the system clock.
  173. * @param aClockDeltaMS
  174. */
  175. void NotifySystemClockChange(const int64_t& aClockDeltaMS);
  176. /**
  177. * Register observer for system timezone changed notification.
  178. * @param aObserver The observer that should be added.
  179. */
  180. void RegisterSystemTimezoneChangeObserver(
  181. hal::SystemTimezoneChangeObserver* aObserver);
  182. /**
  183. * Unregister the observer for system timezone changed.
  184. * @param aObserver The observer that should be removed.
  185. */
  186. void UnregisterSystemTimezoneChangeObserver(
  187. hal::SystemTimezoneChangeObserver* aObserver);
  188. /**
  189. * Notify of a change in the system timezone.
  190. * @param aSystemTimezoneChangeInfo
  191. */
  192. void NotifySystemTimezoneChange(
  193. const hal::SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo);
  194. /**
  195. * Reboot the device.
  196. *
  197. * This API is currently only allowed to be used from the main process.
  198. */
  199. void Reboot();
  200. /**
  201. * Power off the device.
  202. *
  203. * This API is currently only allowed to be used from the main process.
  204. */
  205. void PowerOff();
  206. /**
  207. * Enable wake lock notifications from the backend.
  208. *
  209. * This method is only used by WakeLockObserversManager.
  210. */
  211. void EnableWakeLockNotifications();
  212. /**
  213. * Disable wake lock notifications from the backend.
  214. *
  215. * This method is only used by WakeLockObserversManager.
  216. */
  217. void DisableWakeLockNotifications();
  218. /**
  219. * Inform the wake lock backend there is a new wake lock observer.
  220. * @param aWakeLockObserver The observer that should be added.
  221. */
  222. void RegisterWakeLockObserver(WakeLockObserver* aObserver);
  223. /**
  224. * Inform the wake lock backend a wake lock observer unregistered.
  225. * @param aWakeLockObserver The observer that should be removed.
  226. */
  227. void UnregisterWakeLockObserver(WakeLockObserver* aObserver);
  228. /**
  229. * Adjust a wake lock's counts on behalf of a given process.
  230. *
  231. * In most cases, you shouldn't need to pass the aProcessID argument; the
  232. * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
  233. *
  234. * @param aTopic lock topic
  235. * @param aLockAdjust to increase or decrease active locks
  236. * @param aHiddenAdjust to increase or decrease hidden locks
  237. * @param aProcessID indicates which process we're modifying the wake lock
  238. * on behalf of. It is interpreted as
  239. *
  240. * CONTENT_PROCESS_ID_UNKNOWN: The current process
  241. * CONTENT_PROCESS_ID_MAIN: The root process
  242. * X: The process with ContentChild::GetID() == X
  243. */
  244. void ModifyWakeLock(const nsAString &aTopic,
  245. hal::WakeLockControl aLockAdjust,
  246. hal::WakeLockControl aHiddenAdjust,
  247. uint64_t aProcessID = hal::CONTENT_PROCESS_ID_UNKNOWN);
  248. /**
  249. * Query the wake lock numbers of aTopic.
  250. * @param aTopic lock topic
  251. * @param aWakeLockInfo wake lock numbers
  252. */
  253. void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLockInfo);
  254. /**
  255. * Notify of a change in the wake lock state.
  256. * @param aWakeLockInfo The new wake lock information.
  257. */
  258. void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
  259. /**
  260. * Inform the backend there is a new screen configuration observer.
  261. * @param aScreenConfigurationObserver The observer that should be added.
  262. */
  263. void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
  264. /**
  265. * Inform the backend a screen configuration observer unregistered.
  266. * @param aScreenConfigurationObserver The observer that should be removed.
  267. */
  268. void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
  269. /**
  270. * Returns the current screen configuration.
  271. */
  272. void GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration);
  273. /**
  274. * Notify of a change in the screen configuration.
  275. * @param aScreenConfiguration The new screen orientation.
  276. */
  277. void NotifyScreenConfigurationChange(const hal::ScreenConfiguration& aScreenConfiguration);
  278. /**
  279. * Lock the screen orientation to the specific orientation.
  280. * @return Whether the lock has been accepted.
  281. */
  282. MOZ_MUST_USE bool LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation);
  283. /**
  284. * Unlock the screen orientation.
  285. */
  286. void UnlockScreenOrientation();
  287. /**
  288. * Register an observer that is notified when a programmed alarm
  289. * expires.
  290. *
  291. * Currently, there can only be 0 or 1 alarm observers.
  292. */
  293. MOZ_MUST_USE bool RegisterTheOneAlarmObserver(hal::AlarmObserver* aObserver);
  294. /**
  295. * Unregister the alarm observer. Doing so will implicitly cancel any
  296. * programmed alarm.
  297. */
  298. void UnregisterTheOneAlarmObserver();
  299. /**
  300. * Notify that the programmed alarm has expired.
  301. *
  302. * This API is internal to hal; clients shouldn't call it directly.
  303. */
  304. void NotifyAlarmFired();
  305. /**
  306. * Program the real-time clock to expire at the time |aSeconds|,
  307. * |aNanoseconds|. These specify a point in real time relative to the
  308. * UNIX epoch. The alarm will fire at this time point even if the
  309. * real-time clock is changed; that is, this alarm respects changes to
  310. * the real-time clock. Return true iff the alarm was programmed.
  311. *
  312. * The alarm can be reprogrammed at any time.
  313. *
  314. * This API is currently only allowed to be used from non-sandboxed
  315. * contexts.
  316. */
  317. MOZ_MUST_USE bool SetAlarm(int32_t aSeconds, int32_t aNanoseconds);
  318. /**
  319. * Set the priority of the given process.
  320. *
  321. * Exactly what this does will vary between platforms. On *nix we might give
  322. * background processes higher nice values. On other platforms, we might
  323. * ignore this call entirely.
  324. */
  325. void SetProcessPriority(int aPid,
  326. hal::ProcessPriority aPriority,
  327. uint32_t aLRU = 0);
  328. /**
  329. * Set the current thread's priority to appropriate platform-specific value for
  330. * given functionality. Instead of providing arbitrary priority numbers you
  331. * must specify a type of function like THREAD_PRIORITY_COMPOSITOR.
  332. */
  333. void SetCurrentThreadPriority(hal::ThreadPriority aThreadPriority);
  334. /**
  335. * Set a thread priority to appropriate platform-specific value for
  336. * given functionality. Instead of providing arbitrary priority numbers you
  337. * must specify a type of function like THREAD_PRIORITY_COMPOSITOR.
  338. */
  339. void SetThreadPriority(PlatformThreadId aThreadId,
  340. hal::ThreadPriority aThreadPriority);
  341. /**
  342. * Start a watchdog to compulsively shutdown the system if it hangs.
  343. * @param aMode Specify how to shutdown the system.
  344. * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
  345. *
  346. * This API is currently only allowed to be used from the main process.
  347. */
  348. void StartForceQuitWatchdog(hal::ShutdownMode aMode, int32_t aTimeoutSecs);
  349. /**
  350. * Perform Factory Reset to wipe out all user data.
  351. */
  352. void FactoryReset(mozilla::dom::FactoryResetReason& aReason);
  353. /**
  354. * Get total system memory of device being run on in bytes.
  355. *
  356. * Returns 0 if we are unable to determine this information from /proc/meminfo.
  357. */
  358. uint32_t GetTotalSystemMemory();
  359. /**
  360. * Determine whether the headphone switch event is from input device
  361. */
  362. bool IsHeadphoneEventFromInputDev();
  363. /**
  364. * Start the system service with the specified name and arguments.
  365. */
  366. nsresult StartSystemService(const char* aSvcName, const char* aArgs);
  367. /**
  368. * Stop the system service with the specified name.
  369. */
  370. void StopSystemService(const char* aSvcName);
  371. /**
  372. * Determine whether the system service with the specified name is running.
  373. */
  374. bool SystemServiceIsRunning(const char* aSvcName);
  375. } // namespace MOZ_HAL_NAMESPACE
  376. } // namespace mozilla
  377. #ifdef MOZ_DEFINED_HAL_NAMESPACE
  378. # undef MOZ_DEFINED_HAL_NAMESPACE
  379. # undef MOZ_HAL_NAMESPACE
  380. #endif
  381. #endif // mozilla_Hal_h