Updated connman and bluetooth settings to the new connman protocols in settings-daemon 76/13076/1
authorJimmy Huang <jimmy.huang@intel.com>
Wed, 27 Nov 2013 20:25:17 +0000 (12:25 -0800)
committerJimmy Huang <jimmy.huang@intel.com>
Wed, 27 Nov 2013 20:37:56 +0000 (12:37 -0800)
- Settings will now use the new settings daemon protocols for connman-related apis
- Connman settings supports thew new get_technologies and get_services requests

Change-Id: I0b12321080183695bb5259d1b7a615070ace46a5
Signed-off-by: Jimmy Huang <jimmy.huang@intel.com>
index.html
js/api-connman.js
js/panel-bluetooth.js
js/panel-connman.js
js/utils.js
js/websocket.js
packaging/Settings.changes

index f3cb7da..9783594 100644 (file)
             <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
                 <li data-role="fieldcontain">
                     <label for="select_timezone" class="select">Time zone:</label>
-                    <select name="select_timezone" id="select_timezone" data-native-menu="false">
+                    <select name="select_timezone" id="select_timezone">
                         <option value="Pacific/Midway">(GMT-11:00) Midway Island, Samoa</option>
                         <option value="America/Adak">(GMT-10:00) Hawaii-Aleutian</option>
                         <option value="Etc/GMT+10">(GMT-10:00) Hawaii</option>
