Bug 915071 - Panel screen is still off while 2nd incoming call in dialling. r=hsinyi a=koi+
authorGene Lian <clian@mozilla.com>
Mon, 28 Oct 2013 14:07:28 +0800
changeset 167228 4aacf3bcff3cb396aa80467ffa09d4aface30183
parent 167227 6f8bbab9aee350363a3cb2bebe4a62aacaebc847
child 167229 085c6286911f5a0537c96ccb7206ad9fedb5fa29
child 167244 359e183f3c0a8b4897fc26faeced33cc2f4f6057
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi, koi
bugs915071
milestone27.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 915071 - Panel screen is still off while 2nd incoming call in dialling. r=hsinyi a=koi+
dom/system/gonk/RadioInterfaceLayer.js
dom/telephony/gonk/TelephonyProvider.js
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -1758,22 +1758,23 @@ RadioInterface.prototype = {
       receiver:       aDomMessage.receiver,
       body:           aDomMessage.body,
       messageClass:   aDomMessage.messageClass,
       timestamp:      aDomMessage.timestamp,
       read:           aDomMessage.read
     });
   },
 
-  // The following attributes/functions are used for acquiring the CPU wake
-  // lock when the RIL handles the received SMS. Note that we need a timer to
-  // bound the lock's life cycle to avoid exhausting the battery.
+  // The following attributes/functions are used for acquiring/releasing the
+  // CPU wake lock when the RIL handles the received SMS. Note that we need
+  // a timer to bound the lock's life cycle to avoid exhausting the battery.
   _smsHandledWakeLock: null,
   _smsHandledWakeLockTimer: null,
-  _cancelSmsHandledWakeLockTimer: function _cancelSmsHandledWakeLockTimer() {
+
+  _releaseSmsHandledWakeLock: function _releaseSmsHandledWakeLock() {
     if (DEBUG) this.debug("Releasing the CPU wake lock for handling SMS.");
     if (this._smsHandledWakeLockTimer) {
       this._smsHandledWakeLockTimer.cancel();
     }
     if (this._smsHandledWakeLock) {
       this._smsHandledWakeLock.unlock();
       this._smsHandledWakeLock = null;
     }
@@ -1791,17 +1792,17 @@ RadioInterface.prototype = {
     }
     if (!this._smsHandledWakeLockTimer) {
       if (DEBUG) this.debug("Creating a timer for releasing the CPU wake lock.");
       this._smsHandledWakeLockTimer =
         Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     }
     if (DEBUG) this.debug("Setting the timer for releasing the CPU wake lock.");
     this._smsHandledWakeLockTimer
-        .initWithCallback(this._cancelSmsHandledWakeLockTimer.bind(this),
+        .initWithCallback(this._releaseSmsHandledWakeLock.bind(this),
                           SMS_HANDLED_WAKELOCK_TIMEOUT,
                           Ci.nsITimer.TYPE_ONE_SHOT);
 
     // FIXME: Bug 737202 - Typed arrays become normal arrays when sent to/from workers
     if (message.encoding == RIL.PDU_DCS_MSG_CODING_8BITS_ALPHABET) {
       message.fullData = new Uint8Array(message.fullData);
     }
 
@@ -2169,18 +2170,18 @@ RadioInterface.prototype = {
           try {
             value = Services.prefs.getBoolPref(kPrefCellBroadcastDisabled);
           } catch(e) {}
           this.workerMessenger.send("setCellBroadcastDisabled",
                                     { disabled: value });
         }
         break;
       case NS_XPCOM_SHUTDOWN_OBSERVER_ID:
-        // Cancel the timer of the CPU wake lock for handling the received SMS.
-        this._cancelSmsHandledWakeLockTimer();
+        // Release the CPU wake lock for handling the received SMS.
+        this._releaseSmsHandledWakeLock();
 
         // Shutdown all RIL network interfaces
         for each (let apnSetting in this.apnSettings.byAPN) {
           if (apnSetting.iface) {
             apnSetting.iface.shutdown();
           }
         }
         Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
--- a/dom/telephony/gonk/TelephonyProvider.js
+++ b/dom/telephony/gonk/TelephonyProvider.js
@@ -102,19 +102,40 @@ TelephonyProvider.prototype = {
                                     classDescription: "TelephonyProvider",
                                     interfaces: [Ci.nsITelephonyProvider,
                                                  Ci.nsIGonkTelephonyProvider],
                                     flags: Ci.nsIClassInfo.SINGLETON}),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyProvider,
                                          Ci.nsIGonkTelephonyProvider,
                                          Ci.nsIObserver]),
 
