Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/apps/system/js/icc_cache.js
diff options
context:
space:
mode:
authorDaniel Narvaez <dwnarvaez@gmail.com>2013-02-06 13:49:14 (GMT)
committer Daniel Narvaez <dwnarvaez@gmail.com>2013-02-06 13:49:14 (GMT)
commit821413607a0718156f9d25d895e89b1c3d37aa8b (patch)
tree01c285af734ed5bba64b73b489e1e0226a94a262 /apps/system/js/icc_cache.js
parentc110fb485b3af0066c6df7aeac8c055e9d767efa (diff)
Copy various bits from gaia
Diffstat (limited to 'apps/system/js/icc_cache.js')
-rw-r--r--apps/system/js/icc_cache.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/apps/system/js/icc_cache.js b/apps/system/js/icc_cache.js
new file mode 100644
index 0000000..1f1d0df
--- /dev/null
+++ b/apps/system/js/icc_cache.js
@@ -0,0 +1,86 @@
+/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
+
+'use strict';
+
+(function() {
+ /**
+ * Constants
+ */
+ var DEBUG = false;
+
+ /**
+ * Debug method
+ */
+ function debug(msg, optObject) {
+ if (DEBUG) {
+ var output = '[DEBUG] STKCACHE: ' + msg;
+ if (optObject) {
+ output += JSON.stringify(optObject);
+ }
+ console.log(output);
+ }
+ }
+
+ if (!window.navigator.mozMobileConnection) {
+ return;
+ }
+
+ var icc = window.navigator.mozMobileConnection.icc;
+ // Remove previous menu
+ var resetApplications = window.navigator.mozSettings.createLock().set({
+ 'icc.applications': '{}'
+ });
+ resetApplications.onsuccess = function icc_resetApplications() {
+ debug('STK Cache Reseted');
+ // Register to receive STK commands
+ window.navigator.mozSetMessageHandler('icc-stkcommand',
+ function handleSTKCommand(command) {
+ debug('STK Proactive Command:', command);
+ if (command.typeOfCommand == icc.STK_CMD_SET_UP_MENU) {
+ debug('STK_CMD_SET_UP_MENU:', command.options);
+ var reqApplications = window.navigator.mozSettings.createLock().set({
+ 'icc.applications': JSON.stringify(command.options)
+ });
+ reqApplications.onsuccess = function icc_getApplications() {
+ debug('Cached');
+ icc.sendStkResponse(command, {
+ resultCode: icc.STK_RESULT_OK
+ });
+ }
+ } else {
+ // Unsolicited command? -> Open settings
+ debug('CMD: ', command);
+ var application = document.location.protocol + '//' +
+ document.location.host.replace('system', 'settings');
+ debug('application: ', application);
+ var reqIccData = window.navigator.mozSettings.createLock().set({
+ 'icc.data': JSON.stringify(command)
+ });
+ reqIccData.onsuccess = function icc_getIccData() {
+ if (WindowManager.getRunningApps()[application]) {
+ debug('Settings is running. Ignoring');
+ return; // If settings is opened, we don't manage it
+ }
+
+ debug('Locating settings . . .');
+ navigator.mozApps.mgmt.getAll().onsuccess = function gotApps(evt) {
+ var apps = evt.target.result;
+ apps.forEach(function appIterator(app) {
+ if (app.origin != application)
+ return;
+
+ var reqIccData = window.navigator.mozSettings.createLock().set({
+ 'icc.data': JSON.stringify(command)
+ });
+ reqIccData.onsuccess = function icc_getIccData() {
+ debug('Launching ', app.origin);
+ app.launch();
+ }
+ }, this);
+ }
+ }
+ }
+ });
+ }
+})();