Bug 1159591 - Part 8: Move MMI logic from ril_worker to telephonyService (Call Barring). r=aknow

This commit is contained in:
Edgar Chen 2015-04-30 18:58:30 +08:00
parent 17084a2b82
commit d034fa3d07
4 changed files with 84 additions and 161 deletions

View File

@ -3037,17 +3037,6 @@ this.MMI_SC_BA_ALL = "330";
this.MMI_SC_BA_MO = "333";
this.MMI_SC_BA_MT = "353";
this.MMI_SC_TO_CB_FACILITY = {};
MMI_SC_TO_CB_FACILITY[MMI_SC_BAOC] = ICC_CB_FACILITY_BAOC;
MMI_SC_TO_CB_FACILITY[MMI_SC_BAOIC] = ICC_CB_FACILITY_BAOIC;
MMI_SC_TO_CB_FACILITY[MMI_SC_BAOICxH] = ICC_CB_FACILITY_BAOICxH;
MMI_SC_TO_CB_FACILITY[MMI_SC_BAIC] = ICC_CB_FACILITY_BAIC;
MMI_SC_TO_CB_FACILITY[MMI_SC_BAICr] = ICC_CB_FACILITY_BAICr;
MMI_SC_TO_CB_FACILITY[MMI_SC_BA_ALL] = ICC_CB_FACILITY_BA_ALL;
MMI_SC_TO_CB_FACILITY[MMI_SC_BA_MO] = ICC_CB_FACILITY_BA_MO;
MMI_SC_TO_CB_FACILITY[MMI_SC_BA_MT] = ICC_CB_FACILITY_BA_MT;
// MMI service code key strings.
this.MMI_KS_SC_CALL_BARRING = "scCallBarring";
this.MMI_KS_SC_CALL_FORWARDING = "scCallForwarding";

View File

@ -1928,34 +1928,6 @@ RilObject.prototype = {
// trigger the appropriate RIL request if possible.
let sc = mmi.serviceCode;
switch (sc) {
// Call barring
case MMI_SC_BAOC:
case MMI_SC_BAOIC:
case MMI_SC_BAOICxH:
case MMI_SC_BAIC:
case MMI_SC_BAICr:
case MMI_SC_BA_ALL:
case MMI_SC_BA_MO:
case MMI_SC_BA_MT:
options.password = mmi.sia || "";
options.serviceClass = this._siToServiceClass(mmi.sib);
options.facility = MMI_SC_TO_CB_FACILITY[sc];
options.procedure = mmi.procedure;
if (mmi.procedure === MMI_PROCEDURE_INTERROGATION) {
this.queryICCFacilityLock(options);
return;
}
if (mmi.procedure === MMI_PROCEDURE_ACTIVATION) {
options.enabled = 1;
} else if (mmi.procedure === MMI_PROCEDURE_DEACTIVATION) {
options.enabled = 0;
} else {
_sendMMIError(MMI_ERROR_KS_NOT_SUPPORTED);
return;
}
this.setICCFacilityLock(options);
return;
// Call waiting
case MMI_SC_CALL_WAITING:
if (!_isRadioAvailable()) {
@ -4676,47 +4648,18 @@ RilObject.prototype[REQUEST_QUERY_FACILITY_LOCK] = function REQUEST_QUERY_FACILI
}
// Buf.readInt32List()[0] for Call Barring is a bit vector of services.
let services = this.context.Buf.readInt32List()[0];
options.serviceClass = this.context.Buf.readInt32List()[0];
if (options.queryServiceClass) {
options.enabled = (services & options.queryServiceClass) ? true : false;
options.enabled = (options.serviceClass & options.queryServiceClass) ? true : false;
options.serviceClass = options.queryServiceClass;
} else {
options.enabled = services ? true : false;
options.enabled = options.serviceClass ? true : false;
}
if (options.rilMessageType === "sendMMI") {
if (!options.enabled) {
options.statusMessage = MMI_SM_KS_SERVICE_DISABLED;
} else {
options.statusMessage = MMI_SM_KS_SERVICE_ENABLED_FOR;
let serviceClass = [];
for (let serviceClassMask = 1;
serviceClassMask <= ICC_SERVICE_CLASS_MAX;
serviceClassMask <<= 1) {
if ((serviceClassMask & services) !== 0) {
serviceClass.push(MMI_KS_SERVICE_CLASS_MAPPING[serviceClassMask]);
}
}
options.additionalInformation = serviceClass;
}
}
this.sendChromeMessage(options);
};
RilObject.prototype[REQUEST_SET_FACILITY_LOCK] = function REQUEST_SET_FACILITY_LOCK(length, options) {
options.retryCount = length ? this.context.Buf.readInt32List()[0] : -1;
if (!options.errorMsg && (options.rilMessageType === "sendMMI")) {
switch (options.procedure) {
case MMI_PROCEDURE_ACTIVATION:
options.statusMessage = MMI_SM_KS_SERVICE_ENABLED;
break;
case MMI_PROCEDURE_DEACTIVATION:
options.statusMessage = MMI_SM_KS_SERVICE_DISABLED;
break;
}
}
this.sendChromeMessage(options);
};
RilObject.prototype[REQUEST_CHANGE_BARRING_PASSWORD] =

View File

@ -69,96 +69,6 @@ add_test(function test_sendMMI_short_code() {
run_next_test();
});
add_test(function test_sendMMI_call_barring_BAIC_interrogation_voice() {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
context.Buf.readInt32List = function fakeReadUint32List() {
return [1];
};
context.RIL.queryICCFacilityLock =
function fakeQueryICCFacilityLock(options) {
context.RIL[REQUEST_QUERY_FACILITY_LOCK](1, {
rilMessageType: "sendMMI"
});
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: createMMIOptions("*#", "33")});
let postedMessage = workerhelper.postedMessage;
equal(postedMessage.errorMsg, undefined);
ok(postedMessage.enabled);
equal(postedMessage.statusMessage, MMI_SM_KS_SERVICE_ENABLED_FOR);
ok(Array.isArray(postedMessage.additionalInformation));
equal(postedMessage.additionalInformation[0], "serviceClassVoice");
run_next_test();
});
add_test(function test_sendMMI_call_barring_BAIC_activation() {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
context.RIL.setICCFacilityLock =
function fakeSetICCFacilityLock(options) {
mmiOptions = options;
context.RIL[REQUEST_SET_FACILITY_LOCK](0, {
rilMessageType: "sendMMI",
procedure: MMI_PROCEDURE_ACTIVATION
});
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: createMMIOptions("*", "33")});
let postedMessage = workerhelper.postedMessage;
equal(mmiOptions.procedure, MMI_PROCEDURE_ACTIVATION);
equal(postedMessage.errorMsg, undefined);
equal(postedMessage.statusMessage, MMI_SM_KS_SERVICE_ENABLED);
run_next_test();
});
add_test(function test_sendMMI_call_barring_BAIC_deactivation() {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
context.RIL.setICCFacilityLock =
function fakeSetICCFacilityLock(options) {
mmiOptions = options;
context.RIL[REQUEST_SET_FACILITY_LOCK](0, {
rilMessageType: "sendMMI",
procedure: MMI_PROCEDURE_DEACTIVATION
});
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: createMMIOptions("#", "33")});
let postedMessage = workerhelper.postedMessage;
equal(mmiOptions.procedure, MMI_PROCEDURE_DEACTIVATION);
equal(postedMessage.errorMsg, undefined);
equal(postedMessage.statusMessage, MMI_SM_KS_SERVICE_DISABLED);
run_next_test();
});
add_test(function test_sendMMI_call_barring_BAIC_procedure_not_supported() {
testSendMMI(createMMIOptions("**", "33", "0000"), MMI_ERROR_KS_NOT_SUPPORTED);
run_next_test();
});
add_test(function test_sendMMI_USSD() {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;

View File

@ -63,6 +63,16 @@ const MMI_PROC_TO_CLIR_ACTION = {};
MMI_PROC_TO_CLIR_ACTION[RIL.MMI_PROCEDURE_ACTIVATION] = Ci.nsIMobileConnection.CLIR_INVOCATION;
MMI_PROC_TO_CLIR_ACTION[RIL.MMI_PROCEDURE_DEACTIVATION] = Ci.nsIMobileConnection.CLIR_SUPPRESSION;
const MMI_SC_TO_CB_PROGRAM = {};
MMI_SC_TO_CB_PROGRAM[RIL.MMI_SC_BAOC] = Ci.nsIMobileConnection.CALL_BARRING_PROGRAM_ALL_OUTGOING;
MMI_SC_TO_CB_PROGRAM[RIL.MMI_SC_BAOIC] = Ci.nsIMobileConnection.CALL_BARRING_PROGRAM_OUTGOING_INTERNATIONAL;
MMI_SC_TO_CB_PROGRAM[RIL.MMI_SC_BAOICxH] = Ci.nsIMobileConnection.CALL_BARRING_PROGRAM_OUTGOING_INTERNATIONAL_EXCEPT_HOME;
MMI_SC_TO_CB_PROGRAM[RIL.MMI_SC_BAIC] = Ci.nsIMobileConnection.CALL_BARRING_PROGRAM_ALL_INCOMING;
MMI_SC_TO_CB_PROGRAM[RIL.MMI_SC_BAICr] = Ci.nsIMobileConnection.CALL_BARRING_PROGRAM_INCOMING_ROAMING;
MMI_SC_TO_CB_PROGRAM[RIL.MMI_SC_BA_ALL] = Ci.nsIMobileConnection.CALL_BARRING_PROGRAM_ALL_SERVICE;
MMI_SC_TO_CB_PROGRAM[RIL.MMI_SC_BA_MO] = Ci.nsIMobileConnection.CALL_BARRING_PROGRAM_OUTGOING_SERVICE;
MMI_SC_TO_CB_PROGRAM[RIL.MMI_SC_BA_MT] = Ci.nsIMobileConnection.CALL_BARRING_PROGRAM_INCOMING_SERVICE;
const CF_ACTION_TO_STATUS_MESSAGE = {};
CF_ACTION_TO_STATUS_MESSAGE[Ci.nsIMobileConnection.CALL_FORWARD_ACTION_ENABLE] = RIL.MMI_SM_KS_SERVICE_ENABLED;
CF_ACTION_TO_STATUS_MESSAGE[Ci.nsIMobileConnection.CALL_FORWARD_ACTION_DISABLE] = RIL.MMI_SM_KS_SERVICE_DISABLED;
@ -896,6 +906,11 @@ TelephonyService.prototype = {
this._callBarringPasswordMMI(aClientId, aMmi, aCallback);
break;
// Call barring
case RIL.MMI_KS_SC_CALL_BARRING:
this._callBarringMMI(aClientId, aMmi, aCallback);
break;
// Fall back to "sendMMI".
default:
this._sendMMI(aClientId, aMmi, aCallback);
@ -1312,6 +1327,72 @@ TelephonyService.prototype = {
});
},
/**
* Handle call barring MMI code.
*
* @param aClientId
* Client id.
* @param aMmi
* Parsed MMI structure.
* @param aCallback
* A nsITelephonyDialCallback object.
*/
_callBarringMMI: function(aClientId, aMmi, aCallback) {
let connection = gGonkMobileConnectionService.getItemByServiceId(aClientId);
let program = MMI_SC_TO_CB_PROGRAM[aMmi.serviceCode];
let password = aMmi.sia || "";
let serviceClass = this._siToServiceClass(aMmi.sib);
switch (aMmi.procedure) {
case RIL.MMI_PROCEDURE_INTERROGATION:
connection.getCallBarring(program, password, serviceClass, {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileConnectionCallback]),
notifyGetCallBarringSuccess: function(aProgram, aEnabled, aServiceClass) {
if (!aEnabled) {
aCallback.notifyDialMMISuccess(RIL.MMI_SM_KS_SERVICE_DISABLED);
return;
}
let services = [];
for (let mask = 1;
mask <= Ci.nsIMobileConnection.ICC_SERVICE_CLASS_MAX;
mask <<= 1) {
if (mask & aServiceClass) {
services.push(RIL.MMI_KS_SERVICE_CLASS_MAPPING[mask]);
}
}
aCallback.notifyDialMMISuccessWithStrings(RIL.MMI_SM_KS_SERVICE_ENABLED_FOR,
services.length, services);
},
notifyError: function(aErrorMsg) {
aCallback.notifyDialMMIError(aErrorMsg);
},
});
break;
case RIL.MMI_PROCEDURE_ACTIVATION:
case RIL.MMI_PROCEDURE_DEACTIVATION: {
let enabled = (aMmi.procedure === RIL.MMI_PROCEDURE_ACTIVATION);
connection.setCallBarring(program, enabled, password, serviceClass, {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileConnectionCallback]),
notifySuccess: function() {
aCallback.notifyDialMMISuccess(
enabled ? RIL.MMI_SM_KS_SERVICE_ENABLED
: RIL.MMI_SM_KS_SERVICE_DISABLED
);
},
notifyError: function(aErrorMsg) {
aCallback.notifyDialMMIError(aErrorMsg);
},
});
break;
}
default:
aCallback.notifyDialMMIError(RIL.MMI_ERROR_KS_NOT_SUPPORTED);
break;
}
},
_serviceCodeToKeyString: function(aServiceCode) {
switch (aServiceCode) {
case RIL.MMI_SC_CFU: