Hal.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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. #include "Hal.h"
  6. #include "HalImpl.h"
  7. #include "HalLog.h"
  8. #include "HalSandbox.h"
  9. #include "nsIDOMDocument.h"
  10. #include "nsIDOMWindow.h"
  11. #include "nsIDocument.h"
  12. #include "nsIDocShell.h"
  13. #include "nsITabChild.h"
  14. #include "nsIWebNavigation.h"
  15. #include "nsThreadUtils.h"
  16. #include "nsXULAppAPI.h"
  17. #include "nsPIDOMWindow.h"
  18. #include "nsJSUtils.h"
  19. #include "mozilla/ClearOnShutdown.h"
  20. #include "mozilla/Observer.h"
  21. #include "mozilla/dom/ContentChild.h"
  22. #include "mozilla/dom/ScreenOrientation.h"
  23. #include "WindowIdentifier.h"
  24. #ifdef XP_WIN
  25. #include <process.h>
  26. #define getpid _getpid
  27. #endif
  28. using namespace mozilla::services;
  29. using namespace mozilla::dom;
  30. #define PROXY_IF_SANDBOXED(_call) \
  31. do { \
  32. if (InSandbox()) { \
  33. if (!hal_sandbox::HalChildDestroyed()) { \
  34. hal_sandbox::_call; \
  35. } \
  36. } else { \
  37. hal_impl::_call; \
  38. } \
  39. } while (0)
  40. #define RETURN_PROXY_IF_SANDBOXED(_call, defValue)\
  41. do { \
  42. if (InSandbox()) { \
  43. if (hal_sandbox::HalChildDestroyed()) { \
  44. return defValue; \
  45. } \
  46. return hal_sandbox::_call; \
  47. } else { \
  48. return hal_impl::_call; \
  49. } \
  50. } while (0)
  51. namespace mozilla {
  52. namespace hal {
  53. mozilla::LogModule *
  54. GetHalLog()
  55. {
  56. static mozilla::LazyLogModule sHalLog("hal");
  57. return sHalLog;
  58. }
  59. namespace {
  60. void
  61. AssertMainThread()
  62. {
  63. MOZ_ASSERT(NS_IsMainThread());
  64. }
  65. bool
  66. InSandbox()
  67. {
  68. return GeckoProcessType_Content == XRE_GetProcessType();
  69. }
  70. void
  71. AssertMainProcess()
  72. {
  73. MOZ_ASSERT(GeckoProcessType_Default == XRE_GetProcessType());
  74. }
  75. bool
  76. WindowIsActive(nsPIDOMWindowInner* aWindow)
  77. {
  78. nsIDocument* document = aWindow->GetDoc();
  79. NS_ENSURE_TRUE(document, false);
  80. return !document->Hidden();
  81. }
  82. } // namespace
  83. template <class InfoType>
  84. class ObserversManager
  85. {
  86. public:
  87. void AddObserver(Observer<InfoType>* aObserver) {
  88. if (!mObservers) {
  89. mObservers = new mozilla::ObserverList<InfoType>();
  90. }
  91. mObservers->AddObserver(aObserver);
  92. if (mObservers->Length() == 1) {
  93. EnableNotifications();
  94. }
  95. }
  96. void RemoveObserver(Observer<InfoType>* aObserver) {
  97. bool removed = mObservers && mObservers->RemoveObserver(aObserver);
  98. if (!removed) {
  99. return;
  100. }
  101. if (mObservers->Length() == 0) {
  102. DisableNotifications();
  103. OnNotificationsDisabled();
  104. delete mObservers;
  105. mObservers = nullptr;
  106. }
  107. }
  108. void BroadcastInformation(const InfoType& aInfo) {
  109. // It is possible for mObservers to be nullptr here on some platforms,
  110. // because a call to BroadcastInformation gets queued up asynchronously
  111. // while RemoveObserver is running (and before the notifications are
  112. // disabled). The queued call can then get run after mObservers has
  113. // been nulled out. See bug 757025.
  114. if (!mObservers) {
  115. return;
  116. }
  117. mObservers->Broadcast(aInfo);
  118. }
  119. protected:
  120. virtual void EnableNotifications() = 0;
  121. virtual void DisableNotifications() = 0;
  122. virtual void OnNotificationsDisabled() {}
  123. private:
  124. mozilla::ObserverList<InfoType>* mObservers;
  125. };
  126. template <class InfoType>
  127. class CachingObserversManager : public ObserversManager<InfoType>
  128. {
  129. public:
  130. InfoType GetCurrentInformation() {
  131. if (mHasValidCache) {
  132. return mInfo;
  133. }
  134. GetCurrentInformationInternal(&mInfo);
  135. mHasValidCache = true;
  136. return mInfo;
  137. }
  138. void CacheInformation(const InfoType& aInfo) {
  139. mHasValidCache = true;
  140. mInfo = aInfo;
  141. }
  142. void BroadcastCachedInformation() {
  143. this->BroadcastInformation(mInfo);
  144. }
  145. protected:
  146. virtual void GetCurrentInformationInternal(InfoType*) = 0;
  147. virtual void OnNotificationsDisabled() {
  148. mHasValidCache = false;
  149. }
  150. private:
  151. InfoType mInfo;
  152. bool mHasValidCache;
  153. };
  154. class NetworkObserversManager : public CachingObserversManager<NetworkInformation>
  155. {
  156. protected:
  157. void EnableNotifications() {
  158. PROXY_IF_SANDBOXED(EnableNetworkNotifications());
  159. }
  160. void DisableNotifications() {
  161. PROXY_IF_SANDBOXED(DisableNetworkNotifications());
  162. }
  163. void GetCurrentInformationInternal(NetworkInformation* aInfo) {
  164. PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo));
  165. }
  166. };
  167. static NetworkObserversManager&
  168. NetworkObservers()
  169. {
  170. static NetworkObserversManager sNetworkObservers;
  171. AssertMainThread();
  172. return sNetworkObservers;
  173. }
  174. class WakeLockObserversManager : public ObserversManager<WakeLockInformation>
  175. {
  176. protected:
  177. void EnableNotifications() {
  178. PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
  179. }
  180. void DisableNotifications() {
  181. PROXY_IF_SANDBOXED(DisableWakeLockNotifications());
  182. }
  183. };
  184. static WakeLockObserversManager&
  185. WakeLockObservers()
  186. {
  187. static WakeLockObserversManager sWakeLockObservers;
  188. AssertMainThread();
  189. return sWakeLockObservers;
  190. }
  191. class ScreenConfigurationObserversManager : public CachingObserversManager<ScreenConfiguration>
  192. {
  193. protected:
  194. void EnableNotifications() {
  195. PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
  196. }
  197. void DisableNotifications() {
  198. PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
  199. }
  200. void GetCurrentInformationInternal(ScreenConfiguration* aInfo) {
  201. PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo));
  202. }
  203. };
  204. static ScreenConfigurationObserversManager&
  205. ScreenConfigurationObservers()
  206. {
  207. AssertMainThread();
  208. static ScreenConfigurationObserversManager sScreenConfigurationObservers;
  209. return sScreenConfigurationObservers;
  210. }
  211. bool GetScreenEnabled()
  212. {
  213. AssertMainThread();
  214. RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false);
  215. }
  216. void SetScreenEnabled(bool aEnabled)
  217. {
  218. AssertMainThread();
  219. PROXY_IF_SANDBOXED(SetScreenEnabled(aEnabled));
  220. }
  221. bool GetKeyLightEnabled()
  222. {
  223. AssertMainThread();
  224. RETURN_PROXY_IF_SANDBOXED(GetKeyLightEnabled(), false);
  225. }
  226. void SetKeyLightEnabled(bool aEnabled)
  227. {
  228. AssertMainThread();
  229. PROXY_IF_SANDBOXED(SetKeyLightEnabled(aEnabled));
  230. }
  231. bool GetCpuSleepAllowed()
  232. {
  233. // Generally for interfaces that are accessible by normal web content
  234. // we should cache the result and be notified on state changes, like
  235. // what the battery API does. But since this is only used by
  236. // privileged interface, the synchronous getter is OK here.
  237. AssertMainThread();
  238. RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed(), true);
  239. }
  240. void SetCpuSleepAllowed(bool aAllowed)
  241. {
  242. AssertMainThread();
  243. PROXY_IF_SANDBOXED(SetCpuSleepAllowed(aAllowed));
  244. }
  245. double GetScreenBrightness()
  246. {
  247. AssertMainThread();
  248. RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness(), 0);
  249. }
  250. void SetScreenBrightness(double aBrightness)
  251. {
  252. AssertMainThread();
  253. PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(aBrightness, 0.0, 1.0)));
  254. }
  255. class SystemClockChangeObserversManager : public ObserversManager<int64_t>
  256. {
  257. protected:
  258. void EnableNotifications() {
  259. PROXY_IF_SANDBOXED(EnableSystemClockChangeNotifications());
  260. }
  261. void DisableNotifications() {
  262. PROXY_IF_SANDBOXED(DisableSystemClockChangeNotifications());
  263. }
  264. };
  265. static SystemClockChangeObserversManager&
  266. SystemClockChangeObservers()
  267. {
  268. static SystemClockChangeObserversManager sSystemClockChangeObservers;
  269. AssertMainThread();
  270. return sSystemClockChangeObservers;
  271. }
  272. void
  273. RegisterSystemClockChangeObserver(SystemClockChangeObserver* aObserver)
  274. {
  275. AssertMainThread();
  276. SystemClockChangeObservers().AddObserver(aObserver);
  277. }
  278. void
  279. UnregisterSystemClockChangeObserver(SystemClockChangeObserver* aObserver)
  280. {
  281. AssertMainThread();
  282. SystemClockChangeObservers().RemoveObserver(aObserver);
  283. }
  284. void
  285. NotifySystemClockChange(const int64_t& aClockDeltaMS)
  286. {
  287. SystemClockChangeObservers().BroadcastInformation(aClockDeltaMS);
  288. }
  289. class SystemTimezoneChangeObserversManager : public ObserversManager<SystemTimezoneChangeInformation>
  290. {
  291. protected:
  292. void EnableNotifications() {
  293. PROXY_IF_SANDBOXED(EnableSystemTimezoneChangeNotifications());
  294. }
  295. void DisableNotifications() {
  296. PROXY_IF_SANDBOXED(DisableSystemTimezoneChangeNotifications());
  297. }
  298. };
  299. static SystemTimezoneChangeObserversManager&
  300. SystemTimezoneChangeObservers()
  301. {
  302. static SystemTimezoneChangeObserversManager sSystemTimezoneChangeObservers;
  303. return sSystemTimezoneChangeObservers;
  304. }
  305. void
  306. RegisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver* aObserver)
  307. {
  308. AssertMainThread();
  309. SystemTimezoneChangeObservers().AddObserver(aObserver);
  310. }
  311. void
  312. UnregisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver* aObserver)
  313. {
  314. AssertMainThread();
  315. SystemTimezoneChangeObservers().RemoveObserver(aObserver);
  316. }
  317. void
  318. NotifySystemTimezoneChange(const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
  319. {
  320. nsJSUtils::ResetTimeZone();
  321. SystemTimezoneChangeObservers().BroadcastInformation(aSystemTimezoneChangeInfo);
  322. }
  323. void
  324. AdjustSystemClock(int64_t aDeltaMilliseconds)
  325. {
  326. AssertMainThread();
  327. PROXY_IF_SANDBOXED(AdjustSystemClock(aDeltaMilliseconds));
  328. }
  329. void
  330. SetTimezone(const nsCString& aTimezoneSpec)
  331. {
  332. AssertMainThread();
  333. PROXY_IF_SANDBOXED(SetTimezone(aTimezoneSpec));
  334. }
  335. int32_t
  336. GetTimezoneOffset()
  337. {
  338. AssertMainThread();
  339. RETURN_PROXY_IF_SANDBOXED(GetTimezoneOffset(), 0);
  340. }
  341. nsCString
  342. GetTimezone()
  343. {
  344. AssertMainThread();
  345. RETURN_PROXY_IF_SANDBOXED(GetTimezone(), nsCString(""));
  346. }
  347. void
  348. EnableSensorNotifications(SensorType aSensor) {
  349. AssertMainThread();
  350. PROXY_IF_SANDBOXED(EnableSensorNotifications(aSensor));
  351. }
  352. void
  353. DisableSensorNotifications(SensorType aSensor) {
  354. AssertMainThread();
  355. PROXY_IF_SANDBOXED(DisableSensorNotifications(aSensor));
  356. }
  357. typedef mozilla::ObserverList<SensorData> SensorObserverList;
  358. static SensorObserverList* gSensorObservers = nullptr;
  359. static SensorObserverList &
  360. GetSensorObservers(SensorType sensor_type) {
  361. MOZ_ASSERT(sensor_type < NUM_SENSOR_TYPE);
  362. if(!gSensorObservers) {
  363. gSensorObservers = new SensorObserverList[NUM_SENSOR_TYPE];
  364. }
  365. return gSensorObservers[sensor_type];
  366. }
  367. void
  368. RegisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
  369. SensorObserverList &observers = GetSensorObservers(aSensor);
  370. AssertMainThread();
  371. observers.AddObserver(aObserver);
  372. if(observers.Length() == 1) {
  373. EnableSensorNotifications(aSensor);
  374. }
  375. }
  376. void
  377. UnregisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
  378. AssertMainThread();
  379. if (!gSensorObservers) {
  380. HAL_ERR("Un-registering a sensor when none have been registered");
  381. return;
  382. }
  383. SensorObserverList &observers = GetSensorObservers(aSensor);
  384. if (!observers.RemoveObserver(aObserver) || observers.Length() > 0) {
  385. return;
  386. }
  387. DisableSensorNotifications(aSensor);
  388. // Destroy sSensorObservers only if all observer lists are empty.
  389. for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
  390. if (gSensorObservers[i].Length() > 0) {
  391. return;
  392. }
  393. }
  394. delete [] gSensorObservers;
  395. gSensorObservers = nullptr;
  396. }
  397. void
  398. NotifySensorChange(const SensorData &aSensorData) {
  399. SensorObserverList &observers = GetSensorObservers(aSensorData.sensor());
  400. AssertMainThread();
  401. observers.Broadcast(aSensorData);
  402. }
  403. void
  404. RegisterNetworkObserver(NetworkObserver* aObserver)
  405. {
  406. AssertMainThread();
  407. NetworkObservers().AddObserver(aObserver);
  408. }
  409. void
  410. UnregisterNetworkObserver(NetworkObserver* aObserver)
  411. {
  412. AssertMainThread();
  413. NetworkObservers().RemoveObserver(aObserver);
  414. }
  415. void
  416. GetCurrentNetworkInformation(NetworkInformation* aInfo)
  417. {
  418. AssertMainThread();
  419. *aInfo = NetworkObservers().GetCurrentInformation();
  420. }
  421. void
  422. NotifyNetworkChange(const NetworkInformation& aInfo)
  423. {
  424. NetworkObservers().CacheInformation(aInfo);
  425. NetworkObservers().BroadcastCachedInformation();
  426. }
  427. void Reboot()
  428. {
  429. AssertMainProcess();
  430. AssertMainThread();
  431. PROXY_IF_SANDBOXED(Reboot());
  432. }
  433. void PowerOff()
  434. {
  435. AssertMainProcess();
  436. AssertMainThread();
  437. PROXY_IF_SANDBOXED(PowerOff());
  438. }
  439. void StartForceQuitWatchdog(ShutdownMode aMode, int32_t aTimeoutSecs)
  440. {
  441. AssertMainProcess();
  442. AssertMainThread();
  443. PROXY_IF_SANDBOXED(StartForceQuitWatchdog(aMode, aTimeoutSecs));
  444. }
  445. void
  446. RegisterWakeLockObserver(WakeLockObserver* aObserver)
  447. {
  448. AssertMainThread();
  449. WakeLockObservers().AddObserver(aObserver);
  450. }
  451. void
  452. UnregisterWakeLockObserver(WakeLockObserver* aObserver)
  453. {
  454. AssertMainThread();
  455. WakeLockObservers().RemoveObserver(aObserver);
  456. }
  457. void
  458. ModifyWakeLock(const nsAString& aTopic,
  459. WakeLockControl aLockAdjust,
  460. WakeLockControl aHiddenAdjust,
  461. uint64_t aProcessID /* = CONTENT_PROCESS_ID_UNKNOWN */)
  462. {
  463. AssertMainThread();
  464. if (aProcessID == CONTENT_PROCESS_ID_UNKNOWN) {
  465. aProcessID = InSandbox() ? ContentChild::GetSingleton()->GetID() :
  466. CONTENT_PROCESS_ID_MAIN;
  467. }
  468. PROXY_IF_SANDBOXED(ModifyWakeLock(aTopic, aLockAdjust,
  469. aHiddenAdjust, aProcessID));
  470. }
  471. void
  472. GetWakeLockInfo(const nsAString& aTopic, WakeLockInformation* aWakeLockInfo)
  473. {
  474. AssertMainThread();
  475. PROXY_IF_SANDBOXED(GetWakeLockInfo(aTopic, aWakeLockInfo));
  476. }
  477. void
  478. NotifyWakeLockChange(const WakeLockInformation& aInfo)
  479. {
  480. AssertMainThread();
  481. WakeLockObservers().BroadcastInformation(aInfo);
  482. }
  483. void
  484. RegisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
  485. {
  486. AssertMainThread();
  487. ScreenConfigurationObservers().AddObserver(aObserver);
  488. }
  489. void
  490. UnregisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
  491. {
  492. AssertMainThread();
  493. ScreenConfigurationObservers().RemoveObserver(aObserver);
  494. }
  495. void
  496. GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
  497. {
  498. AssertMainThread();
  499. *aScreenConfiguration = ScreenConfigurationObservers().GetCurrentInformation();
  500. }
  501. void
  502. NotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration)
  503. {
  504. ScreenConfigurationObservers().CacheInformation(aScreenConfiguration);
  505. ScreenConfigurationObservers().BroadcastCachedInformation();
  506. }
  507. bool
  508. LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation)
  509. {
  510. AssertMainThread();
  511. RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation), false);
  512. }
  513. void
  514. UnlockScreenOrientation()
  515. {
  516. AssertMainThread();
  517. PROXY_IF_SANDBOXED(UnlockScreenOrientation());
  518. }
  519. static AlarmObserver* sAlarmObserver;
  520. bool
  521. RegisterTheOneAlarmObserver(AlarmObserver* aObserver)
  522. {
  523. MOZ_ASSERT(!InSandbox());
  524. MOZ_ASSERT(!sAlarmObserver);
  525. sAlarmObserver = aObserver;
  526. RETURN_PROXY_IF_SANDBOXED(EnableAlarm(), false);
  527. }
  528. void
  529. UnregisterTheOneAlarmObserver()
  530. {
  531. if (sAlarmObserver) {
  532. sAlarmObserver = nullptr;
  533. PROXY_IF_SANDBOXED(DisableAlarm());
  534. }
  535. }
  536. void
  537. NotifyAlarmFired()
  538. {
  539. if (sAlarmObserver) {
  540. sAlarmObserver->Notify(void_t());
  541. }
  542. }
  543. bool
  544. SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
  545. {
  546. // It's pointless to program an alarm nothing is going to observe ...
  547. MOZ_ASSERT(sAlarmObserver);
  548. RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds, aNanoseconds), false);
  549. }
  550. void
  551. SetProcessPriority(int aPid, ProcessPriority aPriority, uint32_t aLRU)
  552. {
  553. // n.b. The sandboxed implementation crashes; SetProcessPriority works only
  554. // from the main process.
  555. PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority, aLRU));
  556. }
  557. void
  558. SetCurrentThreadPriority(hal::ThreadPriority aThreadPriority)
  559. {
  560. PROXY_IF_SANDBOXED(SetCurrentThreadPriority(aThreadPriority));
  561. }
  562. void
  563. SetThreadPriority(PlatformThreadId aThreadId,
  564. hal::ThreadPriority aThreadPriority)
  565. {
  566. PROXY_IF_SANDBOXED(SetThreadPriority(aThreadId, aThreadPriority));
  567. }
  568. // From HalTypes.h.
  569. const char*
  570. ProcessPriorityToString(ProcessPriority aPriority)
  571. {
  572. switch (aPriority) {
  573. case PROCESS_PRIORITY_MASTER:
  574. return "MASTER";
  575. case PROCESS_PRIORITY_PREALLOC:
  576. return "PREALLOC";
  577. case PROCESS_PRIORITY_FOREGROUND_HIGH:
  578. return "FOREGROUND_HIGH";
  579. case PROCESS_PRIORITY_FOREGROUND:
  580. return "FOREGROUND";
  581. case PROCESS_PRIORITY_FOREGROUND_KEYBOARD:
  582. return "FOREGROUND_KEYBOARD";
  583. case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
  584. return "BACKGROUND_PERCEIVABLE";
  585. case PROCESS_PRIORITY_BACKGROUND:
  586. return "BACKGROUND";
  587. case PROCESS_PRIORITY_UNKNOWN:
  588. return "UNKNOWN";
  589. default:
  590. MOZ_ASSERT(false);
  591. return "???";
  592. }
  593. }
  594. const char *
  595. ThreadPriorityToString(ThreadPriority aPriority)
  596. {
  597. switch (aPriority) {
  598. case THREAD_PRIORITY_COMPOSITOR:
  599. return "COMPOSITOR";
  600. default:
  601. MOZ_ASSERT(false);
  602. return "???";
  603. }
  604. }
  605. void FactoryReset(mozilla::dom::FactoryResetReason& aReason)
  606. {
  607. AssertMainThread();
  608. PROXY_IF_SANDBOXED(FactoryReset(aReason));
  609. }
  610. uint32_t
  611. GetTotalSystemMemory()
  612. {
  613. return hal_impl::GetTotalSystemMemory();
  614. }
  615. bool IsHeadphoneEventFromInputDev()
  616. {
  617. AssertMainThread();
  618. RETURN_PROXY_IF_SANDBOXED(IsHeadphoneEventFromInputDev(), false);
  619. }
  620. nsresult StartSystemService(const char* aSvcName, const char* aArgs)
  621. {
  622. AssertMainThread();
  623. RETURN_PROXY_IF_SANDBOXED(StartSystemService(aSvcName, aArgs), NS_ERROR_FAILURE);
  624. }
  625. void StopSystemService(const char* aSvcName)
  626. {
  627. AssertMainThread();
  628. PROXY_IF_SANDBOXED(StopSystemService(aSvcName));
  629. }
  630. bool SystemServiceIsRunning(const char* aSvcName)
  631. {
  632. AssertMainThread();
  633. RETURN_PROXY_IF_SANDBOXED(SystemServiceIsRunning(aSvcName), false);
  634. }
  635. } // namespace hal
  636. } // namespace mozilla