Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/hal/Hal.cpp
Line
Count
Source (jump to first uncovered line)
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
9
#include "HalImpl.h"
10
#include "HalLog.h"
11
#include "HalSandbox.h"
12
#include "HalWakeLockInternal.h"
13
#include "nsIDOMWindow.h"
14
#include "nsIDocument.h"
15
#include "nsIDocShell.h"
16
#include "nsITabChild.h"
17
#include "nsIWebNavigation.h"
18
#include "nsThreadUtils.h"
19
#include "nsXULAppAPI.h"
20
#include "nsPIDOMWindow.h"
21
#include "nsJSUtils.h"
22
#include "mozilla/ClearOnShutdown.h"
23
#include "mozilla/Observer.h"
24
#include "mozilla/dom/ContentChild.h"
25
#include "WindowIdentifier.h"
26
27
#ifdef XP_WIN
28
#include <process.h>
29
#define getpid _getpid
30
#endif
31
32
using namespace mozilla::services;
33
using namespace mozilla::dom;
34
35
#define PROXY_IF_SANDBOXED(_call)                 \
36
0
  do {                                            \
37
0
    if (InSandbox()) {                            \
38
0
      if (!hal_sandbox::HalChildDestroyed()) {    \
39
0
        hal_sandbox::_call;                       \
40
0
      }                                           \
41
0
    } else {                                      \
42
0
      hal_impl::_call;                            \
43
0
    }                                             \
44
0
  } while (0)
45
46
#define RETURN_PROXY_IF_SANDBOXED(_call, defValue)\
47
0
  do {                                            \
48
0
    if (InSandbox()) {                            \
49
0
      if (hal_sandbox::HalChildDestroyed()) {     \
50
0
        return defValue;                          \
51
0
      }                                           \
52
0
      return hal_sandbox::_call;                  \
53
0
    } else {                                      \
54
0
      return hal_impl::_call;                     \
55
0
    }                                             \
56
0
  } while (0)
