Bug 834200 - [Audio] Hook AudioManager::SetPhoneState for getting ring & in_call then register into AudioChannelService. r=baku, a=tef+
authorMarco Chen <mchen@mozilla.com>
Mon, 04 Feb 2013 11:23:06 +0800
changeset 118394 ee5bf23c946458d6bf7f4e072b14581118d8bcff
parent 118393 4bf63fd3ceafe5a8e041d253ea265a50dba23738
child 118395 5253c6b83f3ec57ed6f271f44863f2f6270f3f50
push id20
push useramarchesini@mozilla.com
push dateMon, 04 Feb 2013 12:47:10 +0000
reviewersbaku, tef
bugs834200
milestone18.0
Bug 834200 - [Audio] Hook AudioManager::SetPhoneState for getting ring & in_call then register into AudioChannelService. r=baku, a=tef+
dom/system/gonk/AudioManager.cpp
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -301,30 +301,34 @@ AudioManager::SetPhoneState(int32_t aSta
   }
 
   if (AudioSystem::setPhoneState(aState)) {
     return NS_ERROR_FAILURE;
   }
 
   mPhoneState = aState;
 
-  if (aState == PHONE_STATE_IN_CALL) {
-    if (!mPhoneAudioAgent) {
-      mPhoneAudioAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1");
-      MOZ_ASSERT(mPhoneAudioAgent);
+  if (mPhoneAudioAgent) {
+    mPhoneAudioAgent->StopPlaying();
+    mPhoneAudioAgent = nullptr;
+  }
+
+  if (aState == PHONE_STATE_IN_CALL || aState == PHONE_STATE_RINGTONE) {
+    mPhoneAudioAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1");
+    MOZ_ASSERT(mPhoneAudioAgent);
+    if (aState == PHONE_STATE_IN_CALL) {
       // Telephony doesn't be paused by any other channels.
       mPhoneAudioAgent->Init(AUDIO_CHANNEL_TELEPHONY, nullptr);
+    } else {
+      mPhoneAudioAgent->Init(AUDIO_CHANNEL_RINGER, nullptr);
+    }
 
-      // Telephony can always play.
-      bool canPlay;
-      mPhoneAudioAgent->StartPlaying(&canPlay);
-    }
-  } else if (mPhoneAudioAgent) {
-    mPhoneAudioAgent->StopPlaying();
-    mPhoneAudioAgent = nullptr;
+    // Telephony can always play.
+    bool canPlay;
+    mPhoneAudioAgent->StartPlaying(&canPlay);
   }
 
   return NS_OK;
 }
 
 //
 // Kids, don't try this at home.  We want this to link and work on
 // both GB and ICS.  Problem is, the symbol exported by audioflinger