Bug 1005498 - Ignore audio setting for place holder call. r=hsinyi
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Tue, 06 May 2014 03:01:00 +0200
changeset 181963 5893e38d5a525c10e299721d754533fbb3a0f9ae
parent 181962 041f6b1fe7155eb9ff9f83db836457d28e7a7c0c
child 181964 6781b96cca1c3f400999561a0651cfaa1b937dcd
push id43178
push usercbook@mozilla.com
push dateWed, 07 May 2014 12:13:50 +0000
treeherdermozilla-inbound@36b2f696ff10 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs1005498
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1005498 - Ignore audio setting for place holder call. r=hsinyi
dom/telephony/gonk/TelephonyProvider.js
--- a/dom/telephony/gonk/TelephonyProvider.js
+++ b/dom/telephony/gonk/TelephonyProvider.js
@@ -208,40 +208,28 @@ TelephonyProvider.prototype = {
            this._activeCall.clientId === aCall.clientId &&
            this._activeCall.callIndex === aCall.callIndex;
   },
 
   /**
    * Track the active call and update the audio system as its state changes.
    */
   _activeCall: null,
-  _updateCallAudioState: function(aCall, aConferenceState) {
+  _updateActiveCall: function(aCall, aConferenceState) {
     if (aConferenceState === nsITelephonyProvider.CALL_STATE_CONNECTED) {
       this._activeCall = new ConferenceCall(aConferenceState);
-      gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_IN_CALL;
-      if (this.speakerEnabled) {
-        gAudioManager.setForceForUse(nsIAudioManager.USE_COMMUNICATION,
-                                     nsIAudioManager.FORCE_SPEAKER);
-      }
-      if (DEBUG) {
-        debug("Active call, put audio system into PHONE_STATE_IN_CALL: " +
-              gAudioManager.phoneState);
-      }
+      this._updateCallAudioState(aCall);
       return;
     }
 
     if (aConferenceState === nsITelephonyProvider.CALL_STATE_UNKNOWN ||
         aConferenceState === nsITelephonyProvider.CALL_STATE_HELD) {
       if (this._activeCall instanceof ConferenceCall) {
         this._activeCall = null;
-        gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_NORMAL;
-        if (DEBUG) {
-          debug("No active call, put audio system into PHONE_STATE_NORMAL: " +
-                gAudioManager.phoneState);
-        }
+        this._updateCallAudioState(aCall);
       }
       return;
     }
 
     if (!aCall) {
       return;
     }
 
@@ -253,60 +241,73 @@ TelephonyProvider.prototype = {
     }
 
     switch (aCall.state) {
       case nsITelephonyProvider.CALL_STATE_DIALING: // Fall through...
       case nsITelephonyProvider.CALL_STATE_ALERTING:
       case nsITelephonyProvider.CALL_STATE_CONNECTED:
         aCall.isActive = true;
         this._activeCall = new SingleCall(aCall);
-        gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_IN_CALL;
-        if (this.speakerEnabled) {
-          gAudioManager.setForceForUse(nsIAudioManager.USE_COMMUNICATION,
-                                       nsIAudioManager.FORCE_SPEAKER);
-        }
-        if (DEBUG) {
-          debug("Active call, put audio system into PHONE_STATE_IN_CALL: " +
-                gAudioManager.phoneState);
-        }
+        this._updateCallAudioState(aCall);
         break;
 
       case nsITelephonyProvider.CALL_STATE_INCOMING:
         aCall.isActive = false;
-        if (!this._activeCall) {
-          // We can change the phone state into RINGTONE only when there's
-          // no active call.
-          gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_RINGTONE;
-          if (DEBUG) {
-            debug("Incoming call, put audio system into PHONE_STATE_RINGTONE: " +
-                  gAudioManager.phoneState);
-          }
-        }
+        this._updateCallAudioState(aCall);
         break;
 
       case nsITelephonyProvider.CALL_STATE_HELD: // Fall through...
       case nsITelephonyProvider.CALL_STATE_DISCONNECTED:
         aCall.isActive = false;
         if (this._matchActiveSingleCall(aCall)) {
           // Previously active call is not active now.
           this._activeCall = null;
-        }
-
-        if (!this._activeCall) {
-          // No active call. Disable the audio.
-          gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_NORMAL;
-          if (DEBUG) {
-            debug("No active call, put audio system into PHONE_STATE_NORMAL: " +
-                  gAudioManager.phoneState);
-          }
+          this._updateCallAudioState(aCall);
         }
         break;
     }
   },
 
+  _updateCallAudioState: function(aCall) {
+    // Ignore audio state setting if the call is a placeholder.
+    if (aCall && aCall.callIndex === OUTGOING_PLACEHOLDER_CALL_INDEX) {
+      return;
+    }
+
+    let active = (this._activeCall !== null);
+    let incoming = (aCall &&
+                    aCall.state === nsITelephonyProvider.CALL_STATE_INCOMING);
+
+    if (active) {
+      gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_IN_CALL;
+      if (this.speakerEnabled) {
+        gAudioManager.setForceForUse(nsIAudioManager.USE_COMMUNICATION,
+                                     nsIAudioManager.FORCE_SPEAKER);
+      }
+      if (DEBUG) {
+        debug("Active call, put audio system into PHONE_STATE_IN_CALL: " +
+              gAudioManager.phoneState);
+      }
+    } else if (incoming) {
+      // We can change the phone state into RINGTONE only when there's
+      // no active call.
+      gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_RINGTONE;
+      if (DEBUG) {
+        debug("Incoming call, put audio system into PHONE_STATE_RINGTONE: " +
+              gAudioManager.phoneState);
+      }
+    } else {
+      gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_NORMAL;
+      if (DEBUG) {
+        debug("No active call, put audio system into PHONE_STATE_NORMAL: " +
+              gAudioManager.phoneState);
+      }
+    }
+  },
+
   _convertRILCallState: function(aState) {
     switch (aState) {
       case RIL.CALL_STATE_UNKNOWN:
         return nsITelephonyProvider.CALL_STATE_UNKNOWN;
       case RIL.CALL_STATE_ACTIVE:
         return nsITelephonyProvider.CALL_STATE_CONNECTED;
       case RIL.CALL_STATE_HOLDING:
         return nsITelephonyProvider.CALL_STATE_HELD;
@@ -742,17 +743,17 @@ TelephonyProvider.prototype = {
       serviceId: aClientId,
       emergency: aCall.isEmergency,
       duration: duration,
       direction: aCall.isOutgoing ? "outgoing" : "incoming"
     };
     gSystemMessenger.broadcastMessage("telephony-call-ended", data);
 
     aCall.clientId = aClientId;
-    this._updateCallAudioState(aCall, null);
+    this._updateActiveCall(aCall, null);
 
     let manualConfStateChange = false;
     let childId = this._currentCalls[aClientId][aCall.callIndex].childId;
     if (childId) {
       // Child cannot live without parent.
       let childCall = this._currentCalls[aClientId][childId];
       this.notifyCallDisconnected(aClientId, childCall);
     } else {
@@ -822,17 +823,17 @@ TelephonyProvider.prototype = {
       aCall.state = this._convertRILCallState(aCall.state);
     }
 
     if (aCall.state == nsITelephonyProvider.CALL_STATE_DIALING) {
       gSystemMessenger.broadcastMessage("telephony-new-call", {});
     }
 
     aCall.clientId = aClientId;
-    this._updateCallAudioState(aCall, null);
+    this._updateActiveCall(aCall, null);
 
     let call = this._currentCalls[aClientId][aCall.callIndex];
     if (call) {
       call.state = aCall.state;
       call.isConference = aCall.isConference;
       call.isEmergency = aCall.isEmergency;
       call.isActive = aCall.isActive;
       call.isSwitchable = aCall.isSwitchable != null ?
@@ -886,17 +887,17 @@ TelephonyProvider.prototype = {
     let notification = this._convertRILSuppSvcNotification(aNotification);
     this._notifyAllListeners("supplementaryServiceNotification",
                              [aClientId, aCallIndex, notification]);
   },
 
   notifyConferenceCallStateChanged: function(aState) {
     if (DEBUG) debug("handleConferenceCallStateChanged: " + aState);
     aState = this._convertRILCallState(aState);
-    this._updateCallAudioState(null, aState);
+    this._updateActiveCall(null, aState);
 
     this._notifyAllListeners("conferenceCallStateChanged", [aState]);
   },
 
   /**
    * nsIObserver interface.
    */