Implements TIVI-2083, adds tethering support 44/16244/2
authorJimmy Huang <jimmy.huang@intel.com>
Tue, 11 Feb 2014 23:13:14 +0000 (15:13 -0800)
committerJimmy Huang <jimmy.huang@intel.com>
Tue, 11 Feb 2014 23:34:54 +0000 (15:34 -0800)
Added tethering support exposed through settings daemon and connman.

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

index ede664f..8875445 100644 (file)
                     </li>
                 </ul>
             </div>
+            <div id="connman_tethering">
+                <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
+                    <li data-role="fieldcontain">
+                        <a href="#page_connman_tethering">Tethering</a>
+                    </li>
+                </ul>
+            </div>
             <div id="connman_services">
                 <div>
                     <p>Available Services</p>
         </div>
     </div>
 
+    <!-- Connman Tethering -->
+    <div data-role="page" id="page_connman_tethering">
+        <div data-role="header" data-position="fixed">
+            <a href="#page_connman" data-icon="back">Back</a>
+            <h1>Tethering</h1>
+        </div>
+
+        <div data-role="content">
+            <div id="connman_tethering_technologies"></div>
+
+            <label for="input_wifi_tethering_id">Tethering Identifier:</label>
+            <input type="text" name="name" id="input_wifi_tethering_id" value="" />
+
+            <label for="input_wifi_tethering_passphrase">Tethering Passphrase:</label>
+            <input type="password" name="name" id="input_wifi_tethering_passphrase" value="" />
+        </div>
+    </div>
+
     <!-- Connman Service Info -->
     <div data-role="page" id="page_connman_service">
         <div data-role="header" data-position="fixed">
index 8236d2a..e647b65 100644 (file)
@@ -64,6 +64,42 @@ settings.connman = (function() {
         }, error_cb);
     };
 
+    ConnmanTechnology.prototype.setTethering = function(tethered, identifier, passphrase, success_cb, error_cb) {
+        if (wsAPI === undefined) return;
+        if (this.setTetheringInProgress) {
+            console.log('Activating/Deactiviating tethering in progress');
+            return;
+        }
+
+        var me = this;
+        this.setTetheringInProgress = true;
+
+        var tethering_options = {
+            'path': me.id,
+            'ssid': identifier,
+            'password': passphrase,
+            'enabled': tethered
+        };
+
+        wsAPI.sendRequest(WS_REQUEST_TYPE.CONNMAN_TECHNOLOGY, 'tethering', tethering_options, function() {
+            me.setTetheringInProgress = false;
+            success_cb();
+        }, function(e) {
+            if (e.indexOf('Already enabled') >= 0) {
+                console.log('tethering ' + me.prop.Type + ' already enabled');
+                me.setTetheringInProgress = false;
+                success_cb();
+            } else if (e.indexOf('Already disabled') >= 0) {
+                console.log('tethering ' + me.prop.Type + ' already disabled');
+                me.setTetheringInProgress = false;
+                success_cb();
+            } else {
+                me.setTetheringInProgress = false;
+                error_cb(e);
+            }
+        })
+    };
+
     /* Service class */
     ConnmanService = function(service_path, service_properties) {
         this.id = service_path;
index 76f840c..8d1ac8b 100644 (file)
@@ -63,6 +63,11 @@ function connmanPanelInit() {
         $.mobile.changePage('#page_wifi_add');
     });
 
+    /* Connman tethering page */
+    $('#page_connman_tethering').on('pageshow', function(event, data) {
+        connmanTetheringPageReload();
+    });
+
     /* Connman service detail page */
     $('#page_connman_service').on('pageshow', function(event, data) {
         var service_id = localStorage.getItem('connman_service_id');
@@ -530,6 +535,109 @@ function connmanConstructServiceElement(parent, service) {
     });
 }
 
+function connmanTetheringPageReload() {
+    $('#connman_tethering_technologies').html('');
+    settings.connman.getTechnologies(function(technologies) {
+        for (var i = 0; i < technologies.length; i++) {
+            var technology = technologies[i];
+            console.log('Connman technology available for tethering: ' + technology.prop.Name);
+            connmanConstructTetheringElement(technology);
+        }
+    }, function(e) {
+        showMsg('Error', e);
+    });
+}
+
+function connmanConstructTetheringElement(technology) {
+    if (technology.prop.Type === undefined || technology.prop.Name == undefined) {
+        console.error('technology type or name missing ' + technology);
+        return;
+    }
+
+    var html = '<ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">';
+    html += '<li data-role="fieldcontain">';
+    html += '<label for="toggle_tethering_' + technology.prop.Type + '" class="ui-slider">Tether ' + technology.prop.Name + '</label>';
+    html += '<select data-role="slider" name="toggle_tethering_' + technology.prop.Type + '" ';
+    html += 'id="toggle_tethering_' + technology.prop.Type + '" class="ui-slider-switch">';
+    html += '<option value="off">Off</option>';
+    html += '<option value="on">On</option>';
+    html += '</select></li></ul>';
+    $('#connman_tethering_technologies').append(html).trigger('create');
+
+    console.log('Connman technology ' + technology.prop.Type + ' is tethered: ' + technology.prop.Tethering);
+
+    if (technology.prop.Powered === true && technology.prop.Connected === true) {
+        if (technology.prop.Tethering === true) {
+            $('#toggle_tethering_' + technology.prop.Type).val('on').slider('refresh');
+            $('#input_wifi_tethering_id').textinput('disable');
+            $('#input_wifi_tethering_passphrase').textinput('disable');
+            /* WiFi-only options */
+            if (technology.prop.Type === 'wifi') {
+                $('#connman_wifi_tethering_options').show();
+                if (technology.prop.TetheringIdentifier) {
+                    $('#input_wifi_tethering_id').val(technology.prop.TetheringIdentifier);
+                }
+                if (technology.prop.TetheringPassphrase) {
+                    $('#input_wifi_tethering_passphrase').val(technology.prop.TetheringPassphrase);
+                }
+            }
+        } else {
+            $('#toggle_tethering_' + technology.prop.Type).val('off').slider('refresh');
+        }
+    } else {
+        if (technology.prop.Type === 'wifi') {
+            $('#input_wifi_tethering_id').textinput('disable');
+            $('#input_wifi_tethering_passphrase').textinput('disable');
+        }
+        $('#toggle_tethering_' + technology.prop.Type).slider('disable');
+        $('#toggle_tethering_' + technology.prop.Type).slider('refresh');
+    }
+
+    $('#toggle_tethering_' + technology.prop.Type).change(function() {
+        if ($('#toggle_tethering_' + technology.prop.Type).val() === 'on') {
+            if (technology.prop.Type === 'wifi') {
+                var tethering_id = $('#input_wifi_tethering_id').val();
+                var tethering_passphrase = $('#input_wifi_tethering_passphrase').val();
+                if (tethering_id === '' || tethering_passphrase === '') {
+                    connmanTetheringPageReload();
+                    showMsg('Error', 'Please provide identifier and passphrase');
+                    return;
+                }
+
+                technology.setTethering(true, tethering_id, tethering_passphrase, function() {
+                    /* success */
+                    console.log('Successfully tethered connman technology ' + technology.prop.Type);
+                    connmanTetheringPageReload();
+                }, function(e) {
+                    /* error */
+                    connmanTetheringPageReload();
+                    showMsg('Error', 'Cannot tether ' + technology.prop.Type + ': ' + e);
+                });
+            } else {
+                technology.setTethering(true, '', '', function() {
+                    /* success */
+                    console.log('Successfully tethered connman technology ' + technology.prop.Type);
+                    connmanTetheringPageReload();
+                }, function(e) {
+                    /* error */
+                    connmanTetheringPageReload();
+                    showMsg('Error', 'Cannot tether ' + technology.prop.Type + ': ' + e);
+                });
+            }
+        } else {
+            technology.setTethering(false, '', '', function() {
+                /* success */
+                console.log('Successfully untethered connman technology ' + technology.prop.Type);
+                connmanTetheringPageReload();
+            }, function(e) {
+                /* error */
+                connmanTetheringPageReload();
+                showMsg('Error', 'Cannot untether ' + technology.prop.Type + ': ' + e);
+            });
+        }
+    });
+}
+
 function connmanUpdateService(service) {
     connmanAppendToAvailableList(service);
 
index ec54a7b..e22245e 100644 (file)
@@ -292,9 +292,11 @@ var wsAPI = (function() {
                                         {
                                             "Name": "WiFi",
                                             "Type": "wifi",
-                                            "Powered": false,
-                                            "Connected": false,
-                                            "Tethering": false
+                                            "Powered": true,
+                                            "Connected": true,
+                                            "Tethering": true,
+                                            "TetheringIdentifier": "tetherme",
+                                            "TetheringPassphrase": "0123456789"
                                         }],
                                         ["/net/connman/technology/bluetooth",
                                         {
@@ -318,6 +320,9 @@ var wsAPI = (function() {
                                 call.successCB();
                                 fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Powered", false]);
                                 return;
+                            } else if (msg.name === 'tethering') {
+                                call.successCB();
+                                return;
                             } else if (msg.name === 'get_services' || msg.name === 'scan') {
                                 var results = [
                                     [
index 7f192e4..01031b1 100644 (file)
@@ -1,3 +1,6 @@
+* Tue Feb 11 2014 Jimmy Huang <jimmy.huang@intel.com> accepted/tizen/ivi/20140205.225825@41cc562
+- Implements TIVI-2083, adds tethering support
+
 * Wed Feb 05 2014 Jimmy Huang <jimmy.huang@intel.com> accepted/tizen/ivi/20140110.224142@9df45ae
 - Added support for autoconnect for connman services