Bug 830425 - Phone takes too long to wake up for incoming phone calls (acquire and release wake locks in RadioInterfaceLayer.js). r=philikon a=tef+

This commit is contained in:
Gene Lian 2013-01-24 16:35:50 +08:00
parent 4dfec8f0a4
commit 8c1e40b864

View File

@ -61,6 +61,8 @@ const DOM_SMS_DELIVERY_SENDING = "sending";
const DOM_SMS_DELIVERY_SENT = "sent";
const DOM_SMS_DELIVERY_ERROR = "error";
const CALL_WAKELOCK_TIMEOUT = 5000;
const RIL_IPC_TELEPHONY_MSG_NAMES = [
"RIL:EnumerateCalls",
"RIL:GetMicrophoneMuted",
@ -107,6 +109,10 @@ const RIL_IPC_CELLBROADCAST_MSG_NAMES = [
"RIL:RegisterCellBroadcastMsg"
];
XPCOMUtils.defineLazyServiceGetter(this, "gPowerManagerService",
"@mozilla.org/power/powermanagerservice;1",
"nsIPowerManagerService");
XPCOMUtils.defineLazyServiceGetter(this, "gSmsService",
"@mozilla.org/sms/smsservice;1",
"nsISmsService");
@ -1237,6 +1243,18 @@ RadioInterfaceLayer.prototype = {
}
},
_callRingWakeLock: null,
_callRingWakeLockTimer: null,
_cancelCallRingWakeLockTimer: function _cancelCallRingWakeLockTimer() {
if (this._callRingWakeLockTimer) {
this._callRingWakeLockTimer.cancel();
}
if (this._callRingWakeLock) {
this._callRingWakeLock.unlock();
this._callRingWakeLock = null;
}
},
/**
* Handle an incoming call.
*
@ -1244,6 +1262,17 @@ RadioInterfaceLayer.prototype = {
* to start bringing up the Phone app already.
*/
handleCallRing: function handleCallRing() {
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);
gSystemMessenger.broadcastMessage("telephony-new-call", {});
},
@ -1724,6 +1753,8 @@ RadioInterfaceLayer.prototype = {
for (let msgname of RIL_IPC_CELLBROADCAST_MSG_NAMES) {
ppmm.removeMessageListener(msgname, this);
}
// Cancel the timer for the call-ring wake lock.
this._cancelCallRingWakeLockTimer();
// Shutdown all RIL network interfaces
this.dataNetworkInterface.shutdown();
this.mmsNetworkInterface.shutdown();