From a065e04d529da1d847b5062a12c46d916408bf32 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 21:46:22 -0500 Subject: update based on https://github.com/mdn/yari/issues/2028 --- files/id/web/api/mobile_connection_api/index.html | 149 ---------------------- 1 file changed, 149 deletions(-) delete mode 100644 files/id/web/api/mobile_connection_api/index.html (limited to 'files/id/web/api') diff --git a/files/id/web/api/mobile_connection_api/index.html b/files/id/web/api/mobile_connection_api/index.html deleted file mode 100644 index 7b5462e2ef..0000000000 --- a/files/id/web/api/mobile_connection_api/index.html +++ /dev/null @@ -1,149 +0,0 @@ ---- -title: Mobile Connection -slug: Web/API/Mobile_Connection_API -translation_of: Archive/B2G_OS/API/Mobile_Connection_API ---- -

{{ draft }}

-

{{ non-standard_header() }}

-

{{ B2GOnlyHeader2('certified') }}

-

Summary

-

This API has 2 purposes:

- -

As this API can access functionalities that can have an impact on the mobile plan subscribed by the user (some of the functionalities can cost money to use or can damage the ICC), it is restricted to certified applications only.

-

The main entry point for this API is the {{domxref("window.navigator.mozMobileConnection","navigator.mozMobileConnection")}} property which is an instance of the {{domxref("MozMobileConnection")}} interface.

-

State of mobile connection

-

The state of the mobile connection is divided in two: on the one hand the voice connection, on the other hand the data connection. The data related to each type of connection are accessible through the {{domxref("MozMobileConnection.voice")}} and {{domxref("MozMobileConnection.data")}} properties which both return a {{domxref("MozMobileConnectionInfo")}} object.

-

Those objects give access to all information related to the quality of the network (signal strength, quality of the signal, position of the network's cells, restricted usage, roaming, etc.), and related to the carrier operating the network.

-
var cnx = navigator.mozMobileConnection;
-
-console.log("The voice operator is " + cnx.voice.network.longName);
-
-if (cnx.voice.connected) {
-  console.log("The signal has a strength of " + (+cnx.voice.relSignalStrength) + "%");
-} else {
-  console.log("The state of the connection is: " + cnx.voice.state);
-}
-
-

ICC Functionalities

-

The functionalities available for the ICC can be divided into two categories: the management of the ICC itself and the use of the integrated command available within the STK (SIM Application Toolkit).

-

Basic actions

-

The {{domxref("MozMobileConnection")}} provides a set of methods to deal with common behaviors on ICCs.

-
-

Note: All original methods from the MozMobileConnection interface are fully asynchronous. They all return a {{domxref("DOMRequest")}} object which has an onsuccess and onerror event handler to handle the success or failure of the method call.

-
-

Card lock

-

As long as a card is locked, a user is unable to use it to reach its mobile network. It's possible to manage the card lock with the {{domxref("MozMobileConnection.getCardLock","getCardLock()")}}, {{domxref("MozMobileConnection.setCardLock","setCardLock()")}}, and {{domxref("MozMobileConnection.unlockCardLock","unlockCardLock()")}} methods.

-

If {{domxref("MozMobileConnection.getCardLock","getCardLock()")}} allows to get some detailed information about the lock, it's also possible to have quick info about the lock through {{domxref("MozMobileConnection.cardState")}} which returns a string representing the current state of the lock.

-
-

Note: Even if the state change requests are successfully handled, it does not mean that the operations are necessarily successful. For that reason, any change in the card state is tracked independently through events:

- -
-
var cnx = navigator.mozMobileConnection;
-
-function unlockCard() {
-  var unlockOptions = {
-    lockType: "pin",
-    pin     : prompt("Please, enter your PIN")
-  }
-
-  var unlock = cnx.unlockCardLock(unlockOptions);
-
-  unlock.onsuccess = function () {
-    console.log("The card has successfully handled the PIN number.");
-
-    if (this.result.success === false) {
-      if (this.result.retryCount > 0) {
-        console.log("But you mistyped your PIN, you have " + this.result.retryCount + " tries left.");
-      } else {
-        console.log("But your card is hard locked, you need to contact your carrier to get a special unlocking code.");
-      }
-    }
-  }
-
-  unlock.onerror = function () {
-    console.log("Hu! Something goes very wrong!")
-  }
-}
-
-cnx.addEventListener('icccardlockerror', function () {
-  // In case of error, ask the user for his PIN again
-  unlockCard();
-});
-
-cnx.addEventListener('cardsatechange', function () {
-  // In case the card state change and required to be unlocked
-  if (cnx.cardState === 'pinRequired') {
-    unlockCard();
-  }
-}
-
-// First call to unlockCard if required
-if (cnx.cardState === 'pinRequired') {
-  unlockCard();
-}
-
-

MMI Messages

-

MMI messages are human understandable code that, once typed with a phone keyboard, allow to trigger specific action from the RIL or get response from the network through a USSD request. A common example is typing a short code to get the IMEI phone number.

-

Such messages are sent using the {{domxref("MozMobileConnection.sendMMI()")}} method (and can be canceled with {{domxref("MozMobileConnection.cancelMMI","cancelMMI()")}}). Even if it will return a {{domxref("DOMRequest")}} object, the response to such messages are handled in two ways:

- -
var cnx = navigator.mozMobileConnection;
-
-cnx.addEventHandler('ussdreceived', function (evt) {
-  console.log('Network message: ' + evt.data.message);
-});
-
-var MMIRequest = cnx.sendMMI(prompt('Provide a valid MMI'));
-
-MMIRequest.onerror = function() {
-  console.log("Mmmh... Something goes wrong.");
-}
-
-

Call forwarding options

-

Call forwarding options allow to define how a call can or cannot be forwarded to another phone number.

-

Those options are handled with the {{domxref("MozMobileConnection.getCallForwardingOption","getCallForwardingOption()")}} and {{domxref("MozMobileConnection.setCallForwardingOption","setCallForwardingOption()")}} methods.

-
var options = {
-  action      : MozMobileCFInfo.CALL_FORWARD_ACTION_ENABLE,
-  reason      : MozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL,
-  serviceClass: MozMobileConnectionInfo.ICC_SERVICE_CLASS_VOICE,
-  number      : prompt('To which phone number would you wish to forward the calls?'),
-  timeSeconds : 5
-};
-
-var setOption = navigator.mozMobileConnection.setCallForwardingOption(options);
-
-setOption.onsuccess = function () {
-  console.log('Options successfully set');
-}
-
-setOption.onerror = function () {
-  console.log('Unable to set options: ' + this.error.name);
-}
-
-

STK commands

-

The STK commands depend on many factors (carriers, chips model, etc.) but can always be accessed through the {{domxref("MozMobileConnection.icc")}} property which returns a {{domxref("MozIccManager")}} object.

-
-

Warning: It's recommended to use the STK command only if you already know exactly what you are doing, as a misusage can damage the chip and make it unusable.

-
-

Specification

-

Not part of any specification.

-

See also

- -- cgit v1.2.3-54-g00ecf