Add APIs to set/get auto connection mode 66/149966/3 accepted/tizen/unified/20170921.072212 submit/tizen/20170920.020838
authortaesub kim <taesub.kim@samsung.com>
Thu, 14 Sep 2017 00:31:40 +0000 (09:31 +0900)
committertaesub kim <taesub.kim@samsung.com>
Mon, 18 Sep 2017 00:13:25 +0000 (09:13 +0900)
Change-Id: I81a3438278354b225f8d3b1fe55bac26e0ea8b14
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
include/network_dbus.h
include/network_interface.h
include/wifi_internal.h
include/wifi_manager_extension.h
src/network_dbus.c
src/network_interface.c
src/wifi_internal.c
src/wifi_manager.c
test/wifi_manager_test.c

index bce8821aedfca30f3b3693452077eb8071c2add5..505858b43adff61979320595550783d2eb9e9400 100755 (executable)
@@ -149,7 +149,8 @@ int _net_dbus_get_vsie(unsigned int frame_id, char **vsie_str);
 int _net_dbus_remove_vsie(unsigned int frame_id, const char *vsie_str);
 int _net_dbus_get_vsie_list(GSList **vsie_list);
 int _net_dbus_flush_bss(void);
-
+int _net_dbus_get_auto_connect_mode(int *connect_mode);
+int _net_dbus_set_auto_connect_mode(int connect_mode);
 
 #ifdef __cplusplus
 }
index 51f103b292be85b27d1baaf3de9f72ae709a1cf5..1a1f2282e1f3c4a63fe6a865009389336bb237f4 100755 (executable)
@@ -258,6 +258,8 @@ int net_wifi_get_vsie(unsigned int frame_id, char **vsie_str);
 int net_wifi_remove_vsie(unsigned int frame_id, const char *vsie_str);
 int net_wifi_get_vsie_list(GSList **vsie_list);
 int net_wifi_flush_bss(void);
+int net_wifi_get_auto_connect_mode(int *connect_mode);
+int net_wifi_set_auto_connect_mode(int connect_mode);
 
 int net_wifi_cancel_wps(void);
 
index 777182285f60c832780a3887f0f9aa2feeb1e2e2..8bf997ff943642a2ee043c3d43159e1695debcd1 100755 (executable)
@@ -290,7 +290,10 @@ int _wifi_get_vsie(wifi_manager_h wifi,
 int _wifi_remove_vsie(wifi_manager_h wifi,
                wifi_manager_vsie_frames_e frame_id, const char *vsie_str);
 int _wifi_get_vsie_list(wifi_manager_vsie_list_cb callback, void *user_data);
+
 int _wifi_flush_bss(void);
+int _wifi_get_auto_connect(int *connect_mode);
+int _wifi_set_auto_connect(int connect_mode);
 
 /* WIFI Privilege Check */
 int _wifi_check_get_privilege();
index f103414512ab737b796cf4f42e82ba3fb80b6b24..9c2b2e61f83d8b413b5c8013ec9c9df4ce780a28 100755 (executable)
@@ -280,6 +280,29 @@ int wifi_manager_get_vsie_list(wifi_manager_h wifi,
  */
 int wifi_manager_flush_bss(wifi_manager_h wifi);
 
+/**
+ * @brief Gets auto connect mode
+ * @since_tizen 4.0
+ * @param[out] connect_mode pointer
+ * @return 0 on success, otherwise negative error value.
+ * @retval #WIFI_ERROR_NONE  Successful
+ * @retval #WIFI_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #WIFI_ERROR_INVALID_OPERATION  Invalid operation
+ */
+int wifi_manager_get_auto_connect(wifi_manager_h wifi, int *connect_mode);
+
+/**
+ * @brief Sets auto connect mode
+ * @since_tizen 4.0
+ * @param[in] connect_mode
+ * @return 0 on success, otherwise negative error value.
+ * @retval #WIFI_ERROR_NONE  Successful
+ * @retval #WIFI_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #WIFI_ERROR_INVALID_OPERATION  Invalid operation
+ */
+int wifi_manager_set_auto_connect(wifi_manager_h wifi, int connect_mode);
+
+
 /**
 * @}
 */
index 32339d3744a7ce8155cf2367482d016da17c5591..6ed89e57e413c5ea6b4118e45ebc8ceb5d065b01 100755 (executable)
@@ -588,6 +588,33 @@ static void __net_set_passpoint_reply(GObject *source_object, GAsyncResult *res,
        __NETWORK_FUNC_EXIT__;
 }
 
+static void __net_set_auto_connect_reply(GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       net_err_e Error = NET_ERR_NONE;
+
+       WIFI_LOG(WIFI_INFO, "WiFi set auto connection reply");
+
+       conn = G_DBUS_CONNECTION(source_object);
+       g_dbus_connection_call_finish(conn, res, &error);
+       if (error != NULL) {
+               Error = __net_netconfig_error_string_to_enum(error->message);
+               g_error_free(error);
+       }
+
+       if (Error != NET_ERR_NONE)
+               WIFI_LOG(WIFI_ERROR, "set auto connect failed[%d]", Error);
+       else
+               WIFI_LOG(WIFI_INFO, "set auto connect succeeded");
+
+       _net_dbus_pending_call_unref();
+       __NETWORK_FUNC_EXIT__;
+}
+
+
 static char *__net_make_group_name(const char *ssid,
                const char *net_mode, const char *sec)
 {
@@ -2094,9 +2121,85 @@ int _net_dbus_flush_bss(void)
        g_variant_unref(message);
        WIFI_LOG(WIFI_INFO, "Successfully flush bss\n");
 
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+int _net_dbus_get_auto_connect_mode(int *connect_mode)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+       GVariant *value = NULL;
+       GVariantIter *iter = NULL;
+       gchar *key = NULL;
+       gboolean status = TRUE;
+
+       message = _net_invoke_dbus_method(
+                       CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
+                       CONNMAN_MANAGER_INTERFACE, "GetProperties", NULL, &Error);
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get service properties");
+
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+
+       g_variant_get(message, "(a{sv})", &iter);
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               if (g_strcmp0(key, "AutoConnectMode") == 0) {
+                       status = g_variant_get_boolean(value);
+                       g_variant_unref(value);
+                       g_free(key);
+                       break;
+               }
+       }
+
+       *connect_mode = (int)status;
+
+       WIFI_LOG(WIFI_INFO, "Successfully auto connect mode: %d", *connect_mode);
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
        return Error;
 }
 
+
+int _net_dbus_set_auto_connect_mode(int connect_mode)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       GVariant *params = NULL;
+       GVariant *param0 = NULL;
+       net_err_e Error = NET_ERR_NONE;
+       char key[] = "AutoConnectMode";
+       gboolean value_enable = TRUE;
+       gboolean value_disable = FALSE;
+
+       WIFI_LOG(WIFI_INFO, "Request auto connect mode [%s]",
+                       connect_mode == 1 ? "enable" : "disable");
+
+       if (connect_mode == 1)
+               param0 = g_variant_new_boolean(value_enable);
+       else
+               param0 = g_variant_new_boolean(value_disable);
+
+       params = g_variant_new("(sv)", key, param0);
+
+       Error = _net_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
+                       CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
+                       "SetProperty", params, 6 * DBUS_REPLY_TIMEOUT,
+                       __net_set_auto_connect_reply);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+
 static void __net_wps_cancel_reply(GObject *source_object,
                GAsyncResult *res, gpointer user_data)
 {
index ef1ac21ca652257b1f392143ba37a33c8fd39f3a..b65265a1a39fab818f37a92510251eb4e1998fdd 100755 (executable)
@@ -1744,7 +1744,6 @@ int net_wifi_get_vsie_list(GSList **vsie_list)
        __NETWORK_FUNC_EXIT__;
        return Error;
 }
-//LCOV_EXCL_STOP
 
 EXPORT_API int net_wifi_flush_bss(void)
 {
@@ -1770,6 +1769,57 @@ EXPORT_API int net_wifi_flush_bss(void)
        return NET_ERR_NONE;
 }
 
