зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1050696 - Refactor TelephonyService.dial. r=hsinyi
This commit is contained in:
Родитель
62da4d3530
Коммит
954f5f2638
|
@ -1589,8 +1589,7 @@ RilObject.prototype = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.voiceRegistrationState.emergencyCallsOnly ||
|
if (this.voiceRegistrationState.emergencyCallsOnly) {
|
||||||
options.isDialEmergency) {
|
|
||||||
onerror(RIL_CALL_FAILCAUSE_TO_GECKO_CALL_ERROR[CALL_FAIL_UNOBTAINABLE_NUMBER]);
|
onerror(RIL_CALL_FAILCAUSE_TO_GECKO_CALL_ERROR[CALL_FAIL_UNOBTAINABLE_NUMBER]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1615,6 +1614,7 @@ RilObject.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
options.request = REQUEST_DIAL;
|
options.request = REQUEST_DIAL;
|
||||||
|
options.isEmergency = false;
|
||||||
this.sendDialRequest(options);
|
this.sendDialRequest(options);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1637,6 +1637,8 @@ RilObject.prototype = {
|
||||||
|
|
||||||
options.request = RILQUIRKS_REQUEST_USE_DIAL_EMERGENCY_CALL ?
|
options.request = RILQUIRKS_REQUEST_USE_DIAL_EMERGENCY_CALL ?
|
||||||
REQUEST_DIAL_EMERGENCY_CALL : REQUEST_DIAL;
|
REQUEST_DIAL_EMERGENCY_CALL : REQUEST_DIAL;
|
||||||
|
options.isEmergency = true;
|
||||||
|
|
||||||
if (this.radioState == GECKO_RADIOSTATE_OFF) {
|
if (this.radioState == GECKO_RADIOSTATE_OFF) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
this.context.debug("Automatically enable radio for an emergency call.");
|
this.context.debug("Automatically enable radio for an emergency call.");
|
||||||
|
@ -4109,10 +4111,6 @@ RilObject.prototype = {
|
||||||
newCall.isOutgoing = true;
|
newCall.isOutgoing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newCall.isEmergency === undefined) {
|
|
||||||
newCall.isEmergency = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set flag for conference.
|
// Set flag for conference.
|
||||||
newCall.isConference = newCall.isMpty ? true : false;
|
newCall.isConference = newCall.isMpty ? true : false;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ const GONK_TELEPHONYSERVICE_CONTRACTID =
|
||||||
const GONK_TELEPHONYSERVICE_CID =
|
const GONK_TELEPHONYSERVICE_CID =
|
||||||
Components.ID("{67d26434-d063-4d28-9f48-5b3189788155}");
|
Components.ID("{67d26434-d063-4d28-9f48-5b3189788155}");
|
||||||
|
|
||||||
const NS_XPCOM_SHUTDOWN_OBSERVER_ID = "xpcom-shutdown";
|
const NS_XPCOM_SHUTDOWN_OBSERVER_ID = "xpcom-shutdown";
|
||||||
|
|
||||||
const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
|
const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ const CDMA_SECOND_CALL_INDEX = 2;
|
||||||
|
|
||||||
const DIAL_ERROR_INVALID_STATE_ERROR = "InvalidStateError";
|
const DIAL_ERROR_INVALID_STATE_ERROR = "InvalidStateError";
|
||||||
const DIAL_ERROR_OTHER_CONNECTION_IN_USE = "OtherConnectionInUse";
|
const DIAL_ERROR_OTHER_CONNECTION_IN_USE = "OtherConnectionInUse";
|
||||||
|
const DIAL_ERROR_BAD_NUMBER = RIL.GECKO_CALL_ERROR_BAD_NUMBER;
|
||||||
|
|
||||||
const AUDIO_STATE_NO_CALL = 0;
|
const AUDIO_STATE_NO_CALL = 0;
|
||||||
const AUDIO_STATE_INCOMING = 1;
|
const AUDIO_STATE_INCOMING = 1;
|
||||||
|
@ -428,112 +429,119 @@ TelephonyService.prototype = {
|
||||||
return hasConference ? numCalls + 1 : numCalls;
|
return hasConference ? numCalls + 1 : numCalls;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_addCdmaChildCall: function(aClientId, aNumber, aParentId) {
|
||||||
|
let childCall = {
|
||||||
|
callIndex: CDMA_SECOND_CALL_INDEX,
|
||||||
|
state: RIL.CALL_STATE_DIALING,
|
||||||
|
number: aNumber,
|
||||||
|
isOutgoing: true,
|
||||||
|
isEmergency: false,
|
||||||
|
isConference: false,
|
||||||
|
isSwitchable: false,
|
||||||
|
isMergeable: true,
|
||||||
|
parentId: aParentId
|
||||||
|
};
|
||||||
|
|
||||||
|
// Manual update call state according to the request response.
|
||||||
|
this.notifyCallStateChanged(aClientId, childCall);
|
||||||
|
|
||||||
|
childCall.state = RIL.CALL_STATE_ACTIVE;
|
||||||
|
this.notifyCallStateChanged(aClientId, childCall);
|
||||||
|
|
||||||
|
let parentCall = this._currentCalls[aClientId][childCall.parentId];
|
||||||
|
parentCall.childId = CDMA_SECOND_CALL_INDEX;
|
||||||
|
parentCall.state = RIL.CALL_STATE_HOLDING;
|
||||||
|
parentCall.isSwitchable = false;
|
||||||
|
parentCall.isMergeable = true;
|
||||||
|
this.notifyCallStateChanged(aClientId, parentCall);
|
||||||
|
},
|
||||||
|
|
||||||
isDialing: false,
|
isDialing: false,
|
||||||
dial: function(aClientId, aNumber, aIsEmergency, aTelephonyCallback) {
|
dial: function(aClientId, aNumber, aIsDialEmergency, aCallback) {
|
||||||
if (DEBUG) debug("Dialing " + (aIsEmergency ? "emergency " : "") + aNumber);
|
if (DEBUG) debug("Dialing " + (aIsDialEmergency ? "emergency " : "") + aNumber);
|
||||||
|
|
||||||
if (this.isDialing) {
|
if (this.isDialing) {
|
||||||
if (DEBUG) debug("Error: Already has a dialing call.");
|
if (DEBUG) debug("Error: Already has a dialing call.");
|
||||||
aTelephonyCallback.notifyDialError(DIAL_ERROR_INVALID_STATE_ERROR);
|
aCallback.notifyDialError(DIAL_ERROR_INVALID_STATE_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select a proper clientId for dialEmergency.
|
|
||||||
if (aIsEmergency) {
|
|
||||||
aClientId = gRadioInterfaceLayer.getClientIdForEmergencyCall() ;
|
|
||||||
if (aClientId === -1) {
|
|
||||||
if (DEBUG) debug("Error: No client is avaialble for emergency call.");
|
|
||||||
aTelephonyCallback.notifyDialError(DIAL_ERROR_INVALID_STATE_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// For DSDS, if there is aleady a call on SIM 'aClientId', we cannot place
|
// For DSDS, if there is aleady a call on SIM 'aClientId', we cannot place
|
||||||
// any new call on other SIM.
|
// any new call on other SIM.
|
||||||
if (this._hasCallsOnOtherClient(aClientId)) {
|
if (this._hasCallsOnOtherClient(aClientId)) {
|
||||||
if (DEBUG) debug("Error: Already has a call on other sim.");
|
if (DEBUG) debug("Error: Already has a call on other sim.");
|
||||||
aTelephonyCallback.notifyDialError(DIAL_ERROR_OTHER_CONNECTION_IN_USE);
|
aCallback.notifyDialError(DIAL_ERROR_OTHER_CONNECTION_IN_USE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can only have at most two calls on the same line (client).
|
// We can only have at most two calls on the same line (client).
|
||||||
if (this._numCallsOnLine(aClientId) >= 2) {
|
if (this._numCallsOnLine(aClientId) >= 2) {
|
||||||
if (DEBUG) debug("Error: Has more than 2 calls on line.");
|
if (DEBUG) debug("Error: Has more than 2 calls on line.");
|
||||||
aTelephonyCallback.notifyDialError(DIAL_ERROR_INVALID_STATE_ERROR);
|
aCallback.notifyDialError(DIAL_ERROR_INVALID_STATE_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't try to be too clever here, as the phone is probably in the
|
// We don't try to be too clever here, as the phone is probably in the
|
||||||
// locked state. Let's just check if it's a number without normalizing
|
// locked state. Let's just check if it's a number without normalizing
|
||||||
if (!aIsEmergency) {
|
if (!aIsDialEmergency) {
|
||||||
aNumber = gPhoneNumberUtils.normalize(aNumber);
|
aNumber = gPhoneNumberUtils.normalize(aNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the number.
|
// Validate the number.
|
||||||
|
// Note: isPlainPhoneNumber also accepts USSD and SS numbers
|
||||||
if (!gPhoneNumberUtils.isPlainPhoneNumber(aNumber)) {
|
if (!gPhoneNumberUtils.isPlainPhoneNumber(aNumber)) {
|
||||||
// Note: isPlainPhoneNumber also accepts USSD and SS numbers
|
if (DEBUG) debug("Error: Number '" + aNumber + "' is not viable. Drop.");
|
||||||
if (DEBUG) debug("Number '" + aNumber + "' is not viable. Drop.");
|
aCallback.notifyDialError(DIAL_ERROR_BAD_NUMBER);
|
||||||
let errorMsg = RIL.RIL_CALL_FAILCAUSE_TO_GECKO_CALL_ERROR[RIL.CALL_FAIL_UNOBTAINABLE_NUMBER];
|
|
||||||
aTelephonyCallback.notifyDialError(errorMsg);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCdmaDialSuccess(aCallIndex) {
|
if (this._isEmergencyNumber(aNumber)) {
|
||||||
let indexes = Object.keys(this._currentCalls[aClientId]);
|
// Select a proper clientId for dialEmergency.
|
||||||
if (indexes.length == 0) {
|
aClientId = gRadioInterfaceLayer.getClientIdForEmergencyCall() ;
|
||||||
aTelephonyCallback.notifyDialSuccess(aCallIndex);
|
|
||||||
|
if (aClientId === -1) {
|
||||||
|
if (DEBUG) debug("Error: No client is avaialble for emergency call.");
|
||||||
|
aCallback.notifyDialError(DIAL_ERROR_INVALID_STATE_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RIL doesn't hold the 2nd call. We create one by ourselves.
|
this._dialInternal(aClientId, "dialEmergencyNumber", aNumber, aCallback);
|
||||||
let childCall = {
|
} else {
|
||||||
callIndex: CDMA_SECOND_CALL_INDEX,
|
// Shouldn't dial a non-emergency number by dialEmergency.
|
||||||
state: RIL.CALL_STATE_DIALING,
|
if (aIsDialEmergency) {
|
||||||
number: aNumber,
|
if (DEBUG) debug("Error: dialEmergency with a non-emergency number");
|
||||||
isOutgoing: true,
|
aCallback.notifyDialError(DIAL_ERROR_BAD_NUMBER);
|
||||||
isEmergency: false,
|
return;
|
||||||
isConference: false,
|
}
|
||||||
isSwitchable: false,
|
|
||||||
isMergeable: true,
|
|
||||||
parentId: indexes[0]
|
|
||||||
};
|
|
||||||
aTelephonyCallback.notifyDialSuccess(CDMA_SECOND_CALL_INDEX);
|
|
||||||
|
|
||||||
// Manual update call state according to the request response.
|
this._dialInternal(aClientId, "dialNonEmergencyNumber", aNumber, aCallback);
|
||||||
this.notifyCallStateChanged(aClientId, childCall);
|
}
|
||||||
|
},
|
||||||
|
|
||||||
childCall.state = RIL.CALL_STATE_ACTIVE;
|
_dialInternal: function(aClientId, aMsg, aNumber, aCallback) {
|
||||||
this.notifyCallStateChanged(aClientId, childCall);
|
|
||||||
|
|
||||||
let parentCall = this._currentCalls[aClientId][childCall.parentId];
|
|
||||||
parentCall.childId = CDMA_SECOND_CALL_INDEX;
|
|
||||||
parentCall.state = RIL.CALL_STATE_HOLDING;
|
|
||||||
parentCall.isSwitchable = false;
|
|
||||||
parentCall.isMergeable = true;
|
|
||||||
this.notifyCallStateChanged(aClientId, parentCall);
|
|
||||||
};
|
|
||||||
|
|
||||||
let isEmergencyNumber = this._isEmergencyNumber(aNumber);
|
|
||||||
let msg = isEmergencyNumber ?
|
|
||||||
"dialEmergencyNumber" :
|
|
||||||
"dialNonEmergencyNumber";
|
|
||||||
this.isDialing = true;
|
this.isDialing = true;
|
||||||
this._getClient(aClientId).sendWorkerMessage(msg, {
|
this._getClient(aClientId).sendWorkerMessage(aMsg,
|
||||||
number: aNumber,
|
{number: aNumber},
|
||||||
isEmergency: isEmergencyNumber,
|
(function(response) {
|
||||||
isDialEmergency: aIsEmergency
|
|
||||||
}, (function(response) {
|
|
||||||
this.isDialing = false;
|
this.isDialing = false;
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
aTelephonyCallback.notifyDialError(response.errorMsg);
|
aCallback.notifyDialError(response.errorMsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.isCdma) {
|
if (!response.isCdma) {
|
||||||
onCdmaDialSuccess.call(this, response.callIndex);
|
aCallback.notifyDialSuccess(response.callIndex);
|
||||||
} else {
|
} else {
|
||||||
aTelephonyCallback.notifyDialSuccess(response.callIndex);
|
let currentCallId = Object.keys(this._currentCalls[aClientId])[0];
|
||||||
|
if (currentCallId === undefined) {
|
||||||
|
aCallback.notifyDialSuccess(response.callIndex);
|
||||||
|
} else {
|
||||||
|
// RIL doesn't hold the 2nd call. We create one by ourselves.
|
||||||
|
aCallback.notifyDialSuccess(CDMA_SECOND_CALL_INDEX);
|
||||||
|
this._addCdmaChildCall(aClientId, aNumber, currentCallId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}).bind(this));
|
}).bind(this));
|
||||||
},
|
},
|
||||||
|
@ -615,7 +623,7 @@ TelephonyService.prototype = {
|
||||||
this.notifyCallStateChanged(aClientId, call);
|
this.notifyCallStateChanged(aClientId, call);
|
||||||
}
|
}
|
||||||
this.notifyConferenceCallStateChanged(RIL.CALL_STATE_ACTIVE);
|
this.notifyConferenceCallStateChanged(RIL.CALL_STATE_ACTIVE);
|
||||||
};
|
}
|
||||||
|
|
||||||
this._getClient(aClientId).sendWorkerMessage("conferenceCall", null,
|
this._getClient(aClientId).sendWorkerMessage("conferenceCall", null,
|
||||||
(function(response) {
|
(function(response) {
|
||||||
|
@ -660,7 +668,7 @@ TelephonyService.prototype = {
|
||||||
|
|
||||||
let childCall = this._currentCalls[aClientId][childId];
|
let childCall = this._currentCalls[aClientId][childId];
|
||||||
this.notifyCallDisconnected(aClientId, childCall);
|
this.notifyCallDisconnected(aClientId, childCall);
|
||||||
};
|
}
|
||||||
|
|
||||||
this._getClient(aClientId).sendWorkerMessage("separateCall", {
|
this._getClient(aClientId).sendWorkerMessage("separateCall", {
|
||||||
callIndex: aCallIndex
|
callIndex: aCallIndex
|
||||||
|
@ -825,28 +833,25 @@ TelephonyService.prototype = {
|
||||||
aCall.clientId = aClientId;
|
aCall.clientId = aClientId;
|
||||||
this._updateActiveCall(aCall);
|
this._updateActiveCall(aCall);
|
||||||
|
|
||||||
|
function pick(arg, defaultValue) {
|
||||||
|
return typeof arg !== 'undefined' ? arg : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
let call = this._currentCalls[aClientId][aCall.callIndex];
|
let call = this._currentCalls[aClientId][aCall.callIndex];
|
||||||
if (call) {
|
if (call) {
|
||||||
call.state = aCall.state;
|
call.state = aCall.state;
|
||||||
call.isConference = aCall.isConference;
|
call.isConference = aCall.isConference;
|
||||||
call.isEmergency = aCall.isEmergency;
|
call.isEmergency = pick(aCall.isEmergency, call.isEmergency);
|
||||||
call.isSwitchable = aCall.isSwitchable != null ?
|
call.isSwitchable = pick(aCall.isSwitchable, call.isSwitchable);
|
||||||
aCall.isSwitchable : call.isSwitchable;
|
call.isMergeable = pick(aCall.isMergeable, call.isMergeable);
|
||||||
call.isMergeable = aCall.isMergeable != null ?
|
|
||||||
aCall.isMergeable : call.isMergeable;
|
|
||||||
} else {
|
} else {
|
||||||
call = aCall;
|
call = aCall;
|
||||||
call.isSwitchable = aCall.isSwitchable != null ?
|
call.isEmergency = pick(aCall.isEmergency, this._isEmergencyNumber(aCall.number));
|
||||||
aCall.isSwitchable : true;
|
call.isSwitchable = pick(aCall.isSwitchable, true);
|
||||||
call.isMergeable = aCall.isMergeable != null ?
|
call.isMergeable = pick(aCall.isMergeable, true);
|
||||||
aCall.isMergeable : true;
|
call.name = pick(aCall.name, "");
|
||||||
|
call.numberPresentaation = pick(aCall.numberPresentation, nsITelephonyService.CALL_PRESENTATION_ALLOWED);
|
||||||
call.numberPresentation = aCall.numberPresentation != null ?
|
call.namePresentaation = pick(aCall.namePresentation, nsITelephonyService.CALL_PRESENTATION_ALLOWED);
|
||||||
aCall.numberPresentation : nsITelephonyService.CALL_PRESENTATION_ALLOWED;
|
|
||||||
call.name = aCall.name != null ?
|
|
||||||
aCall.name : "";
|
|
||||||
call.namePresentation = aCall.namePresentation != null ?
|
|
||||||
aCall.namePresentation : nsITelephonyService.CALL_PRESENTATION_ALLOWED;
|
|
||||||
|
|
||||||
this._currentCalls[aClientId][aCall.callIndex] = call;
|
this._currentCalls[aClientId][aCall.callIndex] = call;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче