Bug 1021550 - Removed the check to set the PHONE_STATE_NORMAL for speaker/mic when there are no active calls. Added test. r=hsinyi.
authorTamara Hills <thills@mozilla.com>
Tue, 08 Jul 2014 11:02:51 +0800
changeset 192742 90fde19681b94864b9915747d39d9c75f7c49dea
parent 192741 3614132caaa3b1b83751ceef1f93a5f066177bfc
child 192743 7952db5a55805b95c97a69c17593ce4931802c6e
push id7651
push usercbook@mozilla.com
push dateTue, 08 Jul 2014 13:28:32 +0000
treeherderfx-team@05cfda67b9db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs1021550
milestone33.0a1
Bug 1021550 - Removed the check to set the PHONE_STATE_NORMAL for speaker/mic when there are no active calls. Added test. r=hsinyi.
dom/telephony/gonk/TelephonyService.js
dom/telephony/test/marionette/manifest.ini
dom/telephony/test/marionette/test_audiomanager_phonestate.js
dom/telephony/test/marionette/test_incomingcall_phonestate_speaker.js
--- a/dom/telephony/gonk/TelephonyService.js
+++ b/dom/telephony/gonk/TelephonyService.js
@@ -688,38 +688,30 @@ TelephonyService.prototype = {
     return gAudioManager.microphoneMuted;
   },
 
   set microphoneMuted(aMuted) {
     if (aMuted == this.microphoneMuted) {
       return;
     }
     gAudioManager.microphoneMuted = aMuted;
-
-    if (!this._numActiveCall) {
-      gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_NORMAL;
-    }
   },
 
   get speakerEnabled() {
     let force = gAudioManager.getForceForUse(nsIAudioManager.USE_COMMUNICATION);
     return (force == nsIAudioManager.FORCE_SPEAKER);
   },
 
   set speakerEnabled(aEnabled) {
     if (aEnabled == this.speakerEnabled) {
       return;
     }
     let force = aEnabled ? nsIAudioManager.FORCE_SPEAKER :
                            nsIAudioManager.FORCE_NONE;
     gAudioManager.setForceForUse(nsIAudioManager.USE_COMMUNICATION, force);
-
-    if (!this._numActiveCall) {
-      gAudioManager.phoneState = nsIAudioManager.PHONE_STATE_NORMAL;
-    }
   },
 
   /**
    * nsIGonkTelephonyService interface.
    */
 
   /**
    * Handle call disconnects by updating our current state and the audio system.
--- a/dom/telephony/test/marionette/manifest.ini
+++ b/dom/telephony/test/marionette/manifest.ini
@@ -53,8 +53,9 @@ disabled = Bug 821958
 [test_conference_remove_error.js]
 [test_conference_two_hangup_one.js]
 [test_conference_two_hold_resume.js]
 [test_conference_two_remove_one.js]
 [test_conference_three_hangup_one.js]
 [test_conference_three_remove_one.js]
 [test_outgoing_when_two_calls_on_line.js]
 [test_call_presentation.js]
+[test_incomingcall_phonestate_speaker.js]
--- a/dom/telephony/test/marionette/test_audiomanager_phonestate.js
+++ b/dom/telephony/test/marionette/test_audiomanager_phonestate.js
@@ -55,21 +55,17 @@ startTest(function() {
   let inCall;
 
   Promise.resolve()
     .then(() => check(PHONE_STATE_CURRENT, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
 
     // Dial in
     .then(() => gRemoteDial(inNumber))
     .then(call => { inCall = call; })
-    // TODO - Bug 948860: should this be {RINGTONE, RINGTONE, RINGTONE}?
-    // From current UX spec, there is no chance that an user may enable speaker
-    // during alerting, so basically this 'set speaker enable' action can't
-    // happen in B2G.
-    .then(() => check(PHONE_STATE_RINGTONE, PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
+    .then(() => check(PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE))
     .then(() => gAnswer(inCall))
     .then(() => check(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL))
     // Hang up all
     .then(() => gRemoteHangUp(inCall))
     .then(() => check(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL))
 
     // Dial out
     .then(() => gDial(outNumber))
new file mode 100644
--- /dev/null
+++ b/dom/telephony/test/marionette/test_incomingcall_phonestate_speaker.js
@@ -0,0 +1,66 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
+
+const AUDIO_MANAGER_CONTRACT_ID = "@mozilla.org/telephony/audiomanager;1";
+
+// See nsIAudioManager
+const PHONE_STATE_INVALID          = -2;
+const PHONE_STATE_CURRENT          = -1;
+const PHONE_STATE_NORMAL           = 0;
+const PHONE_STATE_RINGTONE         = 1;
+const PHONE_STATE_IN_CALL          = 2;
+const PHONE_STATE_IN_COMMUNICATION = 3;
+
+let audioManager;
+
+function checkSpeakerEnabled(phoneStatePrev, phoneStateNew, toggle, setSpeaker) {
+  if (!audioManager) {
+    audioManager = SpecialPowers.Cc[AUDIO_MANAGER_CONTRACT_ID]
+      .getService(SpecialPowers.Ci.nsIAudioManager);
+    ok(audioManager, "nsIAudioManager instance");
+  }
+
+  is(audioManager.phoneState, phoneStatePrev, "audioManager.phoneState");
+  if (toggle) {
+    telephony.speakerEnabled = setSpeaker;
+  }
+  is(audioManager.phoneState, phoneStateNew, "audioManager.phoneState");
+}
+
+// Start the test
+startTest(function() {
+  let inNumber  = "5555550201";
+  let inCall;
+
+  Promise.resolve()
+    .then(() => checkSpeakerEnabled(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL, false, false))
+    // Dial in
+    .then(() => gRemoteDial(inNumber))
+    .then(call => { inCall = call; })
+    .then(() => checkSpeakerEnabled(PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE, false, false))
+    .then(() => gAnswer(inCall))
+    .then(() => checkSpeakerEnabled(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL, false, false))
+    // Go on Speaker (Don't go off speaker before hanging up.  This is to check
+    // the condition for bug 1021550)
+    .then(() => checkSpeakerEnabled(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL, true, true))
+    // Hang up all
+    .then(() => gRemoteHangUp(inCall))
+    .then(() => checkSpeakerEnabled(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL, false, false))
+    // Make a second inbound call
+    .then(() => gRemoteDial(inNumber))
+    .then(call => { inCall = call; })
+    .then(() => checkSpeakerEnabled(PHONE_STATE_RINGTONE, PHONE_STATE_RINGTONE, false, false))
+    .then(() => gAnswer(inCall))
+    .then(() => checkSpeakerEnabled(PHONE_STATE_IN_CALL, PHONE_STATE_IN_CALL, false, false))
+    // Hang up the call
+    .then(() => gRemoteHangUp(inCall))
+    .then(() => checkSpeakerEnabled(PHONE_STATE_NORMAL, PHONE_STATE_NORMAL, false, false))
+    // End
+    .then(null, error => {
+      ok(false, 'promise rejects during test.');
+    })
+    .then(finish);
+});