index aef05be..e94e338 100644 (file)
@@ -32,7 +32,7 @@ settings.connman = (function() {
         var me = this;
         this.setPowerInProgress = true;
         setTimeout(function() {
-            wsAPI.sendRequest(me.prop.Type, 'enable', powered, function() {
+            wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN_TECHNOLOGY, 'enable', [me.id, powered], function() {
                 me.setPowerInProgress = false;
                 success_cb();
             }, function(e) {
@@ -79,53 +79,46 @@ settings.connman = (function() {
             'Type': this.prop.EncryptionMode,
             'Passphrase': passphrase
         }]
-        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'connect', info, success_cb, error_cb);
+        wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN_SERVICE, 'connect', info, success_cb, error_cb);
     };
 
     ConnmanService.prototype.disconnect = function(success_cb, error_cb) {
         if (wsAPI === undefined) return;
-        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'disconnect', this.id, success_cb, error_cb);
+        wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN_SERVICE, 'disconnect', [this.id, null], success_cb, error_cb);
     };
 
     function getTechnologies(success_cb, error_cb) {
-        wsAPI.sendRequest('connman', 'getTechnologies', null, function(results) {
-            success_cb(results);
-        }, function(error) {
-            console.log('getTechnologies not implemented in settingsd, using pre-defined values');
-            var results = [
-                ['/net/connman/technology/ethernet',
-                {
-                    'Name': 'Wired',
-                    'Type': 'ethernet',
-                }],
-                ['/net/connman/technology/wifi',
-                {
-                    'Name': 'WiFi',
-                    'Type': 'wifi',
-                }],
-                ['/net/connman/technology/bluetooth',
-                {
-                    'Name': 'Bluetooth',
-                    'Type': 'bluetooth',
-                }]
-            ];
-
-            var technologies = [];
-            for (var i = 0; i < results.length; i++) {
-                var technology = new settings.connman.ConnmanTechnology(results[i][0], results[i][1]);
-                technologies.push(technology);
+        if (wsAPI === undefined) return;
+        wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN_MANAGER, 'get_technologies', null, function(results) {
+            if (results.length >= 0 && results[0].length >= 0 && results[0][0][0] === undefined) {
+                error_cb('Cannot parse technologies');
+                return;
             }
 
+            var technologies_list = results[0];
+
+            try {
+                var technologies = [];
+                for (var i = 0; i < technologies_list.length; i++) {
+                    if (technologies_list[i][0] === undefined || technologies_list[i][1] === undefined) {
+                        console.log('Badly form json message: ' + json_msg);
+                    }
+
+                    var technology = new settings.connman.ConnmanTechnology(technologies_list[i][0], technologies_list[i][1]);
+                    technologies.push(technology);
+                }
+            } catch (e) {
+                error_cb(e);
+            }
             success_cb(technologies);
-        });
+        }, error_cb);
     }
 
     function getServices(success_cb, error_cb) {
-        return this.scan(success_cb, error_cb);
-
-        wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN, 'getServices', null, function(results) {
+        if (wsAPI === undefined) return;
+        wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN_MANAGER, 'get_services', null, function(results) {
             if (results.length >= 0 && results[0].length >= 0 && results[0][0][0] === undefined) {
-                error_cb('Cannot parse getServices results');
+                error_cb('Cannot parse get_services results');
                 return;
             }
 
@@ -148,9 +141,9 @@ settings.connman = (function() {
         }, error_cb);
     }
 
-    function scan(success_cb, error_cb) {
+    function scan(technology, success_cb, error_cb) {
         if (wsAPI === undefined) return;
-        wsAPI.sendRequest(WS_REQUEST_TYPE.WIFI, 'scan', null, function(results) {
+        wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN_TECHNOLOGY, 'scan', [technology, null], function(results) {
             if (results.length >= 0 && results[0].length >= 0 && results[0][0][0] === undefined) {
                 error_cb('Cannot parse scan results');
                 return;
@@ -159,19 +152,19 @@ settings.connman = (function() {
             var services_list = results[0];
 
             try {
-                var results = [];
+                var services = [];
                 for (var i = 0; i < services_list.length; i++) {
                     if (services_list[i][0] === undefined || services_list[i][1] === undefined) {
                         console.log('Badly form json message: ' + json_msg);
                     }
 
                     var service = new settings.connman.ConnmanService(services_list[i][0], services_list[i][1]);
-                    results.push(service);
+                    services.push(service);
                 }
             } catch (e) {
                 error_cb(e);
             }
-            success_cb(results);
+            success_cb(services);
         }, error_cb);
     };
 
index dfbfa6d..86e7f0f 100644 (file)
@@ -102,15 +102,18 @@ function bluetoothPanelInit() {
 }
 
 function bluetoothEventReceived(event) {
-    if (event.type !== WS_EVENT_TYPE.BLUETOOTH && event.type !== WS_EVENT_TYPE.CONNMAN) return;
-    if ($.mobile.activePage.attr('id') !== 'page_bluetooth' || $.mobile.activePage.attr('id') !== 'page_bluetooth_detail') {
-        return;
-    }
+    if (event.type === WS_EVENT_TYPE.BLUETOOTH || event.type === WS_EVENT_TYPE.CONNMAN) {
+        if ($.mobile.activePage.attr('id') !== 'page_bluetooth' || $.mobile.activePage.attr('id') !== 'page_bluetooth_detail') {
+            return;
+        }
 
-    if (event.id === '/net/connman/technology/bluetooth' && event.name === 'PropertyChanged') {
-        bluetoothHandlePropertyChanged(event.value);
-    } else {
-        console.log('Unsupported bluetooth event received: ' + event.name);
+        if (event.type === WS_EVENT_TYPE.CONNMAN && event.id === '/net/connman/technology/bluetooth' && event.name === 'PropertyChanged') {
+            bluetoothHandlePropertyChanged(event.value);
+        } else if (event.type === WS_EVENT_TYPE.SYNC) {
+
+        } else {
+            console.log('Unsupported bluetooth event received: ' + event.name);
+        }
     }
 }
 
index 384ccc0..3277b58 100644 (file)
@@ -40,12 +40,20 @@ function connmanPanelInit() {
                     connmanConstructTechnologyElement(technology);
                 }
             }
+        }, function(e) {
+            showMsg('Error', e);
         });
     });
 
     $('#button_connman_refresh').on('click', function() {
         /* connman only supports wifi scan */
-        connmanScan('wifi');
+        if ($('#toggle_connman_wifi').val() === 'on') {
+            connmanScan('/net/connman/technology/wifi');
+        } else {
+            connmanSync(null, function(e) {
+                showMsg('Error', e);
+            });
+        }
     });
 
     $('#button_connman_wifi_add').on('click', function() {
@@ -82,7 +90,7 @@ function connmanPanelInit() {
             return;
         }
 
-        if (security !== 'None' && passcode === '') {
+        if (security !== 'none' && passcode === '') {
             showMsg('Error', 'Enter passphrase');
             return;
         }
@@ -99,7 +107,9 @@ function connmanPanelInit() {
                     hideSpinner();
                     console.log('Go back to Connman page');
                     $.mobile.changePage('#page_connman');
-                }, null);
+                }, function(e) {
+                    showMsg('Error', e);
+                });
             }, function(e) {
                 /* error */
                 hideSpinner();
@@ -107,7 +117,7 @@ function connmanPanelInit() {
             });
         }, function(e) {
             hideSpinner();
-               showMsg('Error', e);
+            showMsg('Error', e);
         });
     });
 
