Add status icon for wifi 25/7825/5
authorsrimaldia <hariasti.srimaldia-1@jp.alps.com>
Thu, 22 Dec 2016 09:47:12 +0000 (18:47 +0900)
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>
Thu, 22 Dec 2016 21:24:42 +0000 (21:24 +0000)
to test this, you need to add conf file under /etc/dbus-1/session.d/

<?xml version="1.0"?> <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
  <policy context="default">
     <allow send_destination="org.agl.homescreen"/>
  </policy>
</busconfig>

Change-Id: I8fa1707883fa4c74460255949bc4ce1cd29cabf2
Signed-off-by: srimaldia <hariasti.srimaldia-1@jp.alps.com>
binding-wifi/wifi-api.c
binding-wifi/wifi-connman.c
binding-wifi/wifi-connman.h

index 2d9748f..f6d6d52 100644 (file)
@@ -272,6 +272,34 @@ void wifi_scanResult(struct afb_req request) /*AFB_SESSION_CHECK*/
                        /*input each scan result into my_array*/
                        json_object_array_add(my_array, jresp);
                        number += 1;
+
+                        //set the HMI icon according to strength, only if "ready" or "online"
+
+                        int error = 0;
+                        struct wifiStatus *status;
+
+                        status = g_try_malloc0(sizeof(struct wifiStatus));
+                        error = wifi_state(status); /*get current status of power and connection*/
+                        if (!error) {
+
+                            if (status->connected == 1) {
+
+                               if ((strcmp(state, "ready") == 0)
+                                    || ((strcmp(state, "online") == 0))) {
+
+                                    if (strength < 30)
+                                        setHMIStatus(BAR_1);
+                                    else if (strength < 50)
+                                        setHMIStatus(BAR_2);
+                                    else if (strength < 70)
+                                        setHMIStatus(BAR_3);
+                                    else
+                                        setHMIStatus(BAR_FULL);
+                               }
+                            } else
+                              setHMIStatus(BAR_NO);
+                      }
+
                }
                while (list != NULL) {
                        printf("Should be freed");
index 74d2be7..68e5e3d 100644 (file)
@@ -350,5 +350,40 @@ void registerPasskey(gchar *passkey) {
        printf("Passkey: %s\n", passkey);
        sendPasskey(passkey);
 
+
+}
+
+GError* setHMIStatus(enum wifiStates state) {
+
+    gchar *iconString = NULL;
+    GDBusConnection *connection;
+    GVariant *params = NULL;
+    GVariant *message = NULL;
+    GError *error = NULL;
+
+    if (state==BAR_NO) iconString = "qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png";
+    else if (state==BAR_1) iconString = "qrc:/images/Status/HMI_Status_Wifi_1Bar-01.png";
+    else if (state==BAR_2) iconString = "qrc:/images/Status/HMI_Status_Wifi_2Bars-01.png";
+    else if (state==BAR_3) iconString = "qrc:/images/Status/HMI_Status_Wifi_3Bars-01.png";
+    else if (state==BAR_FULL) iconString = "qrc:/images/Status/HMI_Status_Wifi_Full-01.png";
+    else iconString = "qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png";
+
+    connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+
+    params = g_variant_new("(is)", HOMESCREEN_WIFI_ICON_POSITION, iconString);
+
+    message = g_dbus_connection_call_sync(connection, HOMESCREEN_SERVICE,
+    HOMESCREEN_ICON_PATH, HOMESCREEN_ICON_INTERFACE, "setStatusIcon", params,
+            NULL, G_DBUS_CALL_FLAGS_NONE,
+            DBUS_REPLY_TIMEOUT, NULL, &error);
+
+    if (error) {
+        printf("error: %s\n", error->message);
+
+        return error;
+    } else {
+        return NULL;
+    }
+
 }
 
index bd83821..c47cbcd 100644 (file)
@@ -52,6 +52,12 @@ extern "C" {
 #define WIFI_MAX_PSK_PASSPHRASE_LEN                    65
 #define WIFI_MAX_WEP_KEY_LEN                           26
 
+#define HOMESCREEN_SERVICE                             "org.agl.homescreen"
+#define HOMESCREEN_ICON_INTERFACE              "org.agl.statusbar"
+#define HOMESCREEN_ICON_PATH                   "/StatusBar"
+#define HOMESCREEN_WIFI_ICON_POSITION          0
+
+
 #define AGENT_PATH "/net/connman/Agent"
 #define AGENT_SERVICE "org.agent"
 
@@ -96,6 +102,8 @@ struct wifi_profile_info{
        struct wifi_net wifiNetwork;
 };
 
+enum wifiStates {BAR_NO, BAR_1, BAR_2, BAR_3, BAR_FULL};
+
 //typedef void(*callback)(void);
 typedef void(*callback)(int password_rejected_flag);
 void register_callback(callback ptr);
@@ -113,6 +121,7 @@ GError* do_disconnectNetwork(gchar *object);
 GError* create_agent(GDBusConnection *connection);
 GError* stop_agent(GDBusConnection *connection);
 
+GError* setHMIStatus(enum wifiStates);
 
 void registerPasskey(gchar *object);
 GError* sendPasskey(gchar *object);