From e7897c4f39085c1f9e25cf204a4d9321c56767c9 Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Tue, 13 May 2014 14:36:18 +0800 Subject: [PATCH] Bug 986395 - Part 1: Correct the API behavior of setPreferredNetworkType(). r=hsinyi --- dom/system/gonk/RILContentHelper.js | 14 ++++++++++ dom/system/gonk/RadioInterfaceLayer.js | 15 ---------- dom/system/gonk/ril_worker.js | 38 ++++++-------------------- 3 files changed, 23 insertions(+), 44 deletions(-) diff --git a/dom/system/gonk/RILContentHelper.js b/dom/system/gonk/RILContentHelper.js index 704c6efbf7d8..b65032475c01 100644 --- a/dom/system/gonk/RILContentHelper.js +++ b/dom/system/gonk/RILContentHelper.js @@ -789,6 +789,13 @@ RILContentHelper.prototype = { let request = Services.DOMRequest.createRequest(window); let requestId = this.getRequestId(request); + let radioState = this.rilContexts[clientId].radioState; + if (radioState !== RIL.GECKO_DETAILED_RADIOSTATE_ENABLED) { + this.dispatchFireRequestError(requestId, + RIL.GECKO_ERROR_RADIO_NOT_AVAILABLE); + return request; + } + cpmm.sendAsyncMessage("RIL:SetPreferredNetworkType", { clientId: clientId, data: { @@ -808,6 +815,13 @@ RILContentHelper.prototype = { let request = Services.DOMRequest.createRequest(window); let requestId = this.getRequestId(request); + let radioState = this.rilContexts[clientId].radioState; + if (radioState !== RIL.GECKO_DETAILED_RADIOSTATE_ENABLED) { + this.dispatchFireRequestError(requestId, + RIL.GECKO_ERROR_RADIO_NOT_AVAILABLE); + return request; + } + cpmm.sendAsyncMessage("RIL:GetPreferredNetworkType", { clientId: clientId, data: { diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index 604e7ed6840d..54a34425351e 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -2456,10 +2456,6 @@ RadioInterface.prototype = { getPreferredNetworkType: function(target, message) { this.workerMessenger.send("getPreferredNetworkType", message, (function(response) { - if (response.success) { - response.type = RIL.RIL_PREFERRED_NETWORK_TYPE_TO_GECKO[response.networkType]; - } - target.sendAsyncMessage("RIL:GetPreferredNetworkType", { clientId: this.clientId, data: response @@ -2469,17 +2465,6 @@ RadioInterface.prototype = { }, setPreferredNetworkType: function(target, message) { - let networkType = RIL.RIL_PREFERRED_NETWORK_TYPE_TO_GECKO.indexOf(message.type); - if (networkType < 0) { - message.errorMsg = RIL.GECKO_ERROR_INVALID_PARAMETER; - target.sendAsyncMessage("RIL:SetPreferredNetworkType", { - clientId: this.clientId, - data: message - }); - return false; - } - message.networkType = networkType; - this.workerMessenger.send("setPreferredNetworkType", message, (function(response) { target.sendAsyncMessage("RIL:SetPreferredNetworkType", { clientId: this.clientId, diff --git a/dom/system/gonk/ril_worker.js b/dom/system/gonk/ril_worker.js index cb38d309879d..e73886595a96 100644 --- a/dom/system/gonk/ril_worker.js +++ b/dom/system/gonk/ril_worker.js @@ -253,12 +253,6 @@ RilObject.prototype = { */ _pendingSentSmsMap: null, - /** - * Index of the RIL_PREFERRED_NETWORK_TYPE_TO_GECKO. Its value should be - * preserved over rild reset. - */ - preferredNetworkType: null, - /** * Marker object. */ @@ -1153,23 +1147,21 @@ RilObject.prototype = { /** * Set the preferred network type. * - * @param options An object contains a valid index of - * RIL_PREFERRED_NETWORK_TYPE_TO_GECKO as its `networkType` - * attribute, or undefined to set current preferred network - * type. + * @param options An object contains a valid value of + * RIL_PREFERRED_NETWORK_TYPE_TO_GECKO as its `type` attribute. */ setPreferredNetworkType: function(options) { - if (options) { - this.preferredNetworkType = options.networkType; - } - if (this.preferredNetworkType == null) { + let networkType = RIL_PREFERRED_NETWORK_TYPE_TO_GECKO.indexOf(options.type); + if (networkType < 0) { + options.errorMsg = GECKO_ERROR_INVALID_PARAMETER; + this.sendChromeMessage(options); return; } let Buf = this.context.Buf; Buf.newParcel(REQUEST_SET_PREFERRED_NETWORK_TYPE, options); Buf.writeInt32(1); - Buf.writeInt32(this.preferredNetworkType); + Buf.writeInt32(networkType); Buf.sendParcel(); }, @@ -6216,31 +6208,20 @@ RilObject.prototype[REQUEST_STK_SEND_TERMINAL_RESPONSE] = null; RilObject.prototype[REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM] = null; RilObject.prototype[REQUEST_EXPLICIT_CALL_TRANSFER] = null; RilObject.prototype[REQUEST_SET_PREFERRED_NETWORK_TYPE] = function REQUEST_SET_PREFERRED_NETWORK_TYPE(length, options) { - if (options.networkType == null) { - // The request was made by ril_worker itself automatically. Don't report. - return; - } - if (options.rilRequestError) { - options.success = false; options.errorMsg = RIL_ERROR_TO_GECKO_ERROR[options.rilRequestError]; - } else { - options.success = true; } this.sendChromeMessage(options); }; RilObject.prototype[REQUEST_GET_PREFERRED_NETWORK_TYPE] = function REQUEST_GET_PREFERRED_NETWORK_TYPE(length, options) { if (options.rilRequestError) { - options.success = false; options.errorMsg = RIL_ERROR_TO_GECKO_ERROR[options.rilRequestError]; this.sendChromeMessage(options); return; } - let results = this.context.Buf.readInt32List(); - options.networkType = this.preferredNetworkType = results[0]; - options.success = true; - + let networkType = this.context.Buf.readInt32List()[0]; + options.type = RIL_PREFERRED_NETWORK_TYPE_TO_GECKO[networkType]; this.sendChromeMessage(options); }; RilObject.prototype[REQUEST_GET_NEIGHBORING_CELL_IDS] = null; @@ -6479,7 +6460,6 @@ RilObject.prototype[UNSOLICITED_RESPONSE_RADIO_STATE_CHANGED] = function UNSOLIC } this.getBasebandVersion(); this.updateCellBroadcastConfig(); - this.setPreferredNetworkType(); if ((RILQUIRKS_DATA_REGISTRATION_ON_DEMAND || RILQUIRKS_SUBSCRIPTION_CONTROL) && this._attachDataRegistration) {