Bug 1167132 - Part 4: [NetworkManager] Move network information into a separate interface (DataCall). r=echen

This commit is contained in:
Jessica Jong 2015-07-29 02:04:00 -04:00
Родитель 637babbd6a
Коммит faef349af0
1 изменённых файлов: 114 добавлений и 77 удалений

Просмотреть файл

@ -53,7 +53,9 @@ const DATACALLMANAGER_CID =
const DATACALLHANDLER_CID =
Components.ID("{132b650f-c4d8-4731-96c5-83785cb31dee}");
const RILNETWORKINTERFACE_CID =
Components.ID("{8c11bef9-9b4f-4d96-bed7-f5a1f48eabda}");
Components.ID("{9574ee84-5d0d-4814-b9e6-8b279e03dcf4}");
const RILNETWORKINFO_CID =
Components.ID("{dd6cf2f0-f0e3-449f-a69e-7c34fdcb8d4b}");
const TOPIC_XPCOM_SHUTDOWN = "xpcom-shutdown";
const TOPIC_MOZSETTINGS_CHANGED = "mozsettings-changed";
@ -61,20 +63,20 @@ const TOPIC_PREF_CHANGED = "nsPref:changed";
const TOPIC_DATA_CALL_ERROR = "data-call-error";
const PREF_RIL_DEBUG_ENABLED = "ril.debugging.enabled";
const NETWORK_TYPE_UNKNOWN = Ci.nsINetworkInterface.NETWORK_TYPE_UNKNOWN;
const NETWORK_TYPE_WIFI = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
const NETWORK_TYPE_MOBILE = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE;
const NETWORK_TYPE_MOBILE_MMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS;
const NETWORK_TYPE_MOBILE_SUPL = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL;
const NETWORK_TYPE_MOBILE_IMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_IMS;
const NETWORK_TYPE_MOBILE_DUN = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_DUN;
const NETWORK_TYPE_MOBILE_FOTA = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_FOTA;
const NETWORK_TYPE_UNKNOWN = Ci.nsINetworkInfo.NETWORK_TYPE_UNKNOWN;
const NETWORK_TYPE_WIFI = Ci.nsINetworkInfo.NETWORK_TYPE_WIFI;
const NETWORK_TYPE_MOBILE = Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE;
const NETWORK_TYPE_MOBILE_MMS = Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_MMS;
const NETWORK_TYPE_MOBILE_SUPL = Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_SUPL;
const NETWORK_TYPE_MOBILE_IMS = Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_IMS;
const NETWORK_TYPE_MOBILE_DUN = Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_DUN;
const NETWORK_TYPE_MOBILE_FOTA = Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_FOTA;
const NETWORK_STATE_UNKNOWN = Ci.nsINetworkInterface.NETWORK_STATE_UNKNOWN;
const NETWORK_STATE_CONNECTING = Ci.nsINetworkInterface.NETWORK_STATE_CONNECTING;
const NETWORK_STATE_CONNECTED = Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
const NETWORK_STATE_DISCONNECTING = Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTING;
const NETWORK_STATE_DISCONNECTED = Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED;
const NETWORK_STATE_UNKNOWN = Ci.nsINetworkInfo.NETWORK_STATE_UNKNOWN;
const NETWORK_STATE_CONNECTING = Ci.nsINetworkInfo.NETWORK_STATE_CONNECTING;
const NETWORK_STATE_CONNECTED = Ci.nsINetworkInfo.NETWORK_STATE_CONNECTED;
const NETWORK_STATE_DISCONNECTING = Ci.nsINetworkInfo.NETWORK_STATE_DISCONNECTING;
const NETWORK_STATE_DISCONNECTED = Ci.nsINetworkInfo.NETWORK_STATE_DISCONNECTED;
const INT32_MAX = 2147483647;
@ -415,7 +417,7 @@ DataCallHandler.prototype = {
this._dataCalls = [];
this.clientId = null;
this.dataCallinterface.unregisterListener(this);
this.dataCallInterface.unregisterListener(this);
this.dataCallInterface = null;
let mobileConnection =
@ -625,8 +627,8 @@ DataCallHandler.prototype = {
return;
}
let wifi_active = false;
if (gNetworkManager.active &&
gNetworkManager.active.type == NETWORK_TYPE_WIFI) {
if (gNetworkManager.activeNetworkInfo &&
gNetworkManager.activeNetworkInfo.type == NETWORK_TYPE_WIFI) {
wifi_active = true;
}
@ -709,7 +711,7 @@ DataCallHandler.prototype = {
if (!networkInterface) {
return NETWORK_STATE_UNKNOWN;
}
return networkInterface.state;
return networkInterface.info.state;
},
setupDataCallByType: function(aNetworkType) {
@ -760,8 +762,8 @@ DataCallHandler.prototype = {
let dataDisconnecting = false;
this.dataNetworkInterfaces.forEach(function(networkInterface) {
if (networkInterface.enabled) {
if (networkInterface.state != NETWORK_STATE_UNKNOWN &&
networkInterface.state != NETWORK_STATE_DISCONNECTED) {
if (networkInterface.info.state != NETWORK_STATE_UNKNOWN &&
networkInterface.info.state != NETWORK_STATE_DISCONNECTED) {
dataDisconnecting = true;
}
networkInterface.disconnect();
@ -1242,7 +1244,7 @@ DataCall.prototype = {
inRequestedTypes: function(aType) {
for (let i = 0; i < this.requestedNetworkIfaces.length; i++) {
if (this.requestedNetworkIfaces[i].type == aType) {
if (this.requestedNetworkIfaces[i].info.type == aType) {
return true;
}
}
@ -1279,7 +1281,7 @@ DataCall.prototype = {
},
connect: function(aNetworkInterface) {
if (DEBUG) this.debug("connect: " + aNetworkInterface.type);
if (DEBUG) this.debug("connect: " + aNetworkInterface.info.type);
if (this.requestedNetworkIfaces.indexOf(aNetworkInterface) == -1) {
this.requestedNetworkIfaces.push(aNetworkInterface);
@ -1295,7 +1297,7 @@ DataCall.prototype = {
Services.tm.currentThread.dispatch(() => {
// Do not notify if state changed while this event was being dispatched,
// the state probably was notified already or need not to be notified.
if (aNetworkInterface.state == RIL.GECKO_NETWORK_STATE_CONNECTED) {
if (aNetworkInterface.info.state == RIL.GECKO_NETWORK_STATE_CONNECTED) {
aNetworkInterface.notifyRILNetworkInterface();
}
}, Ci.nsIEventTarget.DISPATCH_NORMAL);
@ -1405,7 +1407,7 @@ DataCall.prototype = {
},
disconnect: function(aNetworkInterface) {
if (DEBUG) this.debug("disconnect: " + aNetworkInterface.type);
if (DEBUG) this.debug("disconnect: " + aNetworkInterface.info.type);
let index = this.requestedNetworkIfaces.indexOf(aNetworkInterface);
if (index != -1) {
@ -1426,7 +1428,7 @@ DataCall.prototype = {
Services.tm.currentThread.dispatch(() => {
// Do not notify if state changed while this event was being dispatched,
// the state probably was notified already or need not to be notified.
if (aNetworkInterface.state == RIL.GECKO_NETWORK_STATE_DISCONNECTED) {
if (aNetworkInterface.info.state == RIL.GECKO_NETWORK_STATE_DISCONNECTED) {
aNetworkInterface.notifyRILNetworkInterface();
// Clear link info after notifying NetworkManager.
@ -1449,7 +1451,7 @@ DataCall.prototype = {
},
deactivate: function() {
let reason = Ci.nsINetworkInterface.DATACALL_DEACTIVATE_NO_REASON;
let reason = Ci.nsIDataCallInterface.DATACALL_DEACTIVATE_NO_REASON;
if (DEBUG) {
this.debug("Going to disconnect data connection cid " + this.linkInfo.cid);
}
@ -1481,61 +1483,56 @@ DataCall.prototype = {
}
};
function RILNetworkInterface(aDataCallHandler, aType, aApnSetting, aDataCall) {
if (!aDataCall) {
throw new Error("No dataCall for RILNetworkInterface: " + type);
}
this.dataCallHandler = aDataCallHandler;
function RILNetworkInfo(aClientId, aType, aNetworkInterface)
{
this.serviceId = aClientId;
this.type = aType;
this.apnSetting = aApnSetting;
this.dataCall = aDataCall;
this.enabled = false;
this.networkInterface = aNetworkInterface;
}
RILNetworkInfo.prototype = {
classID: RILNETWORKINFO_CID,
classInfo: XPCOMUtils.generateCI({classID: RILNETWORKINFO_CID,
classDescription: "RILNetworkInfo",
interfaces: [Ci.nsINetworkInfo,
Ci.nsIRilNetworkInfo]}),
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInfo,
Ci.nsIRilNetworkInfo]),
RILNetworkInterface.prototype = {
classID: RILNETWORKINTERFACE_CID,
classInfo: XPCOMUtils.generateCI({classID: RILNETWORKINTERFACE_CID,
classDescription: "RILNetworkInterface",
interfaces: [Ci.nsINetworkInterface,
Ci.nsIRilNetworkInterface]}),
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface,
Ci.nsIRilNetworkInterface]),
networkInterface: null,
// Hold reference to DataCall object which is determined at initilization.
dataCall: null,
getDataCall: function() {
return this.networkInterface.dataCall;
},
// If this RILNetworkInterface type is enabled or not.
enabled: null,
getApnSetting: function() {
return this.networkInterface.apnSetting;
},
debug: function(aMsg) {
dump("-*- RILNetworkInfo[" + this.serviceId + ":" + this.type + "]: " +
aMsg + "\n");
},
/**
* nsINetworkInterface Implementation
* nsINetworkInfo Implementation
*/
get state() {
if (!this.dataCall.inRequestedTypes(this.type)) {
let dataCall = this.getDataCall();
if (!dataCall.inRequestedTypes(this.type)) {
return NETWORK_STATE_DISCONNECTED;
}
return this.dataCall.state;
return dataCall.state;
},
type: null,
get name() {
return this.dataCall.linkInfo.ifname;
},
get httpProxyHost() {
return this.apnSetting.proxy || "";
},
get httpProxyPort() {
return this.apnSetting.port || "";
return this.getDataCall().linkInfo.ifname;
},
getAddresses: function(aIps, aPrefixLengths) {
let addresses = this.dataCall.linkInfo.addresses;
let addresses = this.getDataCall().linkInfo.addresses;
let ips = [];
let prefixLengths = [];
@ -1552,33 +1549,33 @@ RILNetworkInterface.prototype = {
},
getGateways: function(aCount) {
let linkInfo = this.dataCall.linkInfo;
let linkInfo = this.getDataCall().linkInfo;
if (aCount) {
aCount.value = linkInfo.gateways.length;
}
return linkInfo.gateways.slice();
},
getDnses: function(aCount) {
let linkInfo = this.dataCall.linkInfo;
let linkInfo = this.getDataCall().linkInfo;
if (aCount) {
aCount.value = linkInfo.dnses.length;
}
return linkInfo.dnses.slice();
},
/**
* nsIRilNetworkInterface Implementation
* nsIRilNetworkInfo Implementation
*/
get serviceId() {
return this.dataCallHandler.clientId;
},
serviceId: 0,
get iccId() {
let icc = gIccService.getIccByServiceId(this.dataCallHandler.clientId);
let icc = gIccService.getIccByServiceId(this.serviceId);
let iccInfo = icc && icc.iccInfo;
return iccInfo && iccInfo.iccid;
@ -1590,7 +1587,7 @@ RILNetworkInterface.prototype = {
throw Cr.NS_ERROR_UNEXPECTED;
}
return this.apnSetting.mmsc || "";
return this.getApnSetting().mmsc || "";
},
get mmsProxy() {
@ -1599,7 +1596,7 @@ RILNetworkInterface.prototype = {
throw Cr.NS_ERROR_UNEXPECTED;
}
return this.apnSetting.mmsproxy || "";
return this.getApnSetting().mmsproxy || "";
},
get mmsPort() {
@ -1610,26 +1607,66 @@ RILNetworkInterface.prototype = {
// Note: Port 0 is reserved, so we treat it as invalid as well.
// See http://www.iana.org/assignments/port-numbers
return this.apnSetting.mmsport || -1;
return this.getApnSetting().mmsport || -1;
},
};
function RILNetworkInterface(aDataCallHandler, aType, aApnSetting, aDataCall) {
if (!aDataCall) {
throw new Error("No dataCall for RILNetworkInterface: " + type);
}
this.dataCallHandler = aDataCallHandler;
this.enabled = false;
this.dataCall = aDataCall;
this.apnSetting = aApnSetting;
this.info = new RILNetworkInfo(aDataCallHandler.clientId, aType, this);
}
RILNetworkInterface.prototype = {
classID: RILNETWORKINTERFACE_CID,
classInfo: XPCOMUtils.generateCI({classID: RILNETWORKINTERFACE_CID,
classDescription: "RILNetworkInterface",
interfaces: [Ci.nsINetworkInterface]}),
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface]),
// If this RILNetworkInterface type is enabled or not.
enabled: null,
apnSetting: null,
dataCall: null,
/**
* nsINetworkInterface Implementation
*/
info: null,
get httpProxyHost() {
return this.apnSetting.proxy || "";
},
get httpProxyPort() {
return this.apnSetting.port || "";
},
// Helpers
debug: function(aMsg) {
dump("-*- RILNetworkInterface[" + this.dataCallHandler.clientId + ":" +
this.type + "]: " + aMsg + "\n");
this.info.type + "]: " + aMsg + "\n");
},
apnSetting: null,
get connected() {
return this.state == NETWORK_STATE_CONNECTED;
return this.info.state == NETWORK_STATE_CONNECTED;
},
notifyRILNetworkInterface: function() {
if (DEBUG) {
this.debug("notifyRILNetworkInterface type: " + this.type + ", state: " +
this.state);
this.debug("notifyRILNetworkInterface type: " + this.info.type +
", state: " + this.info.state);
}
gNetworkManager.updateNetworkInterface(this);