57
58
namespace mozilla {
59
namespace hal {
60
61
static bool sInitialized = false;
62
63
mozilla::LogModule *
64
GetHalLog()
65
0
{
66
0
  static mozilla::LazyLogModule sHalLog("hal");
67
0
  return sHalLog;
68
0
}
69
70
namespace {
71
72
void
73
AssertMainThread()
74
0
{
75
0
  MOZ_ASSERT(NS_IsMainThread());
76
0
}
77
78
bool
79
InSandbox()
80
0
{
81
0
  return GeckoProcessType_Content == XRE_GetProcessType();
82
0
}
83
84
bool
85
WindowIsActive(nsPIDOMWindowInner* aWindow)
86
0
{
87
0
  nsIDocument* document = aWindow->GetDoc();
88
0
  NS_ENSURE_TRUE(document, false);
89
0
90
0
  return !document->Hidden();
91
0
}
92
93
StaticAutoPtr<WindowIdentifier::IDArrayType> gLastIDToVibrate;
94
95
static void
96
RecordLastIDToVibrate(const WindowIdentifier& aId)
97
0
{
98
0
  if (!InSandbox()) {
99
0
    *gLastIDToVibrate = aId.AsArray();
100
0
  }
101
0
}
102
103
static bool
104
MayCancelVibration(const WindowIdentifier& aId)
105
0
{
106
0
  // Although only active windows may start vibrations, a window may
107
0
  // cancel its own vibration even if it's no longer active.
108
0
  //
109
0
  // After a window is marked as inactive, it sends a CancelVibrate
110
0
  // request.  We want this request to cancel a playing vibration
111
0
  // started by that window, so we certainly don't want to reject the
112
0
  // cancellation request because the window is now inactive.
113
0
  //
114
0
  // But it could be the case that, after this window became inactive,
115
0
  // some other window came along and started a vibration.  We don't
116
0
  // want this window's cancellation request to cancel that window's
117
0
  // actively-playing vibration!
118
0
  //
119
0
  // To solve this problem, we keep track of the id of the last window
120
0
  // to start a vibration, and only accepts cancellation requests from
121
0
  // the same window.  All other cancellation requests are ignored.
122
0
123
0
  return InSandbox() || (*gLastIDToVibrate == aId.AsArray());
124
0
}
125
126
} // namespace
127
128
void
129
Vibrate(const nsTArray<uint32_t>& pattern, nsPIDOMWindowInner* window)
130
0
{
131
0
  Vibrate(pattern, WindowIdentifier(window));
132
0
}
133
134
void
135
Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
136
0
{
137
0
  AssertMainThread();
138
0
139
0
  // Only active windows may start vibrations.  If |id| hasn't gone
140
0
  // through the IPC layer -- that is, if our caller is the outside
141
0
  // world, not hal_proxy -- check whether the window is active.  If
142
0
  // |id| has gone through IPC, don't check the window's visibility;
143
0
  // only the window corresponding to the bottommost process has its
144
0
  // visibility state set correctly.
145
0
  if (!id.HasTraveledThroughIPC() && !WindowIsActive(id.GetWindow())) {
146
0
    HAL_LOG("Vibrate: Window is inactive, dropping vibrate.");
147
0
    return;
148
0
  }
149
0
150
0
  RecordLastIDToVibrate(id);
151
0
152
0
  // Don't forward our ID if we are not in the sandbox, because hal_impl
153
0
  // doesn't need it, and we don't want it to be tempted to read it.  The
154
0
  // empty identifier will assert if it's used.
155
0
  PROXY_IF_SANDBOXED(Vibrate(pattern, InSandbox() ? id : WindowIdentifier()));
156
0
}
157
158
void
159
CancelVibrate(nsPIDOMWindowInner* window)
160
0
{
161
0
  CancelVibrate(WindowIdentifier(window));
162
0
}
163
164
void
165
CancelVibrate(const WindowIdentifier &id)
166
0
{
167
0
  AssertMainThread();
168
0
169
0
  if (MayCancelVibration(id)) {
170
0
    // Don't forward our ID if we are not in the sandbox, because hal_impl
171
0
    // doesn't need it, and we don't want it to be tempted to read it.  The
172
0
    // empty identifier will assert if it's used.
173
0
    PROXY_IF_SANDBOXED(CancelVibrate(InSandbox() ? id : WindowIdentifier()));
174
0
  }
175
0
}
176
177
template <class InfoType>
178
class ObserversManager
179
{
180
public:
181
0
  void AddObserver(Observer<InfoType>* aObserver) {
182
0
    mObservers.AddObserver(aObserver);
183
0
184
0
    if (mObservers.Length() == 1) {
185
0
      EnableNotifications();
186
0
    }
187
0
  }
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::BatteryInformation>::AddObserver(mozilla::Observer<mozilla::hal::BatteryInformation>*)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::NetworkInformation>::AddObserver(mozilla::Observer<mozilla::hal::NetworkInformation>*)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::WakeLockInformation>::AddObserver(mozilla::Observer<mozilla::hal::WakeLockInformation>*)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::ScreenConfiguration>::AddObserver(mozilla::Observer<mozilla::hal::ScreenConfiguration>*)
188
189
0
  void RemoveObserver(Observer<InfoType>* aObserver) {
190
0
    bool removed = mObservers.RemoveObserver(aObserver);
191
0
    if (!removed) {
192
0
      return;
193
0
    }
194
0
195
0
    if (mObservers.Length() == 0) {
196
0
      DisableNotifications();
197
0
      OnNotificationsDisabled();
198
0
    }
199
0
  }
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::BatteryInformation>::RemoveObserver(mozilla::Observer<mozilla::hal::BatteryInformation>*)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::NetworkInformation>::RemoveObserver(mozilla::Observer<mozilla::hal::NetworkInformation>*)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::WakeLockInformation>::RemoveObserver(mozilla::Observer<mozilla::hal::WakeLockInformation>*)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::ScreenConfiguration>::RemoveObserver(mozilla::Observer<mozilla::hal::ScreenConfiguration>*)
200
201
0
  void BroadcastInformation(const InfoType& aInfo) {
202
0
    mObservers.Broadcast(aInfo);
203
0
  }
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::BatteryInformation>::BroadcastInformation(mozilla::hal::BatteryInformation const&)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::NetworkInformation>::BroadcastInformation(mozilla::hal::NetworkInformation const&)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::WakeLockInformation>::BroadcastInformation(mozilla::hal::WakeLockInformation const&)
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::ScreenConfiguration>::BroadcastInformation(mozilla::hal::ScreenConfiguration const&)
204
205
protected:
206
0
  ~ObserversManager() {
207
0
    MOZ_ASSERT(mObservers.Length() == 0);
208
0
  }
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::BatteryInformation>::~ObserversManager()
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::NetworkInformation>::~ObserversManager()
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::WakeLockInformation>::~ObserversManager()
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::ScreenConfiguration>::~ObserversManager()
209
210
  virtual void EnableNotifications() = 0;
211
  virtual void DisableNotifications() = 0;
212
0
  virtual void OnNotificationsDisabled() {}
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::BatteryInformation>::OnNotificationsDisabled()
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::NetworkInformation>::OnNotificationsDisabled()
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::WakeLockInformation>::OnNotificationsDisabled()
Unexecuted instantiation: mozilla::hal::ObserversManager<mozilla::hal::ScreenConfiguration>::OnNotificationsDisabled()
213
214
private:
215
  mozilla::ObserverList<InfoType> mObservers;
216
};
217
218
template <class InfoType>
219
class CachingObserversManager : public ObserversManager<InfoType>
220
{
221
public:
222
0
  InfoType GetCurrentInformation() {
223
0
    if (mHasValidCache) {
224
0
      return mInfo;
225
0
    }
226
0
227
0
    GetCurrentInformationInternal(&mInfo);
228
0
    mHasValidCache = true;
229
0
    return mInfo;
230
0
  }
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::BatteryInformation>::GetCurrentInformation()
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::NetworkInformation>::GetCurrentInformation()
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::ScreenConfiguration>::GetCurrentInformation()
231
232
0
  void CacheInformation(const InfoType& aInfo) {
233
0
    mHasValidCache = true;
234
0
    mInfo = aInfo;
235
0
  }
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::BatteryInformation>::CacheInformation(mozilla::hal::BatteryInformation const&)
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::NetworkInformation>::CacheInformation(mozilla::hal::NetworkInformation const&)
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::ScreenConfiguration>::CacheInformation(mozilla::hal::ScreenConfiguration const&)
236
237
0
  void BroadcastCachedInformation() {
238
0
    this->BroadcastInformation(mInfo);
239
0
  }
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::BatteryInformation>::BroadcastCachedInformation()
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::NetworkInformation>::BroadcastCachedInformation()
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::ScreenConfiguration>::BroadcastCachedInformation()
240
241
protected:
242
  virtual void GetCurrentInformationInternal(InfoType*) = 0;
243
244
0
  void OnNotificationsDisabled() override {
245
0
    mHasValidCache = false;
246
0
  }
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::BatteryInformation>::OnNotificationsDisabled()
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::NetworkInformation>::OnNotificationsDisabled()
Unexecuted instantiation: mozilla::hal::CachingObserversManager<mozilla::hal::ScreenConfiguration>::OnNotificationsDisabled()
247
248
private:
249
  InfoType                mInfo;
250
  bool                    mHasValidCache;
251
};
252
253
class BatteryObserversManager final
254
  : public CachingObserversManager<BatteryInformation>
255
{
256
protected:
257
0
  void EnableNotifications() override {
258
0
    PROXY_IF_SANDBOXED(EnableBatteryNotifications());
259
0
  }
260
261
0
  void DisableNotifications() override {
262
0
    PROXY_IF_SANDBOXED(DisableBatteryNotifications());
263
0
  }
264
265
0
  void GetCurrentInformationInternal(BatteryInformation* aInfo) override {
266
0
    PROXY_IF_SANDBOXED(GetCurrentBatteryInformation(aInfo));
267
0
  }
268
};
269
270
class NetworkObserversManager final
271
  : public CachingObserversManager<NetworkInformation>
272
{
273
protected:
274
0
  void EnableNotifications() override {
275
0
    PROXY_IF_SANDBOXED(EnableNetworkNotifications());
276
0
  }
277
278
0
  void DisableNotifications() override {
279
0
    PROXY_IF_SANDBOXED(DisableNetworkNotifications());
280
0
  }
281
282
0
  void GetCurrentInformationInternal(NetworkInformation* aInfo) override {
283
0
    PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo));
284
0
  }
285
};
286
287
class WakeLockObserversManager final
288
  : public ObserversManager<WakeLockInformation>
