LCOV - code coverage report
Current view: top level - hal/sandbox - SandboxHal.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 18 379 4.7 %
Date: 2017-07-14 16:53:18 Functions: 8 122 6.6 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : #include "Hal.h"
       8             : #include "HalLog.h"
       9             : #include "mozilla/dom/ContentChild.h"
      10             : #include "mozilla/dom/ContentParent.h"
      11             : #include "mozilla/hal_sandbox/PHalChild.h"
      12             : #include "mozilla/hal_sandbox/PHalParent.h"
      13             : #include "mozilla/dom/TabParent.h"
      14             : #include "mozilla/dom/TabChild.h"
      15             : #include "mozilla/dom/battery/Types.h"
      16             : #include "mozilla/dom/network/Types.h"
      17             : #include "mozilla/dom/ScreenOrientation.h"
      18             : #include "mozilla/fallback/FallbackScreenConfiguration.h"
      19             : #include "mozilla/Observer.h"
      20             : #include "mozilla/Unused.h"
      21             : #include "nsAutoPtr.h"
      22             : #include "WindowIdentifier.h"
      23             : 
      24             : using namespace mozilla;
      25             : using namespace mozilla::dom;
      26             : using namespace mozilla::hal;
      27             : 
      28             : namespace mozilla {
      29             : namespace hal_sandbox {
      30             : 
      31             : static bool sHalChildDestroyed = false;
      32             : 
      33             : bool
      34           2 : HalChildDestroyed()
      35             : {
      36           2 :   return sHalChildDestroyed;
      37             : }
      38             : 
      39             : static PHalChild* sHal;
      40             : static PHalChild*
      41           2 : Hal()
      42             : {
      43           2 :   if (!sHal) {
      44           2 :     sHal = ContentChild::GetSingleton()->SendPHalConstructor();
      45             :   }
      46           2 :   return sHal;
      47             : }
      48             : 
      49             : void
      50           0 : Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
      51             : {
      52           0 :   HAL_LOG("Vibrate: Sending to parent process.");
      53             : 
      54           0 :   AutoTArray<uint32_t, 8> p(pattern);
      55             : 
      56           0 :   WindowIdentifier newID(id);
      57           0 :   newID.AppendProcessID();
      58           0 :   Hal()->SendVibrate(p, newID.AsArray(), TabChild::GetFrom(newID.GetWindow()));
      59           0 : }
      60             : 
      61             : void
      62           0 : CancelVibrate(const WindowIdentifier &id)
      63             : {
      64           0 :   HAL_LOG("CancelVibrate: Sending to parent process.");
      65             : 
      66           0 :   WindowIdentifier newID(id);
      67           0 :   newID.AppendProcessID();
      68           0 :   Hal()->SendCancelVibrate(newID.AsArray(), TabChild::GetFrom(newID.GetWindow()));
      69           0 : }
      70             : 
      71             : void
      72           0 : EnableBatteryNotifications()
      73             : {
      74           0 :   Hal()->SendEnableBatteryNotifications();
      75           0 : }
      76             : 
      77             : void
      78           0 : DisableBatteryNotifications()
      79             : {
      80           0 :   Hal()->SendDisableBatteryNotifications();
      81           0 : }
      82             : 
      83             : void
      84           0 : GetCurrentBatteryInformation(BatteryInformation* aBatteryInfo)
      85             : {
      86           0 :   Hal()->SendGetCurrentBatteryInformation(aBatteryInfo);
      87           0 : }
      88             : 
      89             : void
      90           0 : EnableNetworkNotifications()
      91             : {
      92           0 :   Hal()->SendEnableNetworkNotifications();
      93           0 : }
      94             : 
      95             : void
      96           0 : DisableNetworkNotifications()
      97             : {
      98           0 :   Hal()->SendDisableNetworkNotifications();
      99           0 : }
     100             : 
     101             : void
     102           0 : GetCurrentNetworkInformation(NetworkInformation* aNetworkInfo)
     103             : {
     104           0 :   Hal()->SendGetCurrentNetworkInformation(aNetworkInfo);
     105           0 : }
     106             : 
     107             : void
     108           0 : EnableScreenConfigurationNotifications()
     109             : {
     110           0 :   Hal()->SendEnableScreenConfigurationNotifications();
     111           0 : }
     112             : 
     113             : void
     114           0 : DisableScreenConfigurationNotifications()
     115             : {
     116           0 :   Hal()->SendDisableScreenConfigurationNotifications();
     117           0 : }
     118             : 
     119             : void
     120           0 : GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
     121             : {
     122           0 :   fallback::GetCurrentScreenConfiguration(aScreenConfiguration);
     123           0 : }
     124             : 
     125             : bool
     126           0 : LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation)
     127             : {
     128             :   bool allowed;
     129           0 :   Hal()->SendLockScreenOrientation(aOrientation, &allowed);
     130           0 :   return allowed;
     131             : }
     132             : 
     133             : void
     134           0 : UnlockScreenOrientation()
     135             : {
     136           0 :   Hal()->SendUnlockScreenOrientation();
     137           0 : }
     138             : 
     139             : bool
     140           0 : GetScreenEnabled()
     141             : {
     142           0 :   bool enabled = false;
     143           0 :   Hal()->SendGetScreenEnabled(&enabled);
     144           0 :   return enabled;
     145             : }
     146             : 
     147             : void
     148           0 : SetScreenEnabled(bool aEnabled)
     149             : {
     150           0 :   Hal()->SendSetScreenEnabled(aEnabled);
     151           0 : }
     152             : 
     153             : bool
     154           0 : GetKeyLightEnabled()
     155             : {
     156           0 :   bool enabled = false;
     157           0 :   Hal()->SendGetKeyLightEnabled(&enabled);
     158           0 :   return enabled;
     159             : }
     160             : 
     161             : void
     162           0 : SetKeyLightEnabled(bool aEnabled)
     163             : {
     164           0 :   Hal()->SendSetKeyLightEnabled(aEnabled);
     165           0 : }
     166             : 
     167             : bool
     168           0 : GetCpuSleepAllowed()
     169             : {
     170           0 :   bool allowed = true;
     171           0 :   Hal()->SendGetCpuSleepAllowed(&allowed);
     172           0 :   return allowed;
     173             : }
     174             : 
     175             : void
     176           0 : SetCpuSleepAllowed(bool aAllowed)
     177             : {
     178           0 :   Hal()->SendSetCpuSleepAllowed(aAllowed);
     179           0 : }
     180             : 
     181             : double
     182           0 : GetScreenBrightness()
     183             : {
     184           0 :   double brightness = 0;
     185           0 :   Hal()->SendGetScreenBrightness(&brightness);
     186           0 :   return brightness;
     187             : }
     188             : 
     189             : void
     190           0 : SetScreenBrightness(double aBrightness)
     191             : {
     192           0 :   Hal()->SendSetScreenBrightness(aBrightness);
     193           0 : }
     194             : 
     195             : void
     196           0 : AdjustSystemClock(int64_t aDeltaMilliseconds)
     197             : {
     198           0 :   Hal()->SendAdjustSystemClock(aDeltaMilliseconds);
     199           0 : }
     200             : 
     201             : void
     202           0 : SetTimezone(const nsCString& aTimezoneSpec)
     203             : {
     204           0 :   Hal()->SendSetTimezone(nsCString(aTimezoneSpec));
     205           0 : }
     206             : 
     207             : nsCString
     208           0 : GetTimezone()
     209             : {
     210           0 :   nsCString timezone;
     211           0 :   Hal()->SendGetTimezone(&timezone);
     212           0 :   return timezone;
     213             : }
     214             : 
     215             : int32_t
     216           0 : GetTimezoneOffset()
     217             : {
     218             :   int32_t timezoneOffset;
     219           0 :   Hal()->SendGetTimezoneOffset(&timezoneOffset);
     220           0 :   return timezoneOffset;
     221             : }
     222             : 
     223             : void
     224           0 : EnableSystemClockChangeNotifications()
     225             : {
     226           0 :   Hal()->SendEnableSystemClockChangeNotifications();
     227           0 : }
     228             : 
     229             : void
     230           0 : DisableSystemClockChangeNotifications()
     231             : {
     232           0 :   Hal()->SendDisableSystemClockChangeNotifications();
     233           0 : }
     234             : 
     235             : void
     236           2 : EnableSystemTimezoneChangeNotifications()
     237             : {
     238           2 :   Hal()->SendEnableSystemTimezoneChangeNotifications();
     239           2 : }
     240             : 
     241             : void
     242           0 : DisableSystemTimezoneChangeNotifications()
     243             : {
     244           0 :   Hal()->SendDisableSystemTimezoneChangeNotifications();
     245           0 : }
     246             : 
     247             : void
     248           0 : Reboot()
     249             : {
     250           0 :   MOZ_CRASH("Reboot() can't be called from sandboxed contexts.");
     251             : }
     252             : 
     253             : void
     254           0 : PowerOff()
     255             : {
     256           0 :   MOZ_CRASH("PowerOff() can't be called from sandboxed contexts.");
     257             : }
     258             : 
     259             : void
     260           0 : StartForceQuitWatchdog(ShutdownMode aMode, int32_t aTimeoutSecs)
     261             : {
     262           0 :   MOZ_CRASH("StartForceQuitWatchdog() can't be called from sandboxed contexts.");
     263             : }
     264             : 
     265             : void
     266           0 : EnableSensorNotifications(SensorType aSensor) {
     267           0 :   Hal()->SendEnableSensorNotifications(aSensor);
     268           0 : }
     269             : 
     270             : void
     271           0 : DisableSensorNotifications(SensorType aSensor) {
     272           0 :   Hal()->SendDisableSensorNotifications(aSensor);
     273           0 : }
     274             : 
     275             : void
     276           0 : EnableWakeLockNotifications()
     277             : {
     278           0 :   Hal()->SendEnableWakeLockNotifications();
     279           0 : }
     280             : 
     281             : void
     282           0 : DisableWakeLockNotifications()
     283             : {
     284           0 :   Hal()->SendDisableWakeLockNotifications();
     285           0 : }
     286             : 
     287             : void
     288           0 : ModifyWakeLock(const nsAString &aTopic,
     289             :                WakeLockControl aLockAdjust,
     290             :                WakeLockControl aHiddenAdjust,
     291             :                uint64_t aProcessID)
     292             : {
     293           0 :   MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN);
     294           0 :   Hal()->SendModifyWakeLock(nsString(aTopic), aLockAdjust, aHiddenAdjust, aProcessID);
     295           0 : }
     296             : 
     297             : void
     298           0 : GetWakeLockInfo(const nsAString &aTopic, WakeLockInformation *aWakeLockInfo)
     299             : {
     300           0 :   Hal()->SendGetWakeLockInfo(nsString(aTopic), aWakeLockInfo);
     301           0 : }
     302             : 
     303             : void
     304           0 : EnableSwitchNotifications(SwitchDevice aDevice)
     305             : {
     306           0 :   Hal()->SendEnableSwitchNotifications(aDevice);
     307           0 : }
     308             : 
     309             : void
     310           0 : DisableSwitchNotifications(SwitchDevice aDevice)
     311             : {
     312           0 :   Hal()->SendDisableSwitchNotifications(aDevice);
     313           0 : }
     314             : 
     315             : SwitchState
     316           0 : GetCurrentSwitchState(SwitchDevice aDevice)
     317             : {
     318             :   SwitchState state;
     319           0 :   Hal()->SendGetCurrentSwitchState(aDevice, &state);
     320           0 :   return state;
     321             : }
     322             : 
     323             : void
     324           0 : NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState)
     325             : {
     326             :   Unused << aDevice;
     327             :   Unused << aState;
     328           0 :   NS_RUNTIMEABORT("Only the main process may notify switch state change.");
     329           0 : }
     330             : 
     331             : bool
     332           0 : EnableAlarm()
     333             : {
     334           0 :   NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts.  Yet.");
     335           0 :   return false;
     336             : }
     337             : 
     338             : void
     339           0 : DisableAlarm()
     340             : {
     341           0 :   NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts.  Yet.");
     342           0 : }
     343             : 
     344             : bool
     345           0 : SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
     346             : {
     347           0 :   NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts.  Yet.");
     348           0 :   return false;
     349             : }
     350             : 
     351             : void
     352           0 : SetProcessPriority(int aPid, ProcessPriority aPriority)
     353             : {
     354           0 :   NS_RUNTIMEABORT("Only the main process may set processes' priorities.");
     355           0 : }
     356             : 
     357             : bool
     358           0 : SetProcessPrioritySupported()
     359             : {
     360           0 :   NS_RUNTIMEABORT("Only the main process may call SetProcessPrioritySupported().");
     361           0 :   return false;
     362             : }
     363             : 
     364             : void
     365           0 : SetCurrentThreadPriority(ThreadPriority aThreadPriority)
     366             : {
     367           0 :   NS_RUNTIMEABORT("Setting current thread priority cannot be called from sandboxed contexts.");
     368           0 : }
     369             : 
     370             : void
     371           0 : SetThreadPriority(PlatformThreadId aThreadId,
     372             :                   ThreadPriority aThreadPriority)
     373             : {
     374           0 :   NS_RUNTIMEABORT("Setting thread priority cannot be called from sandboxed contexts.");
     375           0 : }
     376             : 
     377             : void
     378           0 : FactoryReset(FactoryResetReason& aReason)
     379             : {
     380           0 :   if (aReason == FactoryResetReason::Normal) {
     381           0 :     Hal()->SendFactoryReset(NS_LITERAL_STRING("normal"));
     382           0 :   } else if (aReason == FactoryResetReason::Wipe) {
     383           0 :     Hal()->SendFactoryReset(NS_LITERAL_STRING("wipe"));
     384           0 :   } else if (aReason == FactoryResetReason::Root) {
     385           0 :     Hal()->SendFactoryReset(NS_LITERAL_STRING("root"));
     386             :   }
     387           0 : }
     388             : 
     389             : void
     390           0 : StartDiskSpaceWatcher()
     391             : {
     392           0 :   MOZ_CRASH("StartDiskSpaceWatcher() can't be called from sandboxed contexts.");
     393             : }
     394             : 
     395             : void
     396           0 : StopDiskSpaceWatcher()
     397             : {
     398           0 :   MOZ_CRASH("StopDiskSpaceWatcher() can't be called from sandboxed contexts.");
     399             : }
     400             : 
     401           0 : bool IsHeadphoneEventFromInputDev()
     402             : {
     403           0 :   MOZ_CRASH("IsHeadphoneEventFromInputDev() cannot be called from sandboxed contexts.");
     404             :   return false;
     405             : }
     406             : 
     407           0 : nsresult StartSystemService(const char* aSvcName, const char* aArgs)
     408             : {
     409           0 :   MOZ_CRASH("System services cannot be controlled from sandboxed contexts.");
     410             :   return NS_ERROR_NOT_IMPLEMENTED;
     411             : }
     412             : 
     413           0 : void StopSystemService(const char* aSvcName)
     414             : {
     415           0 :   MOZ_CRASH("System services cannot be controlled from sandboxed contexts.");
     416             : }
     417             : 
     418           0 : bool SystemServiceIsRunning(const char* aSvcName)
     419             : {
     420           0 :   MOZ_CRASH("System services cannot be controlled from sandboxed contexts.");
     421             :   return false;
     422             : }
     423             : 
     424           1 : class HalParent : public PHalParent
     425             :                 , public BatteryObserver
     426             :                 , public NetworkObserver
     427             :                 , public ISensorObserver
     428             :                 , public WakeLockObserver
     429             :                 , public ScreenConfigurationObserver
     430             :                 , public SwitchObserver
     431             :                 , public SystemClockChangeObserver
     432             :                 , public SystemTimezoneChangeObserver
     433             : {
     434             : public:
     435             :   virtual void
     436           0 :   ActorDestroy(ActorDestroyReason aWhy) override
     437             :   {
     438             :     // NB: you *must* unconditionally unregister your observer here,
     439             :     // if it *may* be registered below.
     440           0 :     hal::UnregisterBatteryObserver(this);
     441           0 :     hal::UnregisterNetworkObserver(this);
     442           0 :     hal::UnregisterScreenConfigurationObserver(this);
     443           0 :     for (int32_t sensor = SENSOR_UNKNOWN + 1;
     444           0 :          sensor < NUM_SENSOR_TYPE; ++sensor) {
     445           0 :       hal::UnregisterSensorObserver(SensorType(sensor), this);
     446             :     }
     447           0 :     hal::UnregisterWakeLockObserver(this);
     448           0 :     hal::UnregisterSystemClockChangeObserver(this);
     449           0 :     hal::UnregisterSystemTimezoneChangeObserver(this);
     450           0 :     for (int32_t switchDevice = SWITCH_DEVICE_UNKNOWN + 1;
     451           0 :          switchDevice < NUM_SWITCH_DEVICE; ++switchDevice) {
     452           0 :       hal::UnregisterSwitchObserver(SwitchDevice(switchDevice), this);
     453             :     }
     454           0 :   }
     455             : 
     456             :   virtual mozilla::ipc::IPCResult
     457           0 :   RecvVibrate(InfallibleTArray<unsigned int>&& pattern,
     458             :               InfallibleTArray<uint64_t>&& id,
     459             :               PBrowserParent *browserParent) override
     460             :   {
     461             :     // We give all content vibration permission.
     462             :     //    TabParent *tabParent = TabParent::GetFrom(browserParent);
     463             :     /* xxxkhuey wtf
     464             :     nsCOMPtr<nsIDOMWindow> window =
     465             :       do_QueryInterface(tabParent->GetBrowserDOMWindow());
     466             :     */
     467           0 :     WindowIdentifier newID(id, nullptr);
     468           0 :     hal::Vibrate(pattern, newID);
     469           0 :     return IPC_OK();
     470             :   }
     471             : 
     472             :   virtual mozilla::ipc::IPCResult
     473           0 :   RecvCancelVibrate(InfallibleTArray<uint64_t> &&id,
     474             :                     PBrowserParent *browserParent) override
     475             :   {
     476             :     //TabParent *tabParent = TabParent::GetFrom(browserParent);
     477             :     /* XXXkhuey wtf
     478             :     nsCOMPtr<nsIDOMWindow> window =
     479             :       tabParent->GetBrowserDOMWindow();
     480             :     */
     481           0 :     WindowIdentifier newID(id, nullptr);
     482           0 :     hal::CancelVibrate(newID);
     483           0 :     return IPC_OK();
     484             :   }
     485             : 
     486             :   virtual mozilla::ipc::IPCResult
     487           0 :   RecvEnableBatteryNotifications() override {
     488             :     // We give all content battery-status permission.
     489           0 :     hal::RegisterBatteryObserver(this);
     490           0 :     return IPC_OK();
     491             :   }
     492             : 
     493             :   virtual mozilla::ipc::IPCResult
     494           0 :   RecvDisableBatteryNotifications() override {
     495           0 :     hal::UnregisterBatteryObserver(this);
     496           0 :     return IPC_OK();
     497             :   }
     498             : 
     499             :   virtual mozilla::ipc::IPCResult
     500           0 :   RecvGetCurrentBatteryInformation(BatteryInformation* aBatteryInfo) override {
     501             :     // We give all content battery-status permission.
     502           0 :     hal::GetCurrentBatteryInformation(aBatteryInfo);
     503           0 :     return IPC_OK();
     504             :   }
     505             : 
     506           0 :   void Notify(const BatteryInformation& aBatteryInfo) override {
     507           0 :     Unused << SendNotifyBatteryChange(aBatteryInfo);
     508           0 :   }
     509             : 
     510             :   virtual mozilla::ipc::IPCResult
     511           0 :   RecvEnableNetworkNotifications() override {
     512             :     // We give all content access to this network-status information.
     513           0 :     hal::RegisterNetworkObserver(this);
     514           0 :     return IPC_OK();
     515             :   }
     516             : 
     517             :   virtual mozilla::ipc::IPCResult
     518           0 :   RecvDisableNetworkNotifications() override {
     519           0 :     hal::UnregisterNetworkObserver(this);
     520           0 :     return IPC_OK();
     521             :   }
     522             : 
     523             :   virtual mozilla::ipc::IPCResult
     524           0 :   RecvGetCurrentNetworkInformation(NetworkInformation* aNetworkInfo) override {
     525           0 :     hal::GetCurrentNetworkInformation(aNetworkInfo);
     526           0 :     return IPC_OK();
     527             :   }
     528             : 
     529           0 :   void Notify(const NetworkInformation& aNetworkInfo) override {
     530           0 :     Unused << SendNotifyNetworkChange(aNetworkInfo);
     531           0 :   }
     532             : 
     533             :   virtual mozilla::ipc::IPCResult
     534           0 :   RecvEnableScreenConfigurationNotifications() override {
     535             :     // Screen configuration is used to implement CSS and DOM
     536             :     // properties, so all content already has access to this.
     537           0 :     hal::RegisterScreenConfigurationObserver(this);
     538           0 :     return IPC_OK();
     539             :   }
     540             : 
     541             :   virtual mozilla::ipc::IPCResult
     542           0 :   RecvDisableScreenConfigurationNotifications() override {
     543           0 :     hal::UnregisterScreenConfigurationObserver(this);
     544           0 :     return IPC_OK();
     545             :   }
     546             : 
     547             :   virtual mozilla::ipc::IPCResult
     548           0 :   RecvLockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation, bool* aAllowed) override
     549             :   {
     550             :     // FIXME/bug 777980: unprivileged content may only lock
     551             :     // orientation while fullscreen.  We should check whether the
     552             :     // request comes from an actor in a process that might be
     553             :     // fullscreen.  We don't have that information currently.
     554           0 :     *aAllowed = hal::LockScreenOrientation(aOrientation);
     555           0 :     return IPC_OK();
     556             :   }
     557             : 
     558             :   virtual mozilla::ipc::IPCResult
     559           0 :   RecvUnlockScreenOrientation() override
     560             :   {
     561           0 :     hal::UnlockScreenOrientation();
     562           0 :     return IPC_OK();
     563             :   }
     564             : 
     565           0 :   void Notify(const ScreenConfiguration& aScreenConfiguration) override {
     566           0 :     Unused << SendNotifyScreenConfigurationChange(aScreenConfiguration);
     567           0 :   }
     568             : 
     569             :   virtual mozilla::ipc::IPCResult
     570           0 :   RecvGetScreenEnabled(bool* aEnabled) override
     571             :   {
     572           0 :     *aEnabled = hal::GetScreenEnabled();
     573           0 :     return IPC_OK();
     574             :   }
     575             : 
     576             :   virtual mozilla::ipc::IPCResult
     577           0 :   RecvSetScreenEnabled(const bool& aEnabled) override
     578             :   {
     579           0 :     hal::SetScreenEnabled(aEnabled);
     580           0 :     return IPC_OK();
     581             :   }
     582             : 
     583             :   virtual mozilla::ipc::IPCResult
     584           0 :   RecvGetKeyLightEnabled(bool* aEnabled) override
     585             :   {
     586           0 :     *aEnabled = hal::GetKeyLightEnabled();
     587           0 :     return IPC_OK();
     588             :   }
     589             : 
     590             :   virtual mozilla::ipc::IPCResult
     591           0 :   RecvSetKeyLightEnabled(const bool& aEnabled) override
     592             :   {
     593           0 :     hal::SetKeyLightEnabled(aEnabled);
     594           0 :     return IPC_OK();
     595             :   }
     596             : 
     597             :   virtual mozilla::ipc::IPCResult
     598           0 :   RecvGetCpuSleepAllowed(bool* aAllowed) override
     599             :   {
     600           0 :     *aAllowed = hal::GetCpuSleepAllowed();
     601           0 :     return IPC_OK();
     602             :   }
     603             : 
     604             :   virtual mozilla::ipc::IPCResult
     605           0 :   RecvSetCpuSleepAllowed(const bool& aAllowed) override
     606             :   {
     607           0 :     hal::SetCpuSleepAllowed(aAllowed);
     608           0 :     return IPC_OK();
     609             :   }
     610             : 
     611             :   virtual mozilla::ipc::IPCResult
     612           0 :   RecvGetScreenBrightness(double* aBrightness) override
     613             :   {
     614           0 :     *aBrightness = hal::GetScreenBrightness();
     615           0 :     return IPC_OK();
     616             :   }
     617             : 
     618             :   virtual mozilla::ipc::IPCResult
     619           0 :   RecvSetScreenBrightness(const double& aBrightness) override
     620             :   {
     621           0 :     hal::SetScreenBrightness(aBrightness);
     622           0 :     return IPC_OK();
     623             :   }
     624             : 
     625             :   virtual mozilla::ipc::IPCResult
     626           0 :   RecvAdjustSystemClock(const int64_t &aDeltaMilliseconds) override
     627             :   {
     628           0 :     hal::AdjustSystemClock(aDeltaMilliseconds);
     629           0 :     return IPC_OK();
     630             :   }
     631             : 
     632             :   virtual mozilla::ipc::IPCResult
     633           0 :   RecvSetTimezone(const nsCString& aTimezoneSpec) override
     634             :   {
     635           0 :     hal::SetTimezone(aTimezoneSpec);
     636           0 :     return IPC_OK();
     637             :   }
     638             : 
     639             :   virtual mozilla::ipc::IPCResult
     640           0 :   RecvGetTimezone(nsCString *aTimezoneSpec) override
     641             :   {
     642           0 :     *aTimezoneSpec = hal::GetTimezone();
     643           0 :     return IPC_OK();
     644             :   }
     645             : 
     646             :   virtual mozilla::ipc::IPCResult
     647           0 :   RecvGetTimezoneOffset(int32_t *aTimezoneOffset) override
     648             :   {
     649           0 :     *aTimezoneOffset = hal::GetTimezoneOffset();
     650           0 :     return IPC_OK();
     651             :   }
     652             : 
     653             :   virtual mozilla::ipc::IPCResult
     654           0 :   RecvEnableSystemClockChangeNotifications() override
     655             :   {
     656           0 :     hal::RegisterSystemClockChangeObserver(this);
     657           0 :     return IPC_OK();
     658             :   }
     659             : 
     660             :   virtual mozilla::ipc::IPCResult
     661           0 :   RecvDisableSystemClockChangeNotifications() override
     662             :   {
     663           0 :     hal::UnregisterSystemClockChangeObserver(this);
     664           0 :     return IPC_OK();
     665             :   }
     666             : 
     667             :   virtual mozilla::ipc::IPCResult
     668           1 :   RecvEnableSystemTimezoneChangeNotifications() override
     669             :   {
     670           1 :     hal::RegisterSystemTimezoneChangeObserver(this);
     671           1 :     return IPC_OK();
     672             :   }
     673             : 
     674             :   virtual mozilla::ipc::IPCResult
     675           0 :   RecvDisableSystemTimezoneChangeNotifications() override
     676             :   {
     677           0 :     hal::UnregisterSystemTimezoneChangeObserver(this);
     678           0 :     return IPC_OK();
     679             :   }
     680             : 
     681             :   virtual mozilla::ipc::IPCResult
     682           0 :   RecvEnableSensorNotifications(const SensorType &aSensor) override {
     683             :     // We currently allow any content to register device-sensor
     684             :     // listeners.
     685           0 :     hal::RegisterSensorObserver(aSensor, this);
     686           0 :     return IPC_OK();
     687             :   }
     688             : 
     689             :   virtual mozilla::ipc::IPCResult
     690           0 :   RecvDisableSensorNotifications(const SensorType &aSensor) override {
     691           0 :     hal::UnregisterSensorObserver(aSensor, this);
     692           0 :     return IPC_OK();
     693             :   }
     694             : 
     695           0 :   void Notify(const SensorData& aSensorData) override {
     696           0 :     Unused << SendNotifySensorChange(aSensorData);
     697           0 :   }
     698             : 
     699             :   virtual mozilla::ipc::IPCResult
     700           0 :   RecvModifyWakeLock(const nsString& aTopic,
     701             :                      const WakeLockControl& aLockAdjust,
     702             :                      const WakeLockControl& aHiddenAdjust,
     703             :                      const uint64_t& aProcessID) override
     704             :   {
     705           0 :     MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN);
     706             : 
     707             :     // We allow arbitrary content to use wake locks.
     708           0 :     hal::ModifyWakeLock(aTopic, aLockAdjust, aHiddenAdjust, aProcessID);
     709           0 :     return IPC_OK();
     710             :   }
     711             : 
     712             :   virtual mozilla::ipc::IPCResult
     713           0 :   RecvEnableWakeLockNotifications() override
     714             :   {
     715             :     // We allow arbitrary content to use wake locks.
     716           0 :     hal::RegisterWakeLockObserver(this);
     717           0 :     return IPC_OK();
     718             :   }
     719             : 
     720             :   virtual mozilla::ipc::IPCResult
     721           0 :   RecvDisableWakeLockNotifications() override
     722             :   {
     723           0 :     hal::UnregisterWakeLockObserver(this);
     724           0 :     return IPC_OK();
     725             :   }
     726             : 
     727             :   virtual mozilla::ipc::IPCResult
     728           0 :   RecvGetWakeLockInfo(const nsString &aTopic, WakeLockInformation *aWakeLockInfo) override
     729             :   {
     730           0 :     hal::GetWakeLockInfo(aTopic, aWakeLockInfo);
     731           0 :     return IPC_OK();
     732             :   }
     733             : 
     734           0 :   void Notify(const WakeLockInformation& aWakeLockInfo) override
     735             :   {
     736           0 :     Unused << SendNotifyWakeLockChange(aWakeLockInfo);
     737           0 :   }
     738             : 
     739             :   virtual mozilla::ipc::IPCResult
     740           0 :   RecvEnableSwitchNotifications(const SwitchDevice& aDevice) override
     741             :   {
     742             :     // Content has no reason to listen to switch events currently.
     743           0 :     hal::RegisterSwitchObserver(aDevice, this);
     744           0 :     return IPC_OK();
     745             :   }
     746             : 
     747             :   virtual mozilla::ipc::IPCResult
     748           0 :   RecvDisableSwitchNotifications(const SwitchDevice& aDevice) override
     749             :   {
     750           0 :     hal::UnregisterSwitchObserver(aDevice, this);
     751           0 :     return IPC_OK();
     752             :   }
     753             : 
     754           0 :   void Notify(const SwitchEvent& aSwitchEvent) override
     755             :   {
     756           0 :     Unused << SendNotifySwitchChange(aSwitchEvent);
     757           0 :   }
     758             : 
     759             :   virtual mozilla::ipc::IPCResult
     760           0 :   RecvGetCurrentSwitchState(const SwitchDevice& aDevice, hal::SwitchState *aState) override
     761             :   {
     762             :     // Content has no reason to listen to switch events currently.
     763           0 :     *aState = hal::GetCurrentSwitchState(aDevice);
     764           0 :     return IPC_OK();
     765             :   }
     766             : 
     767           0 :   void Notify(const int64_t& aClockDeltaMS) override
     768             :   {
     769           0 :     Unused << SendNotifySystemClockChange(aClockDeltaMS);
     770           0 :   }
     771             : 
     772           0 :   void Notify(const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo) override
     773             :   {
     774           0 :     Unused << SendNotifySystemTimezoneChange(aSystemTimezoneChangeInfo);
     775           0 :   }
     776             : 
     777             :   virtual mozilla::ipc::IPCResult
     778           0 :   RecvFactoryReset(const nsString& aReason) override
     779             :   {
     780           0 :     FactoryResetReason reason = FactoryResetReason::Normal;
     781           0 :     if (aReason.EqualsLiteral("normal")) {
     782           0 :       reason = FactoryResetReason::Normal;
     783           0 :     } else if (aReason.EqualsLiteral("wipe")) {
     784           0 :       reason = FactoryResetReason::Wipe;
     785           0 :     } else if (aReason.EqualsLiteral("root")) {
     786           0 :       reason = FactoryResetReason::Root;
     787             :     } else {
     788             :       // Invalid factory reset reason. That should never happen.
     789           0 :       return IPC_FAIL_NO_REASON(this);
     790             :     }
     791             : 
     792           0 :     hal::FactoryReset(reason);
     793           0 :     return IPC_OK();
     794             :   }
     795             : };
     796             : 
     797           2 : class HalChild : public PHalChild {
     798             : public:
     799             :   virtual void
     800           0 :   ActorDestroy(ActorDestroyReason aWhy) override
     801             :   {
     802           0 :     sHalChildDestroyed = true;
     803           0 :   }
     804             : 
     805             :   virtual mozilla::ipc::IPCResult
     806           0 :   RecvNotifyBatteryChange(const BatteryInformation& aBatteryInfo) override {
     807           0 :     hal::NotifyBatteryChange(aBatteryInfo);
     808           0 :     return IPC_OK();
     809             :   }
     810             : 
     811             :   virtual mozilla::ipc::IPCResult
     812             :   RecvNotifySensorChange(const hal::SensorData &aSensorData) override;
     813             : 
     814             :   virtual mozilla::ipc::IPCResult
     815           0 :   RecvNotifyNetworkChange(const NetworkInformation& aNetworkInfo) override {
     816           0 :     hal::NotifyNetworkChange(aNetworkInfo);
     817           0 :     return IPC_OK();
     818             :   }
     819             : 
     820             :   virtual mozilla::ipc::IPCResult
     821           0 :   RecvNotifyWakeLockChange(const WakeLockInformation& aWakeLockInfo) override {
     822           0 :     hal::NotifyWakeLockChange(aWakeLockInfo);
     823           0 :     return IPC_OK();
     824             :   }
     825             : 
     826             :   virtual mozilla::ipc::IPCResult
     827           0 :   RecvNotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration) override {
     828           0 :     hal::NotifyScreenConfigurationChange(aScreenConfiguration);
     829           0 :     return IPC_OK();
     830             :   }
     831             : 
     832             :   virtual mozilla::ipc::IPCResult
     833           0 :   RecvNotifySwitchChange(const mozilla::hal::SwitchEvent& aEvent) override {
     834           0 :     hal::NotifySwitchChange(aEvent);
     835           0 :     return IPC_OK();
     836             :   }
     837             : 
     838             :   virtual mozilla::ipc::IPCResult
     839           0 :   RecvNotifySystemClockChange(const int64_t& aClockDeltaMS) override {
     840           0 :     hal::NotifySystemClockChange(aClockDeltaMS);
     841           0 :     return IPC_OK();
     842             :   }
     843             : 
     844             :   virtual mozilla::ipc::IPCResult
     845           0 :   RecvNotifySystemTimezoneChange(
     846             :     const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo) override {
     847           0 :     hal::NotifySystemTimezoneChange(aSystemTimezoneChangeInfo);
     848           0 :     return IPC_OK();
     849             :   }
     850             : };
     851             : 
     852             : mozilla::ipc::IPCResult
     853           0 : HalChild::RecvNotifySensorChange(const hal::SensorData &aSensorData) {
     854           0 :   hal::NotifySensorChange(aSensorData);
     855             : 
     856           0 :   return IPC_OK();
     857             : }
     858             : 
     859           2 : PHalChild* CreateHalChild() {
     860           2 :   return new HalChild();
     861             : }
     862             : 
     863           1 : PHalParent* CreateHalParent() {
     864           1 :   return new HalParent();
     865             : }
     866             : 
     867             : } // namespace hal_sandbox
     868             : } // namespace mozilla

Generated by: LCOV version 1.13