hal/Hal.cpp

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set sw=2 ts=8 et ft=cpp : */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "Hal.h"
michael@0 8 #include "HalImpl.h"
michael@0 9 #include "HalSandbox.h"
michael@0 10 #include "nsThreadUtils.h"
michael@0 11 #include "nsXULAppAPI.h"
michael@0 12 #include "mozilla/Observer.h"
michael@0 13 #include "nsIDocument.h"
michael@0 14 #include "nsIDOMDocument.h"
michael@0 15 #include "nsPIDOMWindow.h"
michael@0 16 #include "nsIDOMWindow.h"
michael@0 17 #include "mozilla/Services.h"
michael@0 18 #include "nsIWebNavigation.h"
michael@0 19 #include "nsITabChild.h"
michael@0 20 #include "nsIDocShell.h"
michael@0 21 #include "mozilla/StaticPtr.h"
michael@0 22 #include "mozilla/ClearOnShutdown.h"
michael@0 23 #include "WindowIdentifier.h"
michael@0 24 #include "mozilla/dom/ScreenOrientation.h"
michael@0 25 #include "mozilla/dom/ContentChild.h"
michael@0 26 #include "mozilla/dom/ContentParent.h"
michael@0 27
michael@0 28 #ifdef XP_WIN
michael@0 29 #include <process.h>
michael@0 30 #define getpid _getpid
michael@0 31 #endif
michael@0 32
michael@0 33 using namespace mozilla::services;
michael@0 34 using namespace mozilla::dom;
michael@0 35
michael@0 36 #define PROXY_IF_SANDBOXED(_call) \
michael@0 37 do { \
michael@0 38 if (InSandbox()) { \
michael@0 39 if (!hal_sandbox::HalChildDestroyed()) { \
michael@0 40 hal_sandbox::_call; \
michael@0 41 } \
michael@0 42 } else { \
michael@0 43 hal_impl::_call; \
michael@0 44 } \
michael@0 45 } while (0)
michael@0 46
michael@0 47 #define RETURN_PROXY_IF_SANDBOXED(_call, defValue)\
michael@0 48 do { \
michael@0 49 if (InSandbox()) { \
michael@0 50 if (hal_sandbox::HalChildDestroyed()) { \
michael@0 51 return defValue; \
michael@0 52 } \
michael@0 53 return hal_sandbox::_call; \
michael@0 54 } else { \
michael@0 55 return hal_impl::_call; \
michael@0 56 } \
michael@0 57 } while (0)
michael@0 58
michael@0 59 namespace mozilla {
michael@0 60 namespace hal {
michael@0 61
michael@0 62 PRLogModuleInfo *
michael@0 63 GetHalLog()
michael@0 64 {
michael@0 65 static PRLogModuleInfo *sHalLog;
michael@0 66 if (!sHalLog) {
michael@0 67 sHalLog = PR_NewLogModule("hal");
michael@0 68 }
michael@0 69 return sHalLog;
michael@0 70 }
michael@0 71
michael@0 72 namespace {
michael@0 73
michael@0 74 void
michael@0 75 AssertMainThread()
michael@0 76 {
michael@0 77 MOZ_ASSERT(NS_IsMainThread());
michael@0 78 }
michael@0 79
michael@0 80 bool
michael@0 81 InSandbox()
michael@0 82 {
michael@0 83 return GeckoProcessType_Content == XRE_GetProcessType();
michael@0 84 }
michael@0 85
michael@0 86 void
michael@0 87 AssertMainProcess()
michael@0 88 {
michael@0 89 MOZ_ASSERT(GeckoProcessType_Default == XRE_GetProcessType());
michael@0 90 }
michael@0 91
michael@0 92 bool
michael@0 93 WindowIsActive(nsIDOMWindow* aWindow)
michael@0 94 {
michael@0 95 nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
michael@0 96 NS_ENSURE_TRUE(window, false);
michael@0 97
michael@0 98 nsIDocument* document = window->GetDoc();
michael@0 99 NS_ENSURE_TRUE(document, false);
michael@0 100
michael@0 101 return !document->Hidden();
michael@0 102 }
michael@0 103
michael@0 104 StaticAutoPtr<WindowIdentifier::IDArrayType> gLastIDToVibrate;
michael@0 105
michael@0 106 void InitLastIDToVibrate()
michael@0 107 {
michael@0 108 gLastIDToVibrate = new WindowIdentifier::IDArrayType();
michael@0 109 ClearOnShutdown(&gLastIDToVibrate);
michael@0 110 }
michael@0 111
michael@0 112 } // anonymous namespace
michael@0 113
michael@0 114 void
michael@0 115 Vibrate(const nsTArray<uint32_t>& pattern, nsIDOMWindow* window)
michael@0 116 {
michael@0 117 Vibrate(pattern, WindowIdentifier(window));
michael@0 118 }
michael@0 119
michael@0 120 void
michael@0 121 Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
michael@0 122 {
michael@0 123 AssertMainThread();
michael@0 124
michael@0 125 // Only active windows may start vibrations. If |id| hasn't gone
michael@0 126 // through the IPC layer -- that is, if our caller is the outside
michael@0 127 // world, not hal_proxy -- check whether the window is active. If
michael@0 128 // |id| has gone through IPC, don't check the window's visibility;
michael@0 129 // only the window corresponding to the bottommost process has its
michael@0 130 // visibility state set correctly.
michael@0 131 if (!id.HasTraveledThroughIPC() && !WindowIsActive(id.GetWindow())) {
michael@0 132 HAL_LOG(("Vibrate: Window is inactive, dropping vibrate."));
michael@0 133 return;
michael@0 134 }
michael@0 135
michael@0 136 if (!InSandbox()) {
michael@0 137 if (!gLastIDToVibrate) {
michael@0 138 InitLastIDToVibrate();
michael@0 139 }
michael@0 140 *gLastIDToVibrate = id.AsArray();
michael@0 141 }
michael@0 142
michael@0 143 // Don't forward our ID if we are not in the sandbox, because hal_impl
michael@0 144 // doesn't need it, and we don't want it to be tempted to read it. The
michael@0 145 // empty identifier will assert if it's used.
michael@0 146 PROXY_IF_SANDBOXED(Vibrate(pattern, InSandbox() ? id : WindowIdentifier()));
michael@0 147 }
michael@0 148
michael@0 149 void
michael@0 150 CancelVibrate(nsIDOMWindow* window)
michael@0 151 {
michael@0 152 CancelVibrate(WindowIdentifier(window));
michael@0 153 }
michael@0 154
michael@0 155 void
michael@0 156 CancelVibrate(const WindowIdentifier &id)
michael@0 157 {
michael@0 158 AssertMainThread();
michael@0 159
michael@0 160 // Although only active windows may start vibrations, a window may
michael@0 161 // cancel its own vibration even if it's no longer active.
michael@0 162 //
michael@0 163 // After a window is marked as inactive, it sends a CancelVibrate
michael@0 164 // request. We want this request to cancel a playing vibration
michael@0 165 // started by that window, so we certainly don't want to reject the
michael@0 166 // cancellation request because the window is now inactive.
michael@0 167 //
michael@0 168 // But it could be the case that, after this window became inactive,
michael@0 169 // some other window came along and started a vibration. We don't
michael@0 170 // want this window's cancellation request to cancel that window's
michael@0 171 // actively-playing vibration!
michael@0 172 //
michael@0 173 // To solve this problem, we keep track of the id of the last window
michael@0 174 // to start a vibration, and only accepts cancellation requests from
michael@0 175 // the same window. All other cancellation requests are ignored.
michael@0 176
michael@0 177 if (InSandbox() || (gLastIDToVibrate && *gLastIDToVibrate == id.AsArray())) {
michael@0 178 // Don't forward our ID if we are not in the sandbox, because hal_impl
michael@0 179 // doesn't need it, and we don't want it to be tempted to read it. The
michael@0 180 // empty identifier will assert if it's used.
michael@0 181 PROXY_IF_SANDBOXED(CancelVibrate(InSandbox() ? id : WindowIdentifier()));
michael@0 182 }
michael@0 183 }
michael@0 184
michael@0 185 template <class InfoType>
michael@0 186 class ObserversManager
michael@0 187 {
michael@0 188 public:
michael@0 189 void AddObserver(Observer<InfoType>* aObserver) {
michael@0 190 if (!mObservers) {
michael@0 191 mObservers = new mozilla::ObserverList<InfoType>();
michael@0 192 }
michael@0 193
michael@0 194 mObservers->AddObserver(aObserver);
michael@0 195
michael@0 196 if (mObservers->Length() == 1) {
michael@0 197 EnableNotifications();
michael@0 198 }
michael@0 199 }
michael@0 200
michael@0 201 void RemoveObserver(Observer<InfoType>* aObserver) {
michael@0 202 bool removed = mObservers && mObservers->RemoveObserver(aObserver);
michael@0 203 if (!removed) {
michael@0 204 NS_WARNING("RemoveObserver() called for unregistered observer");
michael@0 205 return;
michael@0 206 }
michael@0 207
michael@0 208 if (mObservers->Length() == 0) {
michael@0 209 DisableNotifications();
michael@0 210
michael@0 211 OnNotificationsDisabled();
michael@0 212
michael@0 213 delete mObservers;
michael@0 214 mObservers = nullptr;
michael@0 215 }
michael@0 216 }
michael@0 217
michael@0 218 void BroadcastInformation(const InfoType& aInfo) {
michael@0 219 // It is possible for mObservers to be nullptr here on some platforms,
michael@0 220 // because a call to BroadcastInformation gets queued up asynchronously
michael@0 221 // while RemoveObserver is running (and before the notifications are
michael@0 222 // disabled). The queued call can then get run after mObservers has
michael@0 223 // been nulled out. See bug 757025.
michael@0 224 if (!mObservers) {
michael@0 225 return;
michael@0 226 }
michael@0 227 mObservers->Broadcast(aInfo);
michael@0 228 }
michael@0 229
michael@0 230 protected:
michael@0 231 virtual void EnableNotifications() = 0;
michael@0 232 virtual void DisableNotifications() = 0;
michael@0 233 virtual void OnNotificationsDisabled() {}
michael@0 234
michael@0 235 private:
michael@0 236 mozilla::ObserverList<InfoType>* mObservers;
michael@0 237 };
michael@0 238
michael@0 239 template <class InfoType>
michael@0 240 class CachingObserversManager : public ObserversManager<InfoType>
michael@0 241 {
michael@0 242 public:
michael@0 243 InfoType GetCurrentInformation() {
michael@0 244 if (mHasValidCache) {
michael@0 245 return mInfo;
michael@0 246 }
michael@0 247
michael@0 248 GetCurrentInformationInternal(&mInfo);
michael@0 249 mHasValidCache = true;
michael@0 250 return mInfo;
michael@0 251 }
michael@0 252
michael@0 253 void CacheInformation(const InfoType& aInfo) {
michael@0 254 mHasValidCache = true;
michael@0 255 mInfo = aInfo;
michael@0 256 }
michael@0 257
michael@0 258 void BroadcastCachedInformation() {
michael@0 259 this->BroadcastInformation(mInfo);
michael@0 260 }
michael@0 261
michael@0 262 protected:
michael@0 263 virtual void GetCurrentInformationInternal(InfoType*) = 0;
michael@0 264
michael@0 265 virtual void OnNotificationsDisabled() {
michael@0 266 mHasValidCache = false;
michael@0 267 }
michael@0 268
michael@0 269 private:
michael@0 270 InfoType mInfo;
michael@0 271 bool mHasValidCache;
michael@0 272 };
michael@0 273
michael@0 274 class BatteryObserversManager : public CachingObserversManager<BatteryInformation>
michael@0 275 {
michael@0 276 protected:
michael@0 277 void EnableNotifications() {
michael@0 278 PROXY_IF_SANDBOXED(EnableBatteryNotifications());
michael@0 279 }
michael@0 280
michael@0 281 void DisableNotifications() {
michael@0 282 PROXY_IF_SANDBOXED(DisableBatteryNotifications());
michael@0 283 }
michael@0 284
michael@0 285 void GetCurrentInformationInternal(BatteryInformation* aInfo) {
michael@0 286 PROXY_IF_SANDBOXED(GetCurrentBatteryInformation(aInfo));
michael@0 287 }
michael@0 288 };
michael@0 289
michael@0 290 static BatteryObserversManager sBatteryObservers;
michael@0 291
michael@0 292 class NetworkObserversManager : public CachingObserversManager<NetworkInformation>
michael@0 293 {
michael@0 294 protected:
michael@0 295 void EnableNotifications() {
michael@0 296 PROXY_IF_SANDBOXED(EnableNetworkNotifications());
michael@0 297 }
michael@0 298
michael@0 299 void DisableNotifications() {
michael@0 300 PROXY_IF_SANDBOXED(DisableNetworkNotifications());
michael@0 301 }
michael@0 302
michael@0 303 void GetCurrentInformationInternal(NetworkInformation* aInfo) {
michael@0 304 PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo));
michael@0 305 }
michael@0 306 };
michael@0 307
michael@0 308 static NetworkObserversManager sNetworkObservers;
michael@0 309
michael@0 310 class WakeLockObserversManager : public ObserversManager<WakeLockInformation>
michael@0 311 {
michael@0 312 protected:
michael@0 313 void EnableNotifications() {
michael@0 314 PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
michael@0 315 }
michael@0 316
michael@0 317 void DisableNotifications() {
michael@0 318 PROXY_IF_SANDBOXED(DisableWakeLockNotifications());
michael@0 319 }
michael@0 320 };
michael@0 321
michael@0 322 static WakeLockObserversManager sWakeLockObservers;
michael@0 323
michael@0 324 class ScreenConfigurationObserversManager : public CachingObserversManager<ScreenConfiguration>
michael@0 325 {
michael@0 326 protected:
michael@0 327 void EnableNotifications() {
michael@0 328 PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
michael@0 329 }
michael@0 330
michael@0 331 void DisableNotifications() {
michael@0 332 PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
michael@0 333 }
michael@0 334
michael@0 335 void GetCurrentInformationInternal(ScreenConfiguration* aInfo) {
michael@0 336 PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo));
michael@0 337 }
michael@0 338 };
michael@0 339
michael@0 340 static ScreenConfigurationObserversManager sScreenConfigurationObservers;
michael@0 341
michael@0 342 void
michael@0 343 RegisterBatteryObserver(BatteryObserver* aObserver)
michael@0 344 {
michael@0 345 AssertMainThread();
michael@0 346 sBatteryObservers.AddObserver(aObserver);
michael@0 347 }
michael@0 348
michael@0 349 void
michael@0 350 UnregisterBatteryObserver(BatteryObserver* aObserver)
michael@0 351 {
michael@0 352 AssertMainThread();
michael@0 353 sBatteryObservers.RemoveObserver(aObserver);
michael@0 354 }
michael@0 355
michael@0 356 void
michael@0 357 GetCurrentBatteryInformation(BatteryInformation* aInfo)
michael@0 358 {
michael@0 359 AssertMainThread();
michael@0 360 *aInfo = sBatteryObservers.GetCurrentInformation();
michael@0 361 }
michael@0 362
michael@0 363 void
michael@0 364 NotifyBatteryChange(const BatteryInformation& aInfo)
michael@0 365 {
michael@0 366 AssertMainThread();
michael@0 367 sBatteryObservers.CacheInformation(aInfo);
michael@0 368 sBatteryObservers.BroadcastCachedInformation();
michael@0 369 }
michael@0 370
michael@0 371 bool GetScreenEnabled()
michael@0 372 {
michael@0 373 AssertMainThread();
michael@0 374 RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false);
michael@0 375 }
michael@0 376
michael@0 377 void SetScreenEnabled(bool enabled)
michael@0 378 {
michael@0 379 AssertMainThread();
michael@0 380 PROXY_IF_SANDBOXED(SetScreenEnabled(enabled));
michael@0 381 }
michael@0 382
michael@0 383 bool GetCpuSleepAllowed()
michael@0 384 {
michael@0 385 // Generally for interfaces that are accessible by normal web content
michael@0 386 // we should cache the result and be notified on state changes, like
michael@0 387 // what the battery API does. But since this is only used by
michael@0 388 // privileged interface, the synchronous getter is OK here.
michael@0 389 AssertMainThread();
michael@0 390 RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed(), true);
michael@0 391 }
michael@0 392
michael@0 393 void SetCpuSleepAllowed(bool allowed)
michael@0 394 {
michael@0 395 AssertMainThread();
michael@0 396 PROXY_IF_SANDBOXED(SetCpuSleepAllowed(allowed));
michael@0 397 }
michael@0 398
michael@0 399 double GetScreenBrightness()
michael@0 400 {
michael@0 401 AssertMainThread();
michael@0 402 RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness(), 0);
michael@0 403 }
michael@0 404
michael@0 405 void SetScreenBrightness(double brightness)
michael@0 406 {
michael@0 407 AssertMainThread();
michael@0 408 PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(brightness, 0.0, 1.0)));
michael@0 409 }
michael@0 410
michael@0 411 bool SetLight(LightType light, const LightConfiguration& aConfig)
michael@0 412 {
michael@0 413 AssertMainThread();
michael@0 414 RETURN_PROXY_IF_SANDBOXED(SetLight(light, aConfig), false);
michael@0 415 }
michael@0 416
michael@0 417 bool GetLight(LightType light, LightConfiguration* aConfig)
michael@0 418 {
michael@0 419 AssertMainThread();
michael@0 420 RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig), false);
michael@0 421 }
michael@0 422
michael@0 423 class SystemClockChangeObserversManager : public ObserversManager<int64_t>
michael@0 424 {
michael@0 425 protected:
michael@0 426 void EnableNotifications() {
michael@0 427 PROXY_IF_SANDBOXED(EnableSystemClockChangeNotifications());
michael@0 428 }
michael@0 429
michael@0 430 void DisableNotifications() {
michael@0 431 PROXY_IF_SANDBOXED(DisableSystemClockChangeNotifications());
michael@0 432 }
michael@0 433 };
michael@0 434
michael@0 435 static SystemClockChangeObserversManager sSystemClockChangeObservers;
michael@0 436
michael@0 437 void
michael@0 438 RegisterSystemClockChangeObserver(SystemClockChangeObserver* aObserver)
michael@0 439 {
michael@0 440 AssertMainThread();
michael@0 441 sSystemClockChangeObservers.AddObserver(aObserver);
michael@0 442 }
michael@0 443
michael@0 444 void
michael@0 445 UnregisterSystemClockChangeObserver(SystemClockChangeObserver* aObserver)
michael@0 446 {
michael@0 447 AssertMainThread();
michael@0 448 sSystemClockChangeObservers.RemoveObserver(aObserver);
michael@0 449 }
michael@0 450
michael@0 451 void
michael@0 452 NotifySystemClockChange(const int64_t& aClockDeltaMS)
michael@0 453 {
michael@0 454 sSystemClockChangeObservers.BroadcastInformation(aClockDeltaMS);
michael@0 455 }
michael@0 456
michael@0 457 class SystemTimezoneChangeObserversManager : public ObserversManager<SystemTimezoneChangeInformation>
michael@0 458 {
michael@0 459 protected:
michael@0 460 void EnableNotifications() {
michael@0 461 PROXY_IF_SANDBOXED(EnableSystemTimezoneChangeNotifications());
michael@0 462 }
michael@0 463
michael@0 464 void DisableNotifications() {
michael@0 465 PROXY_IF_SANDBOXED(DisableSystemTimezoneChangeNotifications());
michael@0 466 }
michael@0 467 };
michael@0 468
michael@0 469 static SystemTimezoneChangeObserversManager sSystemTimezoneChangeObservers;
michael@0 470
michael@0 471 void
michael@0 472 RegisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver* aObserver)
michael@0 473 {
michael@0 474 AssertMainThread();
michael@0 475 sSystemTimezoneChangeObservers.AddObserver(aObserver);
michael@0 476 }
michael@0 477
michael@0 478 void
michael@0 479 UnregisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver* aObserver)
michael@0 480 {
michael@0 481 AssertMainThread();
michael@0 482 sSystemTimezoneChangeObservers.RemoveObserver(aObserver);
michael@0 483 }
michael@0 484
michael@0 485 void
michael@0 486 NotifySystemTimezoneChange(const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
michael@0 487 {
michael@0 488 sSystemTimezoneChangeObservers.BroadcastInformation(aSystemTimezoneChangeInfo);
michael@0 489 }
michael@0 490
michael@0 491 void
michael@0 492 AdjustSystemClock(int64_t aDeltaMilliseconds)
michael@0 493 {
michael@0 494 AssertMainThread();
michael@0 495 PROXY_IF_SANDBOXED(AdjustSystemClock(aDeltaMilliseconds));
michael@0 496 }
michael@0 497
michael@0 498 void
michael@0 499 SetTimezone(const nsCString& aTimezoneSpec)
michael@0 500 {
michael@0 501 AssertMainThread();
michael@0 502 PROXY_IF_SANDBOXED(SetTimezone(aTimezoneSpec));
michael@0 503 }
michael@0 504
michael@0 505 int32_t
michael@0 506 GetTimezoneOffset()
michael@0 507 {
michael@0 508 AssertMainThread();
michael@0 509 RETURN_PROXY_IF_SANDBOXED(GetTimezoneOffset(), 0);
michael@0 510 }
michael@0 511
michael@0 512 nsCString
michael@0 513 GetTimezone()
michael@0 514 {
michael@0 515 AssertMainThread();
michael@0 516 RETURN_PROXY_IF_SANDBOXED(GetTimezone(), nsCString(""));
michael@0 517 }
michael@0 518
michael@0 519 void
michael@0 520 EnableSensorNotifications(SensorType aSensor) {
michael@0 521 AssertMainThread();
michael@0 522 PROXY_IF_SANDBOXED(EnableSensorNotifications(aSensor));
michael@0 523 }
michael@0 524
michael@0 525 void
michael@0 526 DisableSensorNotifications(SensorType aSensor) {
michael@0 527 AssertMainThread();
michael@0 528 PROXY_IF_SANDBOXED(DisableSensorNotifications(aSensor));
michael@0 529 }
michael@0 530
michael@0 531 typedef mozilla::ObserverList<SensorData> SensorObserverList;
michael@0 532 static SensorObserverList* gSensorObservers = nullptr;
michael@0 533
michael@0 534 static SensorObserverList &
michael@0 535 GetSensorObservers(SensorType sensor_type) {
michael@0 536 MOZ_ASSERT(sensor_type < NUM_SENSOR_TYPE);
michael@0 537
michael@0 538 if(!gSensorObservers) {
michael@0 539 gSensorObservers = new SensorObserverList[NUM_SENSOR_TYPE];
michael@0 540 }
michael@0 541 return gSensorObservers[sensor_type];
michael@0 542 }
michael@0 543
michael@0 544 void
michael@0 545 RegisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
michael@0 546 SensorObserverList &observers = GetSensorObservers(aSensor);
michael@0 547
michael@0 548 AssertMainThread();
michael@0 549
michael@0 550 observers.AddObserver(aObserver);
michael@0 551 if(observers.Length() == 1) {
michael@0 552 EnableSensorNotifications(aSensor);
michael@0 553 }
michael@0 554 }
michael@0 555
michael@0 556 void
michael@0 557 UnregisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
michael@0 558 AssertMainThread();
michael@0 559
michael@0 560 if (!gSensorObservers) {
michael@0 561 return;
michael@0 562 }
michael@0 563
michael@0 564 SensorObserverList &observers = GetSensorObservers(aSensor);
michael@0 565 if (!observers.RemoveObserver(aObserver) || observers.Length() > 0) {
michael@0 566 return;
michael@0 567 }
michael@0 568 DisableSensorNotifications(aSensor);
michael@0 569
michael@0 570 // Destroy sSensorObservers only if all observer lists are empty.
michael@0 571 for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
michael@0 572 if (gSensorObservers[i].Length() > 0) {
michael@0 573 return;
michael@0 574 }
michael@0 575 }
michael@0 576 delete [] gSensorObservers;
michael@0 577 gSensorObservers = nullptr;
michael@0 578 }
michael@0 579
michael@0 580 void
michael@0 581 NotifySensorChange(const SensorData &aSensorData) {
michael@0 582 SensorObserverList &observers = GetSensorObservers(aSensorData.sensor());
michael@0 583
michael@0 584 AssertMainThread();
michael@0 585
michael@0 586 observers.Broadcast(aSensorData);
michael@0 587 }
michael@0 588
michael@0 589 void
michael@0 590 RegisterNetworkObserver(NetworkObserver* aObserver)
michael@0 591 {
michael@0 592 AssertMainThread();
michael@0 593 sNetworkObservers.AddObserver(aObserver);
michael@0 594 }
michael@0 595
michael@0 596 void
michael@0 597 UnregisterNetworkObserver(NetworkObserver* aObserver)
michael@0 598 {
michael@0 599 AssertMainThread();
michael@0 600 sNetworkObservers.RemoveObserver(aObserver);
michael@0 601 }
michael@0 602
michael@0 603 void
michael@0 604 GetCurrentNetworkInformation(NetworkInformation* aInfo)
michael@0 605 {
michael@0 606 AssertMainThread();
michael@0 607 *aInfo = sNetworkObservers.GetCurrentInformation();
michael@0 608 }
michael@0 609
michael@0 610 void
michael@0 611 NotifyNetworkChange(const NetworkInformation& aInfo)
michael@0 612 {
michael@0 613 sNetworkObservers.CacheInformation(aInfo);
michael@0 614 sNetworkObservers.BroadcastCachedInformation();
michael@0 615 }
michael@0 616
michael@0 617 void Reboot()
michael@0 618 {
michael@0 619 AssertMainProcess();
michael@0 620 AssertMainThread();
michael@0 621 PROXY_IF_SANDBOXED(Reboot());
michael@0 622 }
michael@0 623
michael@0 624 void PowerOff()
michael@0 625 {
michael@0 626 AssertMainProcess();
michael@0 627 AssertMainThread();
michael@0 628 PROXY_IF_SANDBOXED(PowerOff());
michael@0 629 }
michael@0 630
michael@0 631 void StartForceQuitWatchdog(ShutdownMode aMode, int32_t aTimeoutSecs)
michael@0 632 {
michael@0 633 AssertMainProcess();
michael@0 634 AssertMainThread();
michael@0 635 PROXY_IF_SANDBOXED(StartForceQuitWatchdog(aMode, aTimeoutSecs));
michael@0 636 }
michael@0 637
michael@0 638 void StartMonitoringGamepadStatus()
michael@0 639 {
michael@0 640 PROXY_IF_SANDBOXED(StartMonitoringGamepadStatus());
michael@0 641 }
michael@0 642
michael@0 643 void StopMonitoringGamepadStatus()
michael@0 644 {
michael@0 645 PROXY_IF_SANDBOXED(StopMonitoringGamepadStatus());
michael@0 646 }
michael@0 647
michael@0 648 void
michael@0 649 RegisterWakeLockObserver(WakeLockObserver* aObserver)
michael@0 650 {
michael@0 651 AssertMainThread();
michael@0 652 sWakeLockObservers.AddObserver(aObserver);
michael@0 653 }
michael@0 654
michael@0 655 void
michael@0 656 UnregisterWakeLockObserver(WakeLockObserver* aObserver)
michael@0 657 {
michael@0 658 AssertMainThread();
michael@0 659 sWakeLockObservers.RemoveObserver(aObserver);
michael@0 660 }
michael@0 661
michael@0 662 void
michael@0 663 ModifyWakeLock(const nsAString& aTopic,
michael@0 664 WakeLockControl aLockAdjust,
michael@0 665 WakeLockControl aHiddenAdjust,
michael@0 666 uint64_t aProcessID /* = CONTENT_PROCESS_ID_UNKNOWN */)
michael@0 667 {
michael@0 668 AssertMainThread();
michael@0 669
michael@0 670 if (aProcessID == CONTENT_PROCESS_ID_UNKNOWN) {
michael@0 671 aProcessID = InSandbox() ? ContentChild::GetSingleton()->GetID() :
michael@0 672 CONTENT_PROCESS_ID_MAIN;
michael@0 673 }
michael@0 674
michael@0 675 PROXY_IF_SANDBOXED(ModifyWakeLock(aTopic, aLockAdjust,
michael@0 676 aHiddenAdjust, aProcessID));
michael@0 677 }
michael@0 678
michael@0 679 void
michael@0 680 GetWakeLockInfo(const nsAString& aTopic, WakeLockInformation* aWakeLockInfo)
michael@0 681 {
michael@0 682 AssertMainThread();
michael@0 683 PROXY_IF_SANDBOXED(GetWakeLockInfo(aTopic, aWakeLockInfo));
michael@0 684 }
michael@0 685
michael@0 686 void
michael@0 687 NotifyWakeLockChange(const WakeLockInformation& aInfo)
michael@0 688 {
michael@0 689 AssertMainThread();
michael@0 690 sWakeLockObservers.BroadcastInformation(aInfo);
michael@0 691 }
michael@0 692
michael@0 693 void
michael@0 694 RegisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
michael@0 695 {
michael@0 696 AssertMainThread();
michael@0 697 sScreenConfigurationObservers.AddObserver(aObserver);
michael@0 698 }
michael@0 699
michael@0 700 void
michael@0 701 UnregisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
michael@0 702 {
michael@0 703 AssertMainThread();
michael@0 704 sScreenConfigurationObservers.RemoveObserver(aObserver);
michael@0 705 }
michael@0 706
michael@0 707 void
michael@0 708 GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
michael@0 709 {
michael@0 710 AssertMainThread();
michael@0 711 *aScreenConfiguration = sScreenConfigurationObservers.GetCurrentInformation();
michael@0 712 }
michael@0 713
michael@0 714 void
michael@0 715 NotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration)
michael@0 716 {
michael@0 717 sScreenConfigurationObservers.CacheInformation(aScreenConfiguration);
michael@0 718 sScreenConfigurationObservers.BroadcastCachedInformation();
michael@0 719 }
michael@0 720
michael@0 721 bool
michael@0 722 LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
michael@0 723 {
michael@0 724 AssertMainThread();
michael@0 725 RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation), false);
michael@0 726 }
michael@0 727
michael@0 728 void
michael@0 729 UnlockScreenOrientation()
michael@0 730 {
michael@0 731 AssertMainThread();
michael@0 732 PROXY_IF_SANDBOXED(UnlockScreenOrientation());
michael@0 733 }
michael@0 734
michael@0 735 void
michael@0 736 EnableSwitchNotifications(SwitchDevice aDevice) {
michael@0 737 AssertMainThread();
michael@0 738 PROXY_IF_SANDBOXED(EnableSwitchNotifications(aDevice));
michael@0 739 }
michael@0 740
michael@0 741 void
michael@0 742 DisableSwitchNotifications(SwitchDevice aDevice) {
michael@0 743 AssertMainThread();
michael@0 744 PROXY_IF_SANDBOXED(DisableSwitchNotifications(aDevice));
michael@0 745 }
michael@0 746
michael@0 747 SwitchState GetCurrentSwitchState(SwitchDevice aDevice)
michael@0 748 {
michael@0 749 AssertMainThread();
michael@0 750 RETURN_PROXY_IF_SANDBOXED(GetCurrentSwitchState(aDevice), SWITCH_STATE_UNKNOWN);
michael@0 751 }
michael@0 752
michael@0 753 void NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState)
michael@0 754 {
michael@0 755 PROXY_IF_SANDBOXED(NotifySwitchStateFromInputDevice(aDevice, aState));
michael@0 756 }
michael@0 757
michael@0 758 typedef mozilla::ObserverList<SwitchEvent> SwitchObserverList;
michael@0 759
michael@0 760 static SwitchObserverList *sSwitchObserverLists = nullptr;
michael@0 761
michael@0 762 static SwitchObserverList&
michael@0 763 GetSwitchObserverList(SwitchDevice aDevice) {
michael@0 764 MOZ_ASSERT(0 <= aDevice && aDevice < NUM_SWITCH_DEVICE);
michael@0 765 if (sSwitchObserverLists == nullptr) {
michael@0 766 sSwitchObserverLists = new SwitchObserverList[NUM_SWITCH_DEVICE];
michael@0 767 }
michael@0 768 return sSwitchObserverLists[aDevice];
michael@0 769 }
michael@0 770
michael@0 771 static void
michael@0 772 ReleaseObserversIfNeeded() {
michael@0 773 for (int i = 0; i < NUM_SWITCH_DEVICE; i++) {
michael@0 774 if (sSwitchObserverLists[i].Length() != 0)
michael@0 775 return;
michael@0 776 }
michael@0 777
michael@0 778 //The length of every list is 0, no observer in the list.
michael@0 779 delete [] sSwitchObserverLists;
michael@0 780 sSwitchObserverLists = nullptr;
michael@0 781 }
michael@0 782
michael@0 783 void
michael@0 784 RegisterSwitchObserver(SwitchDevice aDevice, SwitchObserver *aObserver)
michael@0 785 {
michael@0 786 AssertMainThread();
michael@0 787 SwitchObserverList& observer = GetSwitchObserverList(aDevice);
michael@0 788 observer.AddObserver(aObserver);
michael@0 789 if (observer.Length() == 1) {
michael@0 790 EnableSwitchNotifications(aDevice);
michael@0 791 }
michael@0 792 }
michael@0 793
michael@0 794 void
michael@0 795 UnregisterSwitchObserver(SwitchDevice aDevice, SwitchObserver *aObserver)
michael@0 796 {
michael@0 797 AssertMainThread();
michael@0 798
michael@0 799 if (!sSwitchObserverLists) {
michael@0 800 return;
michael@0 801 }
michael@0 802
michael@0 803 SwitchObserverList& observer = GetSwitchObserverList(aDevice);
michael@0 804 if (!observer.RemoveObserver(aObserver) || observer.Length() > 0) {
michael@0 805 return;
michael@0 806 }
michael@0 807
michael@0 808 DisableSwitchNotifications(aDevice);
michael@0 809 ReleaseObserversIfNeeded();
michael@0 810 }
michael@0 811
michael@0 812 void
michael@0 813 NotifySwitchChange(const SwitchEvent& aEvent)
michael@0 814 {
michael@0 815 // When callback this notification, main thread may call unregister function
michael@0 816 // first. We should check if this pointer is valid.
michael@0 817 if (!sSwitchObserverLists)
michael@0 818 return;
michael@0 819
michael@0 820 SwitchObserverList& observer = GetSwitchObserverList(aEvent.device());
michael@0 821 observer.Broadcast(aEvent);
michael@0 822 }
michael@0 823
michael@0 824 static AlarmObserver* sAlarmObserver;
michael@0 825
michael@0 826 bool
michael@0 827 RegisterTheOneAlarmObserver(AlarmObserver* aObserver)
michael@0 828 {
michael@0 829 MOZ_ASSERT(!InSandbox());
michael@0 830 MOZ_ASSERT(!sAlarmObserver);
michael@0 831
michael@0 832 sAlarmObserver = aObserver;
michael@0 833 RETURN_PROXY_IF_SANDBOXED(EnableAlarm(), false);
michael@0 834 }
michael@0 835
michael@0 836 void
michael@0 837 UnregisterTheOneAlarmObserver()
michael@0 838 {
michael@0 839 if (sAlarmObserver) {
michael@0 840 sAlarmObserver = nullptr;
michael@0 841 PROXY_IF_SANDBOXED(DisableAlarm());
michael@0 842 }
michael@0 843 }
michael@0 844
michael@0 845 void
michael@0 846 NotifyAlarmFired()
michael@0 847 {
michael@0 848 if (sAlarmObserver) {
michael@0 849 sAlarmObserver->Notify(void_t());
michael@0 850 }
michael@0 851 }
michael@0 852
michael@0 853 bool
michael@0 854 SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
michael@0 855 {
michael@0 856 // It's pointless to program an alarm nothing is going to observe ...
michael@0 857 MOZ_ASSERT(sAlarmObserver);
michael@0 858 RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds, aNanoseconds), false);
michael@0 859 }
michael@0 860
michael@0 861 void
michael@0 862 SetProcessPriority(int aPid,
michael@0 863 ProcessPriority aPriority,
michael@0 864 ProcessCPUPriority aCPUPriority,
michael@0 865 uint32_t aBackgroundLRU)
michael@0 866 {
michael@0 867 // n.b. The sandboxed implementation crashes; SetProcessPriority works only
michael@0 868 // from the main process.
michael@0 869 MOZ_ASSERT(aBackgroundLRU == 0 || aPriority == PROCESS_PRIORITY_BACKGROUND);
michael@0 870 PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority, aCPUPriority,
michael@0 871 aBackgroundLRU));
michael@0 872 }
michael@0 873
michael@0 874 // From HalTypes.h.
michael@0 875 const char*
michael@0 876 ProcessPriorityToString(ProcessPriority aPriority)
michael@0 877 {
michael@0 878 switch (aPriority) {
michael@0 879 case PROCESS_PRIORITY_MASTER:
michael@0 880 return "MASTER";
michael@0 881 case PROCESS_PRIORITY_PREALLOC:
michael@0 882 return "PREALLOC";
michael@0 883 case PROCESS_PRIORITY_FOREGROUND_HIGH:
michael@0 884 return "FOREGROUND_HIGH";
michael@0 885 case PROCESS_PRIORITY_FOREGROUND:
michael@0 886 return "FOREGROUND";
michael@0 887 case PROCESS_PRIORITY_FOREGROUND_KEYBOARD:
michael@0 888 return "FOREGROUND_KEYBOARD";
michael@0 889 case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
michael@0 890 return "BACKGROUND_PERCEIVABLE";
michael@0 891 case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
michael@0 892 return "BACKGROUND_HOMESCREEN";
michael@0 893 case PROCESS_PRIORITY_BACKGROUND:
michael@0 894 return "BACKGROUND";
michael@0 895 case PROCESS_PRIORITY_UNKNOWN:
michael@0 896 return "UNKNOWN";
michael@0 897 default:
michael@0 898 MOZ_ASSERT(false);
michael@0 899 return "???";
michael@0 900 }
michael@0 901 }
michael@0 902
michael@0 903 // From HalTypes.h.
michael@0 904 const char*
michael@0 905 ProcessPriorityToString(ProcessPriority aPriority,
michael@0 906 ProcessCPUPriority aCPUPriority)
michael@0 907 {
michael@0 908 // Sorry this is ugly. At least it's all in one place.
michael@0 909 //
michael@0 910 // We intentionally fall through if aCPUPriority is invalid; we won't hit any
michael@0 911 // of the if statements further down, so it's OK.
michael@0 912
michael@0 913 switch (aPriority) {
michael@0 914 case PROCESS_PRIORITY_MASTER:
michael@0 915 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 916 return "MASTER:CPU_NORMAL";
michael@0 917 }
michael@0 918 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 919 return "MASTER:CPU_LOW";
michael@0 920 }
michael@0 921 case PROCESS_PRIORITY_PREALLOC:
michael@0 922 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 923 return "PREALLOC:CPU_NORMAL";
michael@0 924 }
michael@0 925 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 926 return "PREALLOC:CPU_LOW";
michael@0 927 }
michael@0 928 case PROCESS_PRIORITY_FOREGROUND_HIGH:
michael@0 929 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 930 return "FOREGROUND_HIGH:CPU_NORMAL";
michael@0 931 }
michael@0 932 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 933 return "FOREGROUND_HIGH:CPU_LOW";
michael@0 934 }
michael@0 935 case PROCESS_PRIORITY_FOREGROUND:
michael@0 936 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 937 return "FOREGROUND:CPU_NORMAL";
michael@0 938 }
michael@0 939 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 940 return "FOREGROUND:CPU_LOW";
michael@0 941 }
michael@0 942 case PROCESS_PRIORITY_FOREGROUND_KEYBOARD:
michael@0 943 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 944 return "FOREGROUND_KEYBOARD:CPU_NORMAL";
michael@0 945 }
michael@0 946 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 947 return "FOREGROUND_KEYBOARD:CPU_LOW";
michael@0 948 }
michael@0 949 case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
michael@0 950 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 951 return "BACKGROUND_PERCEIVABLE:CPU_NORMAL";
michael@0 952 }
michael@0 953 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 954 return "BACKGROUND_PERCEIVABLE:CPU_LOW";
michael@0 955 }
michael@0 956 case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
michael@0 957 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 958 return "BACKGROUND_HOMESCREEN:CPU_NORMAL";
michael@0 959 }
michael@0 960 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 961 return "BACKGROUND_HOMESCREEN:CPU_LOW";
michael@0 962 }
michael@0 963 case PROCESS_PRIORITY_BACKGROUND:
michael@0 964 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 965 return "BACKGROUND:CPU_NORMAL";
michael@0 966 }
michael@0 967 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 968 return "BACKGROUND:CPU_LOW";
michael@0 969 }
michael@0 970 case PROCESS_PRIORITY_UNKNOWN:
michael@0 971 if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
michael@0 972 return "UNKNOWN:CPU_NORMAL";
michael@0 973 }
michael@0 974 if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
michael@0 975 return "UNKNOWN:CPU_LOW";
michael@0 976 }
michael@0 977 default:
michael@0 978 // Fall through. (|default| is here to silence warnings.)
michael@0 979 break;
michael@0 980 }
michael@0 981
michael@0 982 MOZ_ASSERT(false);
michael@0 983 return "???";
michael@0 984 }
michael@0 985
michael@0 986 static StaticAutoPtr<ObserverList<FMRadioOperationInformation> > sFMRadioObservers;
michael@0 987
michael@0 988 static void
michael@0 989 InitializeFMRadioObserver()
michael@0 990 {
michael@0 991 if (!sFMRadioObservers) {
michael@0 992 sFMRadioObservers = new ObserverList<FMRadioOperationInformation>;
michael@0 993 ClearOnShutdown(&sFMRadioObservers);
michael@0 994 }
michael@0 995 }
michael@0 996
michael@0 997 void
michael@0 998 RegisterFMRadioObserver(FMRadioObserver* aFMRadioObserver) {
michael@0 999 AssertMainThread();
michael@0 1000 InitializeFMRadioObserver();
michael@0 1001 sFMRadioObservers->AddObserver(aFMRadioObserver);
michael@0 1002 }
michael@0 1003
michael@0 1004 void
michael@0 1005 UnregisterFMRadioObserver(FMRadioObserver* aFMRadioObserver) {
michael@0 1006 AssertMainThread();
michael@0 1007 InitializeFMRadioObserver();
michael@0 1008 sFMRadioObservers->RemoveObserver(aFMRadioObserver);
michael@0 1009 }
michael@0 1010
michael@0 1011 void
michael@0 1012 NotifyFMRadioStatus(const FMRadioOperationInformation& aFMRadioState) {
michael@0 1013 InitializeFMRadioObserver();
michael@0 1014 sFMRadioObservers->Broadcast(aFMRadioState);
michael@0 1015 }
michael@0 1016
michael@0 1017 void
michael@0 1018 EnableFMRadio(const FMRadioSettings& aInfo) {
michael@0 1019 AssertMainThread();
michael@0 1020 PROXY_IF_SANDBOXED(EnableFMRadio(aInfo));
michael@0 1021 }
michael@0 1022
michael@0 1023 void
michael@0 1024 DisableFMRadio() {
michael@0 1025 AssertMainThread();
michael@0 1026 PROXY_IF_SANDBOXED(DisableFMRadio());
michael@0 1027 }
michael@0 1028
michael@0 1029 void
michael@0 1030 FMRadioSeek(const FMRadioSeekDirection& aDirection) {
michael@0 1031 AssertMainThread();
michael@0 1032 PROXY_IF_SANDBOXED(FMRadioSeek(aDirection));
michael@0 1033 }
michael@0 1034
michael@0 1035 void
michael@0 1036 GetFMRadioSettings(FMRadioSettings* aInfo) {
michael@0 1037 AssertMainThread();
michael@0 1038 PROXY_IF_SANDBOXED(GetFMRadioSettings(aInfo));
michael@0 1039 }
michael@0 1040
michael@0 1041 void
michael@0 1042 SetFMRadioFrequency(const uint32_t aFrequency) {
michael@0 1043 AssertMainThread();
michael@0 1044 PROXY_IF_SANDBOXED(SetFMRadioFrequency(aFrequency));
michael@0 1045 }
michael@0 1046
michael@0 1047 uint32_t
michael@0 1048 GetFMRadioFrequency() {
michael@0 1049 AssertMainThread();
michael@0 1050 RETURN_PROXY_IF_SANDBOXED(GetFMRadioFrequency(), 0);
michael@0 1051 }
michael@0 1052
michael@0 1053 bool
michael@0 1054 IsFMRadioOn() {
michael@0 1055 AssertMainThread();
michael@0 1056 RETURN_PROXY_IF_SANDBOXED(IsFMRadioOn(), false);
michael@0 1057 }
michael@0 1058
michael@0 1059 uint32_t
michael@0 1060 GetFMRadioSignalStrength() {
michael@0 1061 AssertMainThread();
michael@0 1062 RETURN_PROXY_IF_SANDBOXED(GetFMRadioSignalStrength(), 0);
michael@0 1063 }
michael@0 1064
michael@0 1065 void
michael@0 1066 CancelFMRadioSeek() {
michael@0 1067 AssertMainThread();
michael@0 1068 PROXY_IF_SANDBOXED(CancelFMRadioSeek());
michael@0 1069 }
michael@0 1070
michael@0 1071 FMRadioSettings
michael@0 1072 GetFMBandSettings(FMRadioCountry aCountry) {
michael@0 1073 FMRadioSettings settings;
michael@0 1074
michael@0 1075 switch (aCountry) {
michael@0 1076 case FM_RADIO_COUNTRY_US:
michael@0 1077 case FM_RADIO_COUNTRY_EU:
michael@0 1078 settings.upperLimit() = 108000;
michael@0 1079 settings.lowerLimit() = 87800;
michael@0 1080 settings.spaceType() = 200;
michael@0 1081 settings.preEmphasis() = 75;
michael@0 1082 break;
michael@0 1083 case FM_RADIO_COUNTRY_JP_STANDARD:
michael@0 1084 settings.upperLimit() = 76000;
michael@0 1085 settings.lowerLimit() = 90000;
michael@0 1086 settings.spaceType() = 100;
michael@0 1087 settings.preEmphasis() = 50;
michael@0 1088 break;
michael@0 1089 case FM_RADIO_COUNTRY_CY:
michael@0 1090 case FM_RADIO_COUNTRY_DE:
michael@0 1091 case FM_RADIO_COUNTRY_DK:
michael@0 1092 case FM_RADIO_COUNTRY_ES:
michael@0 1093 case FM_RADIO_COUNTRY_FI:
michael@0 1094 case FM_RADIO_COUNTRY_FR:
michael@0 1095 case FM_RADIO_COUNTRY_HU:
michael@0 1096 case FM_RADIO_COUNTRY_IR:
michael@0 1097 case FM_RADIO_COUNTRY_IT:
michael@0 1098 case FM_RADIO_COUNTRY_KW:
michael@0 1099 case FM_RADIO_COUNTRY_LT:
michael@0 1100 case FM_RADIO_COUNTRY_ML:
michael@0 1101 case FM_RADIO_COUNTRY_NO:
michael@0 1102 case FM_RADIO_COUNTRY_OM:
michael@0 1103 case FM_RADIO_COUNTRY_PG:
michael@0 1104 case FM_RADIO_COUNTRY_NL:
michael@0 1105 case FM_RADIO_COUNTRY_CZ:
michael@0 1106 case FM_RADIO_COUNTRY_UK:
michael@0 1107 case FM_RADIO_COUNTRY_RW:
michael@0 1108 case FM_RADIO_COUNTRY_SN:
michael@0 1109 case FM_RADIO_COUNTRY_SI:
michael@0 1110 case FM_RADIO_COUNTRY_ZA:
michael@0 1111 case FM_RADIO_COUNTRY_SE:
michael@0 1112 case FM_RADIO_COUNTRY_CH:
michael@0 1113 case FM_RADIO_COUNTRY_TW:
michael@0 1114 case FM_RADIO_COUNTRY_UA:
michael@0 1115 settings.upperLimit() = 108000;
michael@0 1116 settings.lowerLimit() = 87500;
michael@0 1117 settings.spaceType() = 100;
michael@0 1118 settings.preEmphasis() = 50;
michael@0 1119 break;
michael@0 1120 case FM_RADIO_COUNTRY_VA:
michael@0 1121 case FM_RADIO_COUNTRY_MA:
michael@0 1122 case FM_RADIO_COUNTRY_TR:
michael@0 1123 settings.upperLimit() = 10800;
michael@0 1124 settings.lowerLimit() = 87500;
michael@0 1125 settings.spaceType() = 100;
michael@0 1126 settings.preEmphasis() = 75;
michael@0 1127 break;
michael@0 1128 case FM_RADIO_COUNTRY_AU:
michael@0 1129 case FM_RADIO_COUNTRY_BD:
michael@0 1130 settings.upperLimit() = 108000;
michael@0 1131 settings.lowerLimit() = 87500;
michael@0 1132 settings.spaceType() = 200;
michael@0 1133 settings.preEmphasis() = 75;
michael@0 1134 break;
michael@0 1135 case FM_RADIO_COUNTRY_AW:
michael@0 1136 case FM_RADIO_COUNTRY_BS:
michael@0 1137 case FM_RADIO_COUNTRY_CO:
michael@0 1138 case FM_RADIO_COUNTRY_KR:
michael@0 1139 settings.upperLimit() = 108000;
michael@0 1140 settings.lowerLimit() = 88000;
michael@0 1141 settings.spaceType() = 200;
michael@0 1142 settings.preEmphasis() = 75;
michael@0 1143 break;
michael@0 1144 case FM_RADIO_COUNTRY_EC:
michael@0 1145 settings.upperLimit() = 108000;
michael@0 1146 settings.lowerLimit() = 88000;
michael@0 1147 settings.spaceType() = 200;
michael@0 1148 settings.preEmphasis() = 0;
michael@0 1149 break;
michael@0 1150 case FM_RADIO_COUNTRY_GM:
michael@0 1151 settings.upperLimit() = 108000;
michael@0 1152 settings.lowerLimit() = 88000;
michael@0 1153 settings.spaceType() = 0;
michael@0 1154 settings.preEmphasis() = 75;
michael@0 1155 break;
michael@0 1156 case FM_RADIO_COUNTRY_QA:
michael@0 1157 settings.upperLimit() = 108000;
michael@0 1158 settings.lowerLimit() = 88000;
michael@0 1159 settings.spaceType() = 200;
michael@0 1160 settings.preEmphasis() = 50;
michael@0 1161 break;
michael@0 1162 case FM_RADIO_COUNTRY_SG:
michael@0 1163 settings.upperLimit() = 108000;
michael@0 1164 settings.lowerLimit() = 88000;
michael@0 1165 settings.spaceType() = 200;
michael@0 1166 settings.preEmphasis() = 50;
michael@0 1167 break;
michael@0 1168 case FM_RADIO_COUNTRY_IN:
michael@0 1169 settings.upperLimit() = 100000;
michael@0 1170 settings.lowerLimit() = 108000;
michael@0 1171 settings.spaceType() = 100;
michael@0 1172 settings.preEmphasis() = 50;
michael@0 1173 break;
michael@0 1174 case FM_RADIO_COUNTRY_NZ:
michael@0 1175 settings.upperLimit() = 100000;
michael@0 1176 settings.lowerLimit() = 88000;
michael@0 1177 settings.spaceType() = 50;
michael@0 1178 settings.preEmphasis() = 50;
michael@0 1179 break;
michael@0 1180 case FM_RADIO_COUNTRY_USER_DEFINED:
michael@0 1181 break;
michael@0 1182 default:
michael@0 1183 MOZ_ASSERT(0);
michael@0 1184 break;
michael@0 1185 };
michael@0 1186 return settings;
michael@0 1187 }
michael@0 1188
michael@0 1189 void FactoryReset()
michael@0 1190 {
michael@0 1191 AssertMainThread();
michael@0 1192 PROXY_IF_SANDBOXED(FactoryReset());
michael@0 1193 }
michael@0 1194
michael@0 1195 void
michael@0 1196 StartDiskSpaceWatcher()
michael@0 1197 {
michael@0 1198 AssertMainProcess();
michael@0 1199 AssertMainThread();
michael@0 1200 PROXY_IF_SANDBOXED(StartDiskSpaceWatcher());
michael@0 1201 }
michael@0 1202
michael@0 1203 void
michael@0 1204 StopDiskSpaceWatcher()
michael@0 1205 {
michael@0 1206 AssertMainProcess();
michael@0 1207 AssertMainThread();
michael@0 1208 PROXY_IF_SANDBOXED(StopDiskSpaceWatcher());
michael@0 1209 }
michael@0 1210
michael@0 1211 uint32_t
michael@0 1212 GetTotalSystemMemory()
michael@0 1213 {
michael@0 1214 return hal_impl::GetTotalSystemMemory();
michael@0 1215 }
michael@0 1216
michael@0 1217
michael@0 1218 } // namespace hal
michael@0 1219 } // namespace mozilla

mercurial