From 54a5d9d8ff76389cce8fbf33d5b9c94e83eeb0ca Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Mon, 6 Feb 2017 21:56:51 +0900 Subject: [PATCH] Remove UI Dependency for headless devices It is recommended to separate the UI-related parts into separate packages. So I created a sub-package and moved all the UI-related parts. Change-Id: Ic56f364dfa75af915f6ec79aa3860c9e87eb00ec --- CMakeLists.txt | 10 +- include/plugin.h | 62 ++++++++ include/util.h | 12 +- packaging/net-config.spec | 22 ++- plugin/headed/CMakeLists.txt | 44 ++++++ plugin/headed/headed.c | 271 +++++++++++++++++++++++++++++++++++ src/main.c | 4 + src/network-state.c | 23 ++- src/utils/util.c | 180 +++++++++-------------- src/wifi-agent.c | 1 - src/wifi-state.c | 32 +---- 11 files changed, 493 insertions(+), 168 deletions(-) create mode 100755 include/plugin.h create mode 100644 plugin/headed/CMakeLists.txt create mode 100755 plugin/headed/headed.c diff --git a/CMakeLists.txt b/CMakeLists.txt index fbf35e8..fa38d65 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,15 +77,11 @@ PKG_CHECK_MODULES(pkgs REQUIRED dlog tapi vconf - bundle gio-2.0 glib-2.0 gio-unix-2.0 - eventsystem - alarm-service - syspopup-caller capi-system-info - capi-appfw-application + libtzplatform-config ${P2P_REQUIRED_PKGS} ${WEARABLE_REQUIRED_PKGS} ) @@ -129,6 +125,8 @@ ADD_CUSTOM_COMMAND( ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS} ${CMAKE_SOURCE_DIR}/generated-code.c) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} ${PCAP_LIB}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} ${PCAP_LIB} "-ldl") INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR}) + +ADD_SUBDIRECTORY(plugin/headed) diff --git a/include/plugin.h b/include/plugin.h new file mode 100755 index 0000000..1c24fe9 --- /dev/null +++ b/include/plugin.h @@ -0,0 +1,62 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __NETCONFIG_PLUGIN_H__ +#define __NETCONFIG_PLUGIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define NETCONFIG_ADD_FOUND_AP_NOTI "add_found_ap_noti" +#define NETCONFIG_DEL_FOUND_AP_NOTI "del_found_ap_noti" +#define NETCONFIG_ADD_PORTAL_NOTI "add_portal_noti" +#define NETCONFIG_DEL_PORTAL_NOTI "del_portal_noti" + +struct netconfig_headed_plugin_t { + void (*pop_device_picker) (void); + gboolean (*send_notification_to_net_popup) (const char *, const char *); + int (*send_message_to_net_popup) (const char *, const char *, const char *, const char *); + int (*send_restriction_to_net_popup) (const char *, const char *, const char *); + void (*set_system_event) (int, int, int); + void (*pop_wifi_connected_poppup) (const char *); +}; + +typedef enum { + SYS_EVT_NETWORK_STATUS = 0, + SYS_EVT_WIFI_STATE = 1, + EKEY_NETWORK_STATUS = 10, + EKEY_WIFI_STATE = 11, + EVAL_NETWORK_WIFI = 20, + EVAL_NETWORK_CELLULAR = 21, + EVAL_NETWORK_ETHERNET = 22, + EVAL_NETWORK_BT = 23, + EVAL_NETWORK_DISCONNECTED = 24, + EVAL_WIFI_CONNECTED = 25, + EVAL_WIFI_ON = 26, + EVAL_WIFI_OFF = 27, +} sys_evt_t; + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_PLUGIN_H__ */ diff --git a/include/util.h b/include/util.h index 908c737..2cce5ee 100755 --- a/include/util.h +++ b/include/util.h @@ -27,11 +27,8 @@ extern "C" { #include #include "wifi.h" +#include "plugin.h" -#define NETCONFIG_ADD_FOUND_AP_NOTI "add_found_ap_noti" -#define NETCONFIG_DEL_FOUND_AP_NOTI "del_found_ap_noti" -#define NETCONFIG_ADD_PORTAL_NOTI "add_portal_noti" -#define NETCONFIG_DEL_PORTAL_NOTI "del_portal_noti" #define NETCONFIG_TIZEN_SYSTEM_ENV "/run/tizen-system-env" #define MAX_SIZE_ERROR_BUFFER 256 @@ -71,7 +68,7 @@ int netconfig_send_message_to_net_popup(const char *title, const char *content, const char *type, const char *ssid); int netconfig_send_restriction_to_net_popup(const char *title, const char *type, const char *restriction); -void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val); +void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val); void netconfig_set_vconf_int(const char * key, int value); void netconfig_set_vconf_str(const char * key, const char * value); int netconfig_vconf_get_int(const char * key, int *value); @@ -79,6 +76,11 @@ int netconfig_vconf_get_bool(const char * key, int *value); char* netconfig_get_env(const char *key); void netconfig_set_mac_address_from_file(void); +void __netconfig_pop_wifi_connected_poppup(const char *ssid); +void netconfig_plugin_init(); +void netconfig_plugin_deinit(); +gboolean netconfig_get_headed_plugin_flag(); + #ifdef __cplusplus } #endif diff --git a/packaging/net-config.spec b/packaging/net-config.spec index d602bcc..d4bf2cd 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.1.98 +Version: 1.1.99 Release: 2 Group: System/Network License: Apache-2.0 @@ -8,14 +8,9 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(eventsystem) -BuildRequires: pkgconfig(alarm-service) -BuildRequires: pkgconfig(syspopup-caller) BuildRequires: pkgconfig(capi-system-info) -BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-network-wifi-direct) BuildRequires: pkgconfig(capi-vpnsvc) BuildRequires: cmake @@ -43,6 +38,16 @@ Requires: %{name} = %{version}-%{release} %description profile_tv TIZEN Network Configuration service extension for Tizen TV profile. +%package plugin-headed +Summary: net-config extension for headed profile +BuildRequires: pkgconfig(bundle) +BuildRequires: pkgconfig(eventsystem) +BuildRequires: pkgconfig(alarm-service) +BuildRequires: pkgconfig(syspopup-caller) +BuildRequires: pkgconfig(capi-appfw-application) +Requires: %{name} = %{version}-%{release} +%description plugin-headed +TIZEN Network Configuration service extension for headed profile. %prep %setup -q @@ -192,3 +197,8 @@ mv %{_unitdir}/net-config.service.tv %{_unitdir}/net-config.service %if "%{?_lib}" == "lib64" %attr(644,root,root) %{_unitdir}/net-config.service.tv %endif + +%files plugin-headed +%manifest net-config.manifest +%attr(500,root,root) %{_libdir}/net-config-plugin-headed.so + diff --git a/plugin/headed/CMakeLists.txt b/plugin/headed/CMakeLists.txt new file mode 100644 index 0000000..d65c185 --- /dev/null +++ b/plugin/headed/CMakeLists.txt @@ -0,0 +1,44 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(net-config-plugin-headed C) + +IF(TIZEN_WEARABLE) + ADD_DEFINITIONS(-DTIZEN_WEARABLE) +ENDIF(TIZEN_WEARABLE) + +# Set required packages +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(pkgs_headed REQUIRED + dlog + vconf + gio-2.0 + gio-unix-2.0 + glib-2.0 + bundle + eventsystem + alarm-service + syspopup-caller + capi-appfw-application + ) + +FOREACH(flag ${pkgs_headed_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +# INCLUDE_DIRECTORIES(SRCS include) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +SET(SRCS_HEADED + headed.c + ) + +# library build +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS_HEADED}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_headed_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${PROJECT_NAME}) + +# install +INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIBDIR}) diff --git a/plugin/headed/headed.c b/plugin/headed/headed.c new file mode 100755 index 0000000..2550fc7 --- /dev/null +++ b/plugin/headed/headed.c @@ -0,0 +1,271 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "plugin.h" + +#ifdef USE_NETCONFIG_LOG +#include "log.h" +#else +#include + +#define NETCONFIG_TAG "NETCONFIG" +#define __LOG(level, format, arg...) \ + do { \ + SLOG(level, NETCONFIG_TAG, format, ## arg); \ + } while (0) + +#define DBG(format, arg...) __LOG(LOG_DEBUG, format, ## arg) +#define ERR(format, arg...) __LOG(LOG_ERROR, format, ## arg) +#endif + +const char *_headed_convert_sys_event(int event_val) +{ + switch (event_val) { + case SYS_EVT_NETWORK_STATUS: + return SYS_EVENT_NETWORK_STATUS; + case SYS_EVT_WIFI_STATE: + return SYS_EVENT_WIFI_STATE; + case EKEY_NETWORK_STATUS: + return EVT_KEY_NETWORK_STATUS; + case EKEY_WIFI_STATE: + return EVT_KEY_WIFI_STATE; + case EVAL_NETWORK_WIFI: + return EVT_VAL_NETWORK_WIFI; + case EVAL_NETWORK_CELLULAR: + return EVT_VAL_NETWORK_CELLULAR; + case EVAL_NETWORK_ETHERNET: + return EVT_VAL_NETWORK_ETHERNET; + case EVAL_NETWORK_BT: + return EVT_VAL_NETWORK_BT; + case EVAL_NETWORK_DISCONNECTED: + return EVT_VAL_NETWORK_DISCONNECTED; + case EVAL_WIFI_CONNECTED: + return EVT_VAL_WIFI_CONNECTED; + case EVAL_WIFI_ON: + return EVT_VAL_WIFI_ON; + case EVAL_WIFI_OFF: + return EVT_VAL_WIFI_OFF; + default: + break; + } + + return NULL; +} + +void headed_pop_device_picker(void) +{ +#if defined TIZEN_WEARABLE + int ret = 0; + app_control_h control = NULL; + + ret = app_control_create(&control); + if (APP_CONTROL_ERROR_NONE != ret) { + DBG("failed to create app control"); + return ; + } + + app_control_add_extra_data(control, "viewtype", "scanlist"); + + app_control_set_app_id(control, "org.tizen.wifi"); + ret = app_control_send_launch_request(control, NULL, NULL); + if (APP_CONTROL_ERROR_NONE == ret) + DBG("Launch request sent successfully"); + + app_control_destroy(control); +#else + bundle *b = NULL; + int wifi_ug_state = 0; + int ret = 0; + + ret = vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state); + if (ret != VCONF_OK) + ERR("Failed to get vconfkey [%s] value", VCONFKEY_WIFI_UG_RUN_STATE); + + if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) + return; + + b = bundle_create(); + + DBG("Launch Wi-Fi device picker"); + syspopup_launch("wifi-qs", b); + + bundle_free(b); +#endif +} + + +gboolean headed_send_notification_to_net_popup(const char * noti, const char * ssid) +{ + int ret = 0; + bundle *b; + static gboolean is_found_noti_exists = FALSE; + static gboolean is_portal_noti_exists = FALSE; + + if (noti == NULL) { + ERR("Invalid notification"); + return FALSE; + } + + if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) { + if (is_found_noti_exists == FALSE) + return TRUE; + + is_found_noti_exists = FALSE; + } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) { + if (is_found_noti_exists == TRUE) + return TRUE; + + is_found_noti_exists = TRUE; + } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) { + if (is_portal_noti_exists == TRUE) + return TRUE; + + is_portal_noti_exists = TRUE; + } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) { + if (is_portal_noti_exists == FALSE) + return TRUE; + + is_portal_noti_exists = FALSE; + } + + b = bundle_create(); + bundle_add(b, "_SYSPOPUP_TYPE_", noti); + + if (ssid != NULL) { + DBG("ssid (%s)", ssid); + bundle_add(b, "_AP_NAME_", ssid); + } + + ret = syspopup_launch("net-popup", b); + + bundle_free(b); + + if (ret < 0) { + ERR("Unable to launch noti-popup. Err = %d", ret); + return FALSE; + } + + DBG("Successfully sent notification (%s)", noti); + return TRUE; +} + +int headed_send_message_to_net_popup(const char *title, + const char *content, const char *type, const char *ssid) +{ + int ret = 0; + bundle *b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TITLE_", title); + bundle_add(b, "_SYSPOPUP_CONTENT_", content); + bundle_add(b, "_SYSPOPUP_TYPE_", type); + bundle_add(b, "_AP_NAME_", ssid); + + ret = syspopup_launch("net-popup", b); + + bundle_free(b); + + return ret; +} + +int headed_send_restriction_to_net_popup(const char *title, + const char *type, const char *restriction) +{ + int ret = 0; + bundle *b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TITLE_", title); + bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction"); + bundle_add(b, "_SYSPOPUP_TYPE_", type); + bundle_add(b, "_RESTRICTED_TYPE_", restriction); + + ret = syspopup_launch("net-popup", b); + + bundle_free(b); + + return ret; +} + +void headed_set_system_event(int sys_evt, int evt_key, int evt_val) +{ + bundle *b = NULL; + const char *sevent = _headed_convert_sys_event(sys_evt); + const char *ekey = _headed_convert_sys_event(evt_key); + const char *eval = _headed_convert_sys_event(evt_val); + + DBG("System event set [%s : %s : %s]", sevent, ekey, eval); + + b = bundle_create(); + bundle_add_str(b, ekey, eval); + eventsystem_send_system_event(sevent, b); + bundle_free(b); +} + +void headed_pop_wifi_connected_poppup(const char *ssid) +{ + bundle *b = NULL; + + if (ssid == NULL) + return; + + b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TITLE_", "Network connection popup"); + bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup"); + bundle_add(b, "_SYSPOPUP_CONTENT_", "wifi connected"); + bundle_add(b, "_AP_NAME_", ssid); + + DBG("Launch Wi-Fi connected alert network popup"); + syspopup_launch("net-popup", b); + + bundle_free(b); +} + + +extern struct netconfig_headed_plugin_t netconfig_headed_plugin + __attribute__ ((visibility("default"))); +struct netconfig_headed_plugin_t netconfig_headed_plugin = { + headed_pop_device_picker, + headed_send_notification_to_net_popup, + headed_send_message_to_net_popup, + headed_send_restriction_to_net_popup, + headed_set_system_event, + headed_pop_wifi_connected_poppup +}; + diff --git a/src/main.c b/src/main.c index c3a3584..3892e69 100755 --- a/src/main.c +++ b/src/main.c @@ -145,8 +145,12 @@ int main(int argc, char *argv[]) ERR("Error - Feature getting from System Info"); } + netconfig_plugin_init(); + g_main_loop_run(main_loop); + netconfig_plugin_deinit(); + _objects_deinit(); log_cleanup(); diff --git a/src/network-state.c b/src/network-state.c index f0c488f..61c001a 100755 --- a/src/network-state.c +++ b/src/network-state.c @@ -28,9 +28,6 @@ #include #include #include -#include -#include -#include #include "log.h" #include "util.h" @@ -478,8 +475,8 @@ static void __netconfig_update_default_connection_info(void) netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_WIFI); netconfig_set_vconf_int("memory/private/wifi/frequency", freq); - netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS, - EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_WIFI); + netconfig_set_system_event(SYS_EVT_NETWORK_STATUS, + EKEY_NETWORK_STATUS, EVAL_NETWORK_WIFI); } else if (netconfig_is_cellular_profile(profile)) { if (!netconfig_is_cellular_internet_profile(profile)) { @@ -489,20 +486,20 @@ static void __netconfig_update_default_connection_info(void) netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_CELLULAR); - netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS, - EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_CELLULAR); + netconfig_set_system_event(SYS_EVT_NETWORK_STATUS, + EKEY_NETWORK_STATUS, EVAL_NETWORK_CELLULAR); } else if (netconfig_is_ethernet_profile(profile) == TRUE) { netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_ETHERNET); - netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS, - EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_ETHERNET); + netconfig_set_system_event(SYS_EVT_NETWORK_STATUS, + EKEY_NETWORK_STATUS, EVAL_NETWORK_ETHERNET); } else if (netconfig_is_bluetooth_profile(profile) == TRUE) { netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_BLUETOOTH); - netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS, - EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_BT); + netconfig_set_system_event(SYS_EVT_NETWORK_STATUS, + EKEY_NETWORK_STATUS, EVAL_NETWORK_BT); } else{ netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_OFF); - netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS, - EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_DISCONNECTED); + netconfig_set_system_event(SYS_EVT_NETWORK_STATUS, + EKEY_NETWORK_STATUS, EVAL_NETWORK_DISCONNECTED); } if (g_strcmp0(old_ip, ip_addr) != 0 || old_ip == NULL) { diff --git a/src/utils/util.c b/src/utils/util.c index 6fbba12..6efd972 100755 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -17,7 +17,7 @@ * */ -#include +#include #include #include #include @@ -31,10 +31,6 @@ #include #include #include -#include -#include -#include -#include #include #include @@ -49,6 +45,7 @@ #define MAC_INFO_FILEPATH tzplatform_mkpath(TZ_SYS_ETC, "/.mac.info") #define MAC_ADDRESS_FILEPATH "/sys/class/net/wlan0/address" #define MAC_ADDRESS_MAX_LEN 18 +#define HEADED_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-headed.so" static gboolean netconfig_device_picker_test = FALSE; static int mdnsd_ref_count = 0; @@ -57,6 +54,10 @@ typedef struct { int conn_id; } dnssd_conn_destroy_data; +static gboolean netconfig_plugin_headed_enabled = FALSE; +static void *handle_headed; +static struct netconfig_headed_plugin_t *headed_plugin; + GKeyFile *netconfig_keyfile_load(const char *pathname) { GKeyFile *keyfile = NULL; @@ -199,39 +200,13 @@ static gboolean __netconfig_test_device_picker() static void __netconfig_pop_device_picker(void) { -#if defined TIZEN_WEARABLE - int ret = 0; - app_control_h control = NULL; - - ret = app_control_create(&control); - if (APP_CONTROL_ERROR_NONE != ret) { - DBG("failed to create app control"); - return ; - } - - app_control_add_extra_data(control, "viewtype", "scanlist"); - - app_control_set_app_id(control, "org.tizen.wifi"); - ret = app_control_send_launch_request(control, NULL, NULL); - if (APP_CONTROL_ERROR_NONE == ret) - DBG("Launch request sent successfully"); - - app_control_destroy(control); -#else - bundle *b = NULL; - int wifi_ug_state = 0; - - netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state); - if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) + if (!netconfig_plugin_headed_enabled) return; - b = bundle_create(); - - DBG("Launch Wi-Fi device picker"); - syspopup_launch("wifi-qs", b); + if (!headed_plugin) + return; - bundle_free(b); -#endif + headed_plugin->pop_device_picker(); } static gboolean __netconfig_wifi_try_device_picker(gpointer data) @@ -865,105 +840,59 @@ gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context, gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid) { - int ret = 0; - bundle *b; - static gboolean is_found_noti_exists = FALSE; - static gboolean is_portal_noti_exists = FALSE; - - if (noti == NULL) { - ERR("Invalid notification"); + if (!netconfig_plugin_headed_enabled) return FALSE; - } - - if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) { - if (is_found_noti_exists == FALSE) - return TRUE; - - is_found_noti_exists = FALSE; - } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) { - if (is_found_noti_exists == TRUE) - return TRUE; - - is_found_noti_exists = TRUE; - } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) { - if (is_portal_noti_exists == TRUE) - return TRUE; - - is_portal_noti_exists = TRUE; - } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) { - if (is_portal_noti_exists == FALSE) - return TRUE; - - is_portal_noti_exists = FALSE; - } - b = bundle_create(); - bundle_add(b, "_SYSPOPUP_TYPE_", noti); - - if (ssid != NULL) { - DBG("ssid (%s)", ssid); - bundle_add(b, "_AP_NAME_", ssid); - } - - ret = syspopup_launch("net-popup", b); - - bundle_free(b); - - if (ret < 0) { - ERR("Unable to launch noti-popup. Err = %d", ret); + if (!headed_plugin) return FALSE; - } - DBG("Successfully sent notification (%s)", noti); - return TRUE; + return headed_plugin->send_notification_to_net_popup(noti, ssid); } int netconfig_send_message_to_net_popup(const char *title, const char *content, const char *type, const char *ssid) { - int ret = 0; - bundle *b = bundle_create(); - - bundle_add(b, "_SYSPOPUP_TITLE_", title); - bundle_add(b, "_SYSPOPUP_CONTENT_", content); - bundle_add(b, "_SYSPOPUP_TYPE_", type); - bundle_add(b, "_AP_NAME_", ssid); - - ret = syspopup_launch("net-popup", b); + if (!netconfig_plugin_headed_enabled) + return 0; - bundle_free(b); + if (!headed_plugin) + return 0; - return ret; + return headed_plugin->send_message_to_net_popup(title, content, type, ssid); } int netconfig_send_restriction_to_net_popup(const char *title, const char *type, const char *restriction) { - int ret = 0; - bundle *b = bundle_create(); + if (!netconfig_plugin_headed_enabled) + return 0; - bundle_add(b, "_SYSPOPUP_TITLE_", title); - bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction"); - bundle_add(b, "_SYSPOPUP_TYPE_", type); - bundle_add(b, "_RESTRICTED_TYPE_", restriction); + if (!headed_plugin) + return 0; - ret = syspopup_launch("net-popup", b); + return headed_plugin->send_restriction_to_net_popup(title, type, restriction); +} - bundle_free(b); +void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val) +{ + if (!netconfig_plugin_headed_enabled) + return; - return ret; + if (!headed_plugin) + return; + + headed_plugin->set_system_event(sys_evt, evt_key, evt_val); } -void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val) +void __netconfig_pop_wifi_connected_poppup(const char *ssid) { - bundle *b = NULL; + if (!netconfig_plugin_headed_enabled) + return; - DBG("System event set [%s : %s : %s]", sys_evt, evt_key, evt_val); + if (!headed_plugin) + return; - b = bundle_create(); - bundle_add_str(b, evt_key, evt_val); - eventsystem_send_system_event(sys_evt, b); - bundle_free(b); + headed_plugin->pop_wifi_connected_poppup(ssid); } void netconfig_set_vconf_int(const char * key, int value) @@ -1118,3 +1047,36 @@ tizen_profile_t _get_tizen_profile() return profile; } + +void netconfig_plugin_init() +{ + handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW); + if (!handle_headed) { + ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror()); + return; + } + + headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin"); + if (!headed_plugin) { + ERR("Can't load symbol: %s", dlerror()); + dlclose(handle_headed); + return; + } + + netconfig_plugin_headed_enabled = TRUE; +} + +void netconfig_plugin_deinit() +{ + if (!netconfig_plugin_headed_enabled) + return; + + netconfig_plugin_headed_enabled = FALSE; + dlclose(handle_headed); +} + +gboolean netconfig_get_headed_plugin_flag() +{ + return netconfig_plugin_headed_enabled; +} + diff --git a/src/wifi-agent.c b/src/wifi-agent.c index 61dc12a..2d3c745 100755 --- a/src/wifi-agent.c +++ b/src/wifi-agent.c @@ -17,7 +17,6 @@ * */ -#include #include #include #include diff --git a/src/wifi-state.c b/src/wifi-state.c index 072431f..4fb0e44 100755 --- a/src/wifi-state.c +++ b/src/wifi-state.c @@ -19,10 +19,6 @@ #include #include -#include -#include -#include -#include #include "log.h" #include "util.h" @@ -48,26 +44,6 @@ static GSList *notifier_list = NULL; static guint network_connected_popup_timer_id = 0; static gboolean block_network_connected_popup = FALSE; -static void __netconfig_pop_wifi_connected_poppup(const char *ssid) -{ - bundle *b = NULL; - - if (ssid == NULL) - return; - - b = bundle_create(); - - bundle_add(b, "_SYSPOPUP_TITLE_", "Network connection popup"); - bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup"); - bundle_add(b, "_SYSPOPUP_CONTENT_", "wifi connected"); - bundle_add(b, "_AP_NAME_", ssid); - - DBG("Launch Wi-Fi connected alert network popup"); - syspopup_launch("net-popup", b); - - bundle_free(b); -} - static gboolean _block_network_connection_popup(gpointer data) { block_network_connected_popup = FALSE; @@ -460,7 +436,7 @@ void wifi_state_update_power_state(gboolean powered) netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED); netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); - netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON); + netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON); netconfig_wifi_bgscan_stop(); netconfig_wifi_bgscan_start(TRUE); @@ -484,7 +460,7 @@ void wifi_state_update_power_state(gboolean powered) netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF); netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF); - netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_OFF); + netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_OFF); netconfig_wifi_set_bgscan_pause(FALSE); netconfig_wifi_bgscan_stop(); @@ -570,7 +546,7 @@ void wifi_state_set_service_state(wifi_service_state_e new_state) netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_CONNECTED); netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_CONNECTED); - netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_CONNECTED); + netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_CONNECTED); __set_wifi_connected_essid(); @@ -583,7 +559,7 @@ void wifi_state_set_service_state(wifi_service_state_e new_state) netconfig_set_vconf_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED); netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); - netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON); + netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON); netconfig_wifi_indicator_stop(); -- 2.34.1