Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

This API is available on Firefox OS for internal applications only.

This API is used to get information about the current mobile voice and data connection states of the device. It is accessible through navigator.mozMobileConnections, which returns an array of MozMobileConnection objects.

Note: The syntax used to be window.navigator.mozMobileConnection, returning a single MozMobileConnection object, but this was updated in Firefox 1.3 due to the introduction of Multi-SIM support (Dual-SIM-Dual-Standby or DSDS).

Interface overview

callback EventHandler = any (Event event);

interface MozMobileConnection : EventTarget
{
  const long ICC_SERVICE_CLASS_VOICE = (1 << 0);
  const long ICC_SERVICE_CLASS_DATA = (1 << 1);
  const long ICC_SERVICE_CLASS_FAX = (1 << 2);
  const long ICC_SERVICE_CLASS_SMS = (1 << 3);
  const long ICC_SERVICE_CLASS_DATA_SYNC = (1 << 4);
  const long ICC_SERVICE_CLASS_DATA_ASYNC = (1 << 5);
  const long ICC_SERVICE_CLASS_PACKET = (1 << 6);
  const long ICC_SERVICE_CLASS_PAD = (1 << 7);
  const long ICC_SERVICE_CLASS_MAX = (1 << 7);

  readonly attribute MozMobileConnectionInfo voice;
  readonly attribute MozMobileConnectionInfo data;
  readonly attribute DOMString networkSelectionMode;
  readonly attribute DOMString iccId;

  DOMRequest getNetworks();
  DOMRequest selectNetwork(MozMobileNetworkInfo network);
  DOMRequest selectNetworkAutomatically();
  DOMRequest sendMMI(DOMString mmi);
  DOMRequest cancelMMI();
  DOMRequest setCallForwardingOption(MozMobileCFInfo CFInfo);
  DOMRequest getCallForwardingOption(unsigned short reason);

  attribute EventHandler onvoicechange;
  attribute EventHandler ondatachange;
  attribute EventHandler onussdreceived;
  attribute EventHandler ondataerror;
  attribute EventHandler oncfstatechange;
};

Properties

 
MozMobileConnection.voice Read only
A MozMobileConnectionInfo object that gives access to information about the voice connection.
MozMobileConnection.data Read only
A MozMobileConnectionInfo object that gives access to information about the data connection.
MozMobileConnection.iccId Read only
A string that indicates the Integrated Circuit Card Identifier of the SIM this mobile connection corresponds to.
MozMobileConnection.networkSelectionMode Read only
A string that indicates the selection mode of the voice and data networks.
MozMobileConnection.oncfstatechange
A handler for the cfstatechange event. This event is fired when the call forwarding state changes.
MozMobileConnection.ondatachange
A handler for the datachange event. This event is fired whenever the data connection object changes values.
MozMobileConnection.ondataerror
A handler for the dataerror event. This event is fired whenever the data connection object receive an error from the RIL.
MozMobileConnection.onussdreceived
A handler for the ussdreceived event. This event is fired whenever a new USSD message is received.
MozMobileConnection.onvoicechange
A handler for the voicechange event. This event is fired whenever the voice connection object changes.

Constants

  • ICC_SERVICE_CLASS_VOICE
  • ICC_SERVICE_CLASS_DATA
  • ICC_SERVICE_CLASS_FAX
  • ICC_SERVICE_CLASS_SMS
  • ICC_SERVICE_CLASS_DATA_SYNC
  • ICC_SERVICE_CLASS_DATA_ASYNC
  • ICC_SERVICE_CLASS_PACKET
  • ICC_SERVICE_CLASS_PAD
  • ICC_SERVICE_CLASS_MAX

Methods

Note: All original methods from the MozMobileConnection interface are fully asynchronous. They all return a DOMRequest which has a onsuccess and onerror event handler to handle the success or failur of the method call.

MozMobileConnection.cancelMMI()
Cancel the current MMI request if one exists.
MozMobileConnection.getCallForwardingOption()
Queries current call forward options.
MozMobileConnection.getNetworks()
Search for available networks.
MozMobileConnection.selectNetwork()
Manually selects a network, overriding the radio's current selection.
MozMobileConnection.selectNetworkAutomatically()
Tell the radio to automatically select a network.
MozMobileConnection.sendMMI()
Send a MMI message.
MozMobileConnection.setCallForwardingOption()
Configures call forward options.

The MozMobileConnection interface also inherit from the EventTarget interface

EventTarget.addEventListener()
Register an event handler of a specific event type on the EventTarget.
EventTarget.removeEventListener()
Removes an event listener from the EventTarget.
EventTarget.dispatchEvent()
Dispatch an event to this EventTarget.

Additional methods for Mozilla chrome code

Mozilla extensions for use by JS-implemented event targets to implement on* properties. See also WebIDL bindings.

  • void setEventHandler(DOMString type, EventHandler handler)
  • EventHandler getEventHandler(DOMString type)

Examples

The following snippet returns an array of strings that correspond to MCCs, which can be mapped back to countries or even continents based on the first digit (see Mobile country code for a useful reference.) This is useful for redirection logic.

var mcc_mnc = (function () {
 function f (c) { return !!c.lastKnownHomeNetwork && !!c.lastKnownNetwork; };
 function m (c) {
   var s = (c.lastKnownHomeNetwork || c.lastKnownNetwork).split("-");
   return { mcc: s[0], mnc: s[1], };
 };
 return function () {
   if ("mozMobileConnections" in navigator) {
     return Array.prototype.filter.call(navigator.mozMobileConnections, f).map(m);
   } else if ("mozMobileConnection" in navigator) {
     return [navigator.mozMobileConnection].filter(f).map(m);
   } else {
     return [];
   }
 };
})();

Specification

Not part of any specification

See also

Document Tags and Contributors

 Last updated by: chrisdavidmills,