+  // The following attributes/functions are used for acquiring/releasing the
+  // CPU wake lock when the RIL handles the incoming call. Note that we need
+  // a timer to bound the lock's life cycle to avoid exhausting the battery.
   _callRingWakeLock: null,
   _callRingWakeLockTimer: null,
-  _cancelCallRingWakeLockTimer: function _cancelCallRingWakeLockTimer() {
+
+  _acquireCallRingWakeLock: function _acquireCallRingWakeLock() {
+    if (!this._callRingWakeLock) {
+      if (DEBUG) debug("Acquiring a CPU wake lock for handling incoming call.");
+      this._callRingWakeLock = gPowerManagerService.newWakeLock("cpu");
+    }
+    if (!this._callRingWakeLockTimer) {
+      if (DEBUG) debug("Creating a timer for releasing the CPU wake lock.");
+      this._callRingWakeLockTimer =
+        Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+    }
+    if (DEBUG) debug("Setting the timer for releasing the CPU wake lock.");
+    this._callRingWakeLockTimer
+        .initWithCallback(this._releaseCallRingWakeLock.bind(this),
+                          CALL_WAKELOCK_TIMEOUT, Ci.nsITimer.TYPE_ONE_SHOT);
+  },
+
+  _releaseCallRingWakeLock: function _releaseCallRingWakeLock() {
+    if (DEBUG) debug("Releasing the CPU wake lock for handling incoming call.");
     if (this._callRingWakeLockTimer) {
       this._callRingWakeLockTimer.cancel();
     }
     if (this._callRingWakeLock) {
       this._callRingWakeLock.unlock();
       this._callRingWakeLock = null;
     }
   },
@@ -460,26 +481,19 @@ TelephonyProvider.prototype = {
 
   /**
    * Handle an incoming call.
    *
    * Not much is known about this call at this point, but it's enough
    * to start bringing up the Phone app already.
    */
   notifyCallRing: function notifyCallRing() {
-    if (!this._callRingWakeLock) {
-      this._callRingWakeLock = gPowerManagerService.newWakeLock("cpu");
-    }
-    if (!this._callRingWakeLockTimer) {
-      this._callRingWakeLockTimer =
-        Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    }
-    this._callRingWakeLockTimer
-        .initWithCallback(this._cancelCallRingWakeLockTimer.bind(this),
-                          CALL_WAKELOCK_TIMEOUT, Ci.nsITimer.TYPE_ONE_SHOT);
+    // We need to acquire a CPU wake lock to avoid the system falling into
+    // the sleep mode when the RIL handles the incoming call.
+    this._acquireCallRingWakeLock();
 
     gSystemMessenger.broadcastMessage("telephony-new-call", {});
   },
 
   /**
    * Handle call state changes by updating our current state and the audio
    * system.
    */
@@ -498,16 +512,20 @@ TelephonyProvider.prototype = {
                                                   aCall.number,
                                                   aCall.isActive,
                                                   aCall.isOutgoing,
                                                   aCall.isEmergency,
                                                   aCall.isConference]);
   },
 
   notifyCdmaCallWaiting: function notifyCdmaCallWaiting(aNumber) {
+    // We need to acquire a CPU wake lock to avoid the system falling into
+    // the sleep mode when the RIL handles the incoming call.
+    this._acquireCallRingWakeLock();
+
     this._notifyAllListeners("notifyCdmaCallWaiting", [aNumber]);
   },
 
   notifySupplementaryService: function notifySupplementaryService(aCallIndex,
                                                                   aNotification) {
     let notification = this._convertRILSuppSvcNotification(aNotification);
     this._notifyAllListeners("supplementaryServiceNotification",
                              [aCallIndex, notification]);
@@ -531,18 +549,18 @@ TelephonyProvider.prototype = {
         if (aData === kPrefRilDebuggingEnabled) {
           this._updateDebugFlag();
 	} else if (aData === kPrefDefaultServiceId) {
           this.defaultServiceId = this._getDefaultServiceId();
         }
         break;
 
       case NS_XPCOM_SHUTDOWN_OBSERVER_ID:
-        // Cancel the timer for the call-ring wake lock.
-        this._cancelCallRingWakeLockTimer();
+        // Release the CPU wake lock for handling the incoming call.
+        this._releaseCallRingWakeLock();
 
         Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
         break;
     }
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelephonyProvider]);