+EXPORT_API int net_wifi_set_auto_connect_mode(int connect_mode)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+
+       if (NetworkInfo.ref_count < 1) {
+               WIFI_LOG(WIFI_ERROR, "Application is not registered");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_APP_NOT_REGISTERED;
+       }
+
+       if ((Error = _net_dbus_set_auto_connect_mode(connect_mode)) != NET_ERR_NONE) {
+               WIFI_LOG(WIFI_ERROR,
+                               "Failed to set auto connect mode. Error [%s]",
+                               _net_print_error(Error));
+
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+
+       __NETWORK_FUNC_EXIT__;
+       return NET_ERR_NONE;
+}
+
+EXPORT_API int net_wifi_get_auto_connect_mode(int *connect_mode)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+
+       if (NetworkInfo.ref_count < 1) {
+               WIFI_LOG(WIFI_ERROR, "Application is not registered");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_APP_NOT_REGISTERED;
+       }
+
+       if ((Error = _net_dbus_get_auto_connect_mode(connect_mode)) != NET_ERR_NONE) {
+               WIFI_LOG(WIFI_ERROR,
+                               "Failed to set auto connect mode. Error [%s]",
+                               _net_print_error(Error));
+
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+
+       __NETWORK_FUNC_EXIT__;
+       return NET_ERR_NONE;
+}
+//LCOV_EXCL_STOP
+
 int net_open_connection_with_wifi_info(const net_wifi_connection_info_s *wifi_info)
 {
        __NETWORK_FUNC_ENTER__;
index b8dd277b21365202626c871b871dc399f938f9c7..0fe291e6b21bf2169e0e3c92ec686d49b0b7f698 100755 (executable)
@@ -1775,6 +1775,32 @@ int _wifi_flush_bss(void)
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+int _wifi_set_auto_connect(int connect_mode)
+{
+       int rv;
+
+       rv = net_wifi_set_auto_connect_mode(connect_mode);
+
+       if (rv != NET_ERR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to set auto connection mode");
+       }
+
+       return rv;
+}
+
+int _wifi_get_auto_connect(int *connect_mode)
+{
+       int rv;
+
+       rv = net_wifi_get_auto_connect_mode(connect_mode);
+
+       if (rv != NET_ERR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get auto connection mode");
+       }
+
+       return rv;
+}
+
 int _wifi_get_connected_profile(wifi_manager_ap_h *ap)
 {
        int rv;
index 19894b2799d04c2a8d8b232ac6f752aa860ed393..908133b4530744859f935cd0d33e50c617f7ba23 100755 (executable)
@@ -1032,6 +1032,35 @@ EXPORT_API int wifi_manager_flush_bss(wifi_manager_h wifi)
        return rv;
 
 }
+
+EXPORT_API int wifi_manager_get_auto_connect(wifi_manager_h wifi, int *connect_mode)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+       WIFI_LOG(WIFI_INFO, "[App-->TizenMW] get auto connect mode");
+
+       int rv;
+
+       if (!(__wifi_check_handle_validity(wifi))) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       rv = _wifi_get_auto_connect(connect_mode);
+
+       return rv;
+}
+
+EXPORT_API int wifi_manager_set_auto_connect(wifi_manager_h wifi, int connect_mode)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+       WIFI_LOG(WIFI_INFO, "[App-->TizenMW] set auto connect mode");
+
+       int rv;
+
+       rv = _wifi_set_auto_connect(connect_mode);
+
+       return rv;
+}
 //LCOV_EXCL_STOP
 
 EXPORT_API int wifi_manager_specific_scan_create(wifi_manager_h wifi,
index 5a5d196b5f2bfd7fe0c2734f87e6968288fa5c6f..5a272fe7fbb7dafaf2e5257cfe7f315b6339d2db 100755 (executable)
@@ -2475,6 +2475,42 @@ int test_wifi_manager_flush_bss(void)
        return 1;
 }
 
+int test_wifi_manager_set_auto_connect(void)
+{
+       int rv;
+       int mode;
+
+       printf("Auto connect mode (1:enable, 0:disable) : ");
+       rv = scanf("%d", &mode);
+       if (rv <= 0)
+               return -1;
+
+       rv = wifi_manager_set_auto_connect(wifi, mode);
+
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to set auto connect mode, rv = %d\n", rv);
+       }
+
+       printf("Request to set auto connect mode\n");
+       return 1;
+}
+
+int test_wifi_manager_get_auto_connect(void)
+{
+       int rv;
+       int mode;
+
+       rv = wifi_manager_get_auto_connect(wifi, &mode);
+
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to get auto connect mode, rv = %d\n", rv);
+               return 1;
+       }
+
+       printf("Request to get auto connect mode = %d (1:enable, 0:disable)\n", mode);
+       return 1;
+}
+
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
@@ -2561,6 +2597,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("H   - Remove VSIE\n");
                printf("I   - Start Multi Scan\n");
                printf("J   - Flush BSS\n");
+               printf("K   - Set auto connect mode\n");
+               printf("L   - Get auto connect mode\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
 
                printf("ENTER  - Show options menu.......\n");
@@ -2704,6 +2742,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'J':
                rv = test_wifi_manager_flush_bss();
                break;
+       case 'K':
+               rv = test_wifi_manager_set_auto_connect();
+               break;
+       case 'L':
+               rv = test_wifi_manager_get_auto_connect();
+               break;
        default:
                break;
        }