dom/speakermanager/SpeakerManagerServiceChild.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
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 "SpeakerManagerServiceChild.h"
michael@0 8 #include "mozilla/Services.h"
michael@0 9 #include "mozilla/StaticPtr.h"
michael@0 10 #include "mozilla/unused.h"
michael@0 11 #include "mozilla/dom/ContentChild.h"
michael@0 12 #include "mozilla/dom/ContentParent.h"
michael@0 13 #include "nsIObserverService.h"
michael@0 14 #include "nsThreadUtils.h"
michael@0 15 #include "AudioChannelService.h"
michael@0 16 #include <cutils/properties.h>
michael@0 17
michael@0 18 using namespace mozilla;
michael@0 19 using namespace mozilla::dom;
michael@0 20
michael@0 21 StaticRefPtr<SpeakerManagerServiceChild> gSpeakerManagerServiceChild;
michael@0 22
michael@0 23 // static
michael@0 24 SpeakerManagerService*
michael@0 25 SpeakerManagerServiceChild::GetSpeakerManagerService()
michael@0 26 {
michael@0 27 MOZ_ASSERT(NS_IsMainThread());
michael@0 28
michael@0 29 // If we already exist, exit early
michael@0 30 if (gSpeakerManagerServiceChild) {
michael@0 31 return gSpeakerManagerServiceChild;
michael@0 32 }
michael@0 33
michael@0 34 // Create new instance, register, return
michael@0 35 nsRefPtr<SpeakerManagerServiceChild> service = new SpeakerManagerServiceChild();
michael@0 36 NS_ENSURE_TRUE(service, nullptr);
michael@0 37
michael@0 38 gSpeakerManagerServiceChild = service;
michael@0 39 return gSpeakerManagerServiceChild;
michael@0 40 }
michael@0 41
michael@0 42 void
michael@0 43 SpeakerManagerServiceChild::ForceSpeaker(bool aEnable, bool aVisible)
michael@0 44 {
michael@0 45 mVisible = aVisible;
michael@0 46 mOrgSpeakerStatus = aEnable;
michael@0 47 ContentChild *cc = ContentChild::GetSingleton();
michael@0 48 if (cc) {
michael@0 49 cc->SendSpeakerManagerForceSpeaker(aEnable && aVisible);
michael@0 50 }
michael@0 51 }
michael@0 52
michael@0 53 bool
michael@0 54 SpeakerManagerServiceChild::GetSpeakerStatus()
michael@0 55 {
michael@0 56 ContentChild *cc = ContentChild::GetSingleton();
michael@0 57 bool status = false;
michael@0 58 if (cc) {
michael@0 59 cc->SendSpeakerManagerGetSpeakerStatus(&status);
michael@0 60 }
michael@0 61 char propQemu[PROPERTY_VALUE_MAX];
michael@0 62 property_get("ro.kernel.qemu", propQemu, "");
michael@0 63 if (!strncmp(propQemu, "1", 1)) {
michael@0 64 return mOrgSpeakerStatus;
michael@0 65 }
michael@0 66 return status;
michael@0 67 }
michael@0 68
michael@0 69 void
michael@0 70 SpeakerManagerServiceChild::Shutdown()
michael@0 71 {
michael@0 72 if (gSpeakerManagerServiceChild) {
michael@0 73 gSpeakerManagerServiceChild = nullptr;
michael@0 74 }
michael@0 75 }
michael@0 76
michael@0 77 void
michael@0 78 SpeakerManagerServiceChild::SetAudioChannelActive(bool aIsActive)
michael@0 79 {
michael@0 80 // Content process and switch to background with no audio and speaker forced.
michael@0 81 // Then disable speaker
michael@0 82 for (uint32_t i = 0; i < mRegisteredSpeakerManagers.Length(); i++) {
michael@0 83 mRegisteredSpeakerManagers[i]->SetAudioChannelActive(aIsActive);
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 SpeakerManagerServiceChild::SpeakerManagerServiceChild()
michael@0 88 {
michael@0 89 MOZ_ASSERT(NS_IsMainThread());
michael@0 90 AudioChannelService* audioChannelService = AudioChannelService::GetAudioChannelService();
michael@0 91 if (audioChannelService) {
michael@0 92 audioChannelService->RegisterSpeakerManager(this);
michael@0 93 }
michael@0 94 MOZ_COUNT_CTOR(SpeakerManagerServiceChild);
michael@0 95 }
michael@0 96
michael@0 97 SpeakerManagerServiceChild::~SpeakerManagerServiceChild()
michael@0 98 {
michael@0 99 AudioChannelService* audioChannelService = AudioChannelService::GetAudioChannelService();
michael@0 100 if (audioChannelService) {
michael@0 101 audioChannelService->UnregisterSpeakerManager(this);
michael@0 102 }
michael@0 103 MOZ_COUNT_DTOR(SpeakerManagerServiceChild);
michael@0 104 }
michael@0 105
michael@0 106 void
michael@0 107 SpeakerManagerServiceChild::Notify()
michael@0 108 {
michael@0 109 for (uint32_t i = 0; i < mRegisteredSpeakerManagers.Length(); i++) {
michael@0 110 mRegisteredSpeakerManagers[i]->DispatchSimpleEvent(NS_LITERAL_STRING("speakerforcedchange"));
michael@0 111 }
michael@0 112 }

mercurial