289
{
290
protected:
291
0
  void EnableNotifications() override {
292
0
    PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
293
0
  }
294
295
0
  void DisableNotifications() override {
296
0
    PROXY_IF_SANDBOXED(DisableWakeLockNotifications());
297
0
  }
298
};
299
300
class ScreenConfigurationObserversManager final
301
  : public CachingObserversManager<ScreenConfiguration>
302
{
303
protected:
304
0
  void EnableNotifications() override {
305
0
    PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
306
0
  }
307
308
0
  void DisableNotifications() override {
309
0
    PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
310
0
  }
311
312
0
  void GetCurrentInformationInternal(ScreenConfiguration* aInfo) override {
313
0
    PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo));
314
0
  }
315
};
316
317
typedef mozilla::ObserverList<SensorData> SensorObserverList;
318
StaticAutoPtr<SensorObserverList> sSensorObservers[NUM_SENSOR_TYPE];
319
320
static SensorObserverList*
321
0
GetSensorObservers(SensorType sensor_type) {
322
0
  AssertMainThread();
323
0
  MOZ_ASSERT(sensor_type < NUM_SENSOR_TYPE);
324
0
325
0
  if (!sSensorObservers[sensor_type]) {
326
0
    sSensorObservers[sensor_type] = new SensorObserverList();
327
0
  }
328
0
329
0
  return sSensorObservers[sensor_type];
330
0
}
331
332
#define MOZ_IMPL_HAL_OBSERVER(name_)                          \
333
StaticAutoPtr<name_##ObserversManager> s##name_##Observers;   \
334
                                                              \