@@ -140,17 +150,18 @@ function connmanPanelInit() {
 }
 
 function connmanEventReceived(event) {
-    if (event.type !== WS_EVENT_TYPE.CONNMAN) return;
-    if ($.mobile.activePage.attr('id') !== 'page_connman' && $.mobile.activePage.attr('id') !== 'page_connman_service') {
-        return;
-    }
+    if (event.type === WS_EVENT_TYPE.CONNMAN) {
+        if ($.mobile.activePage.attr('id') !== 'page_connman' && $.mobile.activePage.attr('id') !== 'page_connman_service') {
+            return;
+        }
 
-    if (event.name === 'ServicesChanged') {
-        connmanHandleServicesChanged(event.id, event.value);
-    } else if (event.name === 'PropertyChanged') {
-        connmanHandlePropertyChanged(event.id, event.value);
-    } else {
-        console.log('Unsupported event received: ' + event.name);
+        if (event.name === 'ServicesChanged') {
+            connmanHandleServicesChanged(event.id, event.value);
+        } else if (event.name === 'PropertyChanged') {
+            connmanHandlePropertyChanged(event.id, event.value);
+        } else {
+            console.log('Unsupported event received: ' + event.name);
+        }
     }
 }
 
@@ -201,7 +212,7 @@ function connmanHandlePropertyChanged(id, property) {
             if (technology === 'wifi') {
                 setTimeout(function() {
                     /* add a 1 sec delay */
-                    connmanScan(technology);
+                    connmanScan(id);
                 }, 1000);
             }
         } else {
@@ -222,7 +233,9 @@ function connmanHandlePropertyChanged(id, property) {
     } else if (property[0] === 'Connected') {
         /* unknown service has changed, sync Connman */
         console.log('Unknown service connected property changed');
-        connmanSync(null, null);
+        connmanSync(null, function(e) {
+            showMsg('Error', e);
+        });
     }
 }
 
@@ -231,7 +244,7 @@ function connmanClearAvailableList() {
 }
 
 function connmanScan(technology) {
-    if (technology !== 'wifi') {
+    if (technology !== '/net/connman/technology/wifi') {
         /* Connman only supports wifi scan */
         return;
     }
@@ -250,7 +263,7 @@ function connmanScan(technology) {
     showSpinner(false, 'Scanning...');
     $('#toggle_connman_wifi').slider('disable');
     $('#toggle_connman_wifi').slider('refresh');
-    settings.connman.scan(function(services) {
+    settings.connman.scan(technology, function(services) {
         hideSpinner();
         connmanScanInProgress = false;
         $('#toggle_connman_wifi').slider('enable');
@@ -382,7 +395,14 @@ function connmanConstructTechnologyElement(technology) {
     if (technology.prop.Powered) {
         connmanToggleOn(technology.prop.Type);
         if ($('ul#listview_services_available li').length === 0) {
-            connmanScan(technology.prop.Type);
+            /* connman only supports wifi scan */
+            if (technology.prop.Type === 'wifi') {
+                connmanScan(technology.id);
+            } else {
+                connmanSync(null, function(e) {
+                    showMsg('Error', e);
+                });
+            }
         }
     } else {
         connmanToggleOff(technology.prop.Type);
@@ -419,7 +439,7 @@ function connmanConstructTechnologyElement(technology) {
                 if (technology.prop.Type === 'wifi') {
                     setTimeout(function() {
                         /* add a 1 sec delay */
-                        connmanScan(technology.prop.Type);
+                        connmanScan(technology.id);
                     }, 1000);
                 }
                 console.log('Successfully enabled connman technology ' + technology.prop.Type);
@@ -498,7 +518,9 @@ function connmanConstructServiceElement(parent, service) {
                 /* success */
                 connmanSync(function() {
                     hideSpinner();
-                }, null)
+                }, function(e) {
+                    showMsg('Error', e);
+                })
             }, function(e) {
                 /* error */
                 hideSpinner();
index 9345063..38992a4 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 function jqId(id) {
-    if (id == undefined) return null;
+    if (!id) return null;
 
     /* replace colons and spaces with dash for jquery ids */
     return '#' + id.replace(/:| |\//g, '-');
index 901c1c2..01f19e6 100644 (file)
@@ -13,8 +13,9 @@ var dummyBackend = false;
 var ERROR_SETTINGSD_DISCONNECTED = 'Settings daemon is not connected';
 
 var WS_REQUEST_TYPE = {
-    CONNMAN: "connman::manager",
-    WIFI: "wifi",
+    CONNMAN_MANAGER: "connman::manager",
+    CONNMAN_TECHNOLOGY: "connman::technology",
+    CONNMAN_SERVICE: "connman::service",
     BLUETOOTH: "bluetooth",
     DISPLAY: "display",
     SOUND: "sound",
@@ -23,8 +24,7 @@ var WS_REQUEST_TYPE = {
 };
 
 var WS_EVENT_TYPE = {
-    CONNMAN: "connman::manager",
-    WIFI: "wifi",
+    CONNMAN: "connman",
     BLUETOOTH: "bluetooth",
     DISPLAY: "display",
     SOUND: "sound",
@@ -196,7 +196,7 @@ var wsAPI = (function() {
                 }
 
                 if (response.value.object_path === '/' || response.value.object_path.indexOf('/net/connman/technology/') >= 0) {
-                    fireEvent(WS_REQUEST_TYPE.CONNMAN, response.value.object_path, response.value.signal_name, response.value.parameters);
+                    fireEvent(WS_EVENT_TYPE.CONNMAN, response.value.object_path, response.value.signal_name, response.value.parameters);
                 } else {
                     console.error('Unrecognized event object_path, skipping');
                 }
index 7142887..0e25d0b 100644 (file)
@@ -1,3 +1,6 @@
+* Wed Nov 27 2013 Jimmy Huang <jimmy.huang@intel.com> ivi_oct_m2@d39bf75
+- Updated connman and bluetooth settings to the new connman protocols in settings-daemon
+
 * Fri Nov 15 2013 Jimmy Huang <jimmy.huang@intel.com> submit/tizen_ivi_milestone/20131113.054020@1cf567d
 - Refactor WiFi module