Bug 717434 - B2G telephony: audio isn't switched on for incoming calls and never switched off once switched on. r=bent
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Wed, 11 Jan 2012 16:20:16 -0800
changeset 85542 289576c5080271352fb1c342e809268e2ff009ed
parent 85541 ece727bdde6e2ea1a41acdcad8b9e7b2daa7fe43
child 85543 c5536ad3e639f13d4efe214a3c523cd805fcad46
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs717434
milestone12.0a1
Bug 717434 - B2G telephony: audio isn't switched on for incoming calls and never switched off once switched on. r=bent
dom/telephony/nsTelephonyWorker.js
--- a/dom/telephony/nsTelephonyWorker.js
+++ b/dom/telephony/nsTelephonyWorker.js
@@ -184,80 +184,75 @@ nsTelephonyWorker.prototype = {
   },
 
   /**
    * Track the active call and update the audio system as its state changes.
    *
    * XXX Needs some more work to support hold/resume.
    */
   _activeCall: null,
-  get activeCall() {
-    return this._activeCall;
-  },
-  set activeCall(val) {
-    if (val && !this._activeCall) {
-      // Enable audio.
-      switch (val.state) {
-        case nsITelephone.CALL_STATE_INCOMING:
-          gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_RINGTONE;
-          break;
-        case nsITelephone.CALL_STATE_DIALING: // Fall through...
-        case nsITelephone.CALL_STATE_CONNECTED:
-          gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_IN_CALL;
-          gAudioManager.setForceForUse(nsIAudioManager.USE_COMMUNICATION,
-                                       nsIAudioManager.FORCE_NONE);
-          break;
-        default:
-          throw new Error("Invalid call state for active call: " + val.state);
-      }
-    } else if (!val && this._activeCall) {
+  updateCallAudioState: function updateCallAudioState() {
+    if (!this._activeCall) {
       // Disable audio.
       gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_NORMAL;
+      debug("No active call, put audio system into PHONE_STATE_NORMAL.");
+      return;
     }
-    this._activeCall = val;
+    switch (this._activeCall.state) {
+      case nsITelephone.CALL_STATE_INCOMING:
+        gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_RINGTONE;
+        debug("Incoming call, put audio system into PHONE_STATE_RINGTONE.");
+        break;
+      case nsITelephone.CALL_STATE_DIALING: // Fall through...
+      case nsITelephone.CALL_STATE_CONNECTED:
+        gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_IN_CALL;
+        gAudioManager.setForceForUse(nsIAudioManager.USE_COMMUNICATION,
+                                     nsIAudioManager.FORCE_NONE);
+        debug("Active call, put audio system into PHONE_STATE_IN_CALL.");
+        break;
+    }
   },
 
   /**
    * Handle call state changes by updating our current state and the audio
    * system.
    */
   handleCallStateChange: function handleCallStateChange(call) {
     debug("handleCallStateChange: " + JSON.stringify(call));
     call.state = convertRILCallState(call.state);
-    if (call.state == nsITelephone.CALL_STATE_INCOMING ||
-        call.state == nsITelephone.CALL_STATE_DIALING ||
-        call.state == nsITelephone.CALL_STATE_CONNECTED) {
+    if (call.state == nsITelephone.CALL_STATE_CONNECTED) {
       // This is now the active call.
-      this.activeCall = call;
+      this._activeCall = call;
     }
+    this.updateCallAudioState();
     this._deliverCallback("callStateChanged",
                           [call.callIndex, call.state, call.number]);
   },
 
   /**
    * Handle call disconnects by updating our current state and the audio system.
    */
-  handleCallDisconnected: function handleCallStateChange(call) {
+  handleCallDisconnected: function handleCallDisconnected(call) {
     debug("handleCallDisconnected: " + JSON.stringify(call));
-    if (this.activeCall == call) {
-      // No loner active.
-      this.activeCall = null;
+    if (this._activeCall.callIndex == call.callIndex) {
+      this._activeCall = null;
     }
+    this.updateCallAudioState();
     this._deliverCallback("callStateChanged",
                           [call.callIndex, nsITelephone.CALL_STATE_DISCONNECTED,
                            call.number]);
   },
 
   /**
    * Handle calls delivered in response to a 'enumerateCalls' request.
    */
   handleEnumerateCalls: function handleEnumerateCalls(calls) {
     debug("handleEnumerateCalls: " + JSON.stringify(calls));
     let callback = this._enumerationCallbacks.shift();
-    let activeCallIndex = this.activeCall ? this.activeCall.callIndex : -1;
+    let activeCallIndex = this._activeCall ? this._activeCall.callIndex : -1;
     for (let i in calls) {
       let call = calls[i];
       let state = convertRILCallState(call.state);
       let keepGoing;
       try {
         keepGoing =
           callback.enumerateCallState(call.callIndex, state, call.number,
                                       call.callIndex == activeCallIndex);