335
static name_##ObserversManager*                               \
336
0
name_##Observers()                                            \
337
0
{                                                             \
338
0
  AssertMainThread();                                         \
339
0
                                                              \
340
0
  if (!s##name_##Observers) {                                 \
341
0
    MOZ_ASSERT(sInitialized);                                 \
342
0
    s##name_##Observers = new name_##ObserversManager();      \
343
0
  }                                                           \
344
0
                                                              \
345
0
  return s##name_##Observers;                                 \
346
0
}                                                             \
Unexecuted instantiation: Hal.cpp:mozilla::hal::BatteryObservers()
Unexecuted instantiation: Hal.cpp:mozilla::hal::NetworkObservers()
Unexecuted instantiation: Hal.cpp:mozilla::hal::WakeLockObservers()
Unexecuted instantiation: Hal.cpp:mozilla::hal::ScreenConfigurationObservers()
347
                                                              \
348
void                                                          \
349
0
Register##name_##Observer(name_##Observer* aObserver)         \
350
0
{                                                             \
351
0
  AssertMainThread();                                         \
352
0
  name_##Observers()->AddObserver(aObserver);                 \
353
0
}                                                             \
Unexecuted instantiation: mozilla::hal::RegisterBatteryObserver(mozilla::Observer<mozilla::hal::BatteryInformation>*)
Unexecuted instantiation: mozilla::hal::RegisterNetworkObserver(mozilla::Observer<mozilla::hal::NetworkInformation>*)
Unexecuted instantiation: mozilla::hal::RegisterWakeLockObserver(mozilla::Observer<mozilla::hal::WakeLockInformation>*)
Unexecuted instantiation: mozilla::hal::RegisterScreenConfigurationObserver(mozilla::Observer<mozilla::hal::ScreenConfiguration>*)
354
                                                              \
355
void                                                          \
356
0
Unregister##name_##Observer(name_##Observer* aObserver)       \
357
0
{                                                             \
358
0
  AssertMainThread();                                         \
359
0
  name_##Observers()->RemoveObserver(aObserver);              \
360
0
}
Unexecuted instantiation: mozilla::hal::UnregisterBatteryObserver(mozilla::Observer<mozilla::hal::BatteryInformation>*)
Unexecuted instantiation: mozilla::hal::UnregisterNetworkObserver(mozilla::Observer<mozilla::hal::NetworkInformation>*)
Unexecuted instantiation: mozilla::hal::UnregisterWakeLockObserver(mozilla::Observer<mozilla::hal::WakeLockInformation>*)
Unexecuted instantiation: mozilla::hal::UnregisterScreenConfigurationObserver(mozilla::Observer<mozilla::hal::ScreenConfiguration>*)
361
362
MOZ_IMPL_HAL_OBSERVER(Battery)
363
364
void
365
GetCurrentBatteryInformation(BatteryInformation* aInfo)
366
0
{
367
0
  *aInfo = BatteryObservers()->GetCurrentInformation();
368
0
}
369
370
void
371
NotifyBatteryChange(const BatteryInformation& aInfo)
372
0
{
373
0
  BatteryObservers()->CacheInformation(aInfo);
374
0
  BatteryObservers()->BroadcastCachedInformation();
375
0
}
376
377
void
378
0
EnableSensorNotifications(SensorType aSensor) {
379
0
  AssertMainThread();
380
0
  PROXY_IF_SANDBOXED(EnableSensorNotifications(aSensor));
381
0
}
382
383
void
384
0
DisableSensorNotifications(SensorType aSensor) {
385
0
  AssertMainThread();
386
0
  PROXY_IF_SANDBOXED(DisableSensorNotifications(aSensor));
387
0
}
388
389
void
390
0
RegisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
391
0
  SensorObserverList* observers = GetSensorObservers(aSensor);
392
0
393
0
  observers->AddObserver(aObserver);
394
0
  if (observers->Length() == 1) {
395
0
    EnableSensorNotifications(aSensor);
396
0
  }
397
0
}
398
399
void
400
0
UnregisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
401
0
  SensorObserverList* observers = GetSensorObservers(aSensor);
402
0
  if (!observers->RemoveObserver(aObserver) || observers->Length() > 0) {
403
0
    return;
404
0
  }
405
0
  DisableSensorNotifications(aSensor);
406
0
}
407
408
void
409
0
NotifySensorChange(const SensorData &aSensorData) {
410
0
  SensorObserverList* observers = GetSensorObservers(aSensorData.sensor());
411
0
412
0
  observers->Broadcast(aSensorData);
413
0
}
414
415
MOZ_IMPL_HAL_OBSERVER(Network)
416
417
void
418
GetCurrentNetworkInformation(NetworkInformation* aInfo)
419
0
{
420
0
  *aInfo = NetworkObservers()->GetCurrentInformation();
421
0
}
422
423
void
424
NotifyNetworkChange(const NetworkInformation& aInfo)
425
0
{
426
0
  NetworkObservers()->CacheInformation(aInfo);
427
0
  NetworkObservers()->BroadcastCachedInformation();
428
0
}
429
430
MOZ_IMPL_HAL_OBSERVER(WakeLock)
431
432
void
433
ModifyWakeLock(const nsAString& aTopic,
434
               WakeLockControl aLockAdjust,
435
               WakeLockControl aHiddenAdjust,
436
               uint64_t aProcessID /* = CONTENT_PROCESS_ID_UNKNOWN */)
437
0
{
438
0
  AssertMainThread();
439
0
440
0
  if (aProcessID == CONTENT_PROCESS_ID_UNKNOWN) {
441
0
    aProcessID = InSandbox() ? ContentChild::GetSingleton()->GetID() :
442
0
                               CONTENT_PROCESS_ID_MAIN;
443
0
  }
444
0
445
0
  PROXY_IF_SANDBOXED(ModifyWakeLock(aTopic, aLockAdjust,
446
0
                                    aHiddenAdjust, aProcessID));
447
0
}
448
449
void
450
GetWakeLockInfo(const nsAString& aTopic, WakeLockInformation* aWakeLockInfo)
451
0
{
452
0
  AssertMainThread();
453
0
  PROXY_IF_SANDBOXED(GetWakeLockInfo(aTopic, aWakeLockInfo));
454
0
}
455
456
void
457
NotifyWakeLockChange(const WakeLockInformation& aInfo)
458
0
{
459
0
  AssertMainThread();
460
0
  WakeLockObservers()->BroadcastInformation(aInfo);
461
0
}
462
463
MOZ_IMPL_HAL_OBSERVER(ScreenConfiguration)
464
465
void
466
GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
467
0
{
468
0
  *aScreenConfiguration =
469
0
    ScreenConfigurationObservers()->GetCurrentInformation();
470
0
}
471
472
void
473
NotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration)
474
0
{
475
0
  ScreenConfigurationObservers()->CacheInformation(aScreenConfiguration);
476
0
  ScreenConfigurationObservers()->BroadcastCachedInformation();
477
0
}
478
479
bool
480
LockScreenOrientation(const ScreenOrientation& aOrientation)
481
0
{
482
0
  AssertMainThread();
483
0
  RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation), false);
484
0
}
485
486
void
487
UnlockScreenOrientation()
488
0
{
489
0
  AssertMainThread();
490
0
  PROXY_IF_SANDBOXED(UnlockScreenOrientation());
491
0
}
492
493
bool
494
SetProcessPrioritySupported()
495
0
{
496
0
  RETURN_PROXY_IF_SANDBOXED(SetProcessPrioritySupported(), false);
497
0
}
498
499
void
500
SetProcessPriority(int aPid, ProcessPriority aPriority)
501
0
{
502
0
  // n.b. The sandboxed implementation crashes; SetProcessPriority works only
503
0
  // from the main process.
504
0
  PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority));
505
0
}
506
507
// From HalTypes.h.
508
const char*
509
ProcessPriorityToString(ProcessPriority aPriority)
510
0
{
511
0
  switch (aPriority) {
512
0
  case PROCESS_PRIORITY_MASTER:
513
0
    return "MASTER";
514
0
  case PROCESS_PRIORITY_PREALLOC:
515
0
    return "PREALLOC";
516
0
  case PROCESS_PRIORITY_FOREGROUND_HIGH:
517
0
    return "FOREGROUND_HIGH";
518
0
  case PROCESS_PRIORITY_FOREGROUND:
519
0
    return "FOREGROUND";
520
0
  case PROCESS_PRIORITY_FOREGROUND_KEYBOARD:
521
0
    return "FOREGROUND_KEYBOARD";
522
0
  case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
523
0
    return "BACKGROUND_PERCEIVABLE";
524
0
  case PROCESS_PRIORITY_BACKGROUND:
525
0
    return "BACKGROUND";
526
0
  case PROCESS_PRIORITY_UNKNOWN:
527
0
    return "UNKNOWN";
528
0
  default:
529
0
    MOZ_ASSERT(false);
530
0
    return "???";
531
0
  }
532
0
}
533
534
void
535
Init()
536
0
{
537
0
  MOZ_ASSERT(!sInitialized);
538
0
539
0
  if (!InSandbox()) {
540
0
    gLastIDToVibrate = new WindowIdentifier::IDArrayType();
541
0
  }
542
0
543
0
  WakeLockInit();
544
0
545
0
  sInitialized = true;
546
0
}
547
548
void
549
Shutdown()
550
0
{
551
0
  MOZ_ASSERT(sInitialized);
552
0
553
0
  gLastIDToVibrate = nullptr;
554
0
555
0
  sBatteryObservers = nullptr;
556
0
  sNetworkObservers = nullptr;
557
0
  sWakeLockObservers = nullptr;
558
0
  sScreenConfigurationObservers = nullptr;
559
0
560
0
  for (auto& sensorObserver : sSensorObservers) {
561
0
    sensorObserver = nullptr;
562
0
  }
563
0
564
0
  sInitialized = false;
565
0
}
566
567
} // namespace hal
568
} // namespace mozilla