summaryrefslogtreecommitdiff
path: root/src/net-popup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net-popup.c')
-rwxr-xr-xsrc/net-popup.c347
1 files changed, 346 insertions, 1 deletions
diff --git a/src/net-popup.c b/src/net-popup.c
index 707d37b..d70c10a 100755
--- a/src/net-popup.c
+++ b/src/net-popup.c
@@ -37,17 +37,23 @@
#include <tzplatform_config.h>
#include <vpn_service.h>
#include <vpn_service_internal.h>
+#include <stc.h>
+#include <stc_internal.h>
#include "net-popup.h"
#include "net-popup-vpn.h"
#include "net-popup-strings.h"
#define NET_WIFIQS_APPID "net.wifi-qs"
+#define DATA_USAGE_APPID "org.tizen.setting"
#define LOCALEDIR "/usr/share/locale"
#define NETPOPUP_EDJ tzplatform_mkpath(TZ_SYS_RO_UG, "/res/edje/net-popup/netpopup-custom.edj")
#define QP_PRELOAD_NOTI_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "/org.tizen.quickpanel/shared/res/noti_icons/Wi-Fi")
+#define STC_NOTI_DATA_USAGE_ICON_PATH "/usr/share/icons/"
+#define STC_NOTI_DATA_USAGE_ICON_NAME "stc_noti_datausage.png"
+
#define NETCONFIG_NOTIFICATION_WIFI_ICON \
tzplatform_mkpath(TZ_SYS_RO_ICONS, "/noti_wifi_in_range.png")
#define NETCONFIG_NOTIFICATION_WIFI_ICON_LITE \
@@ -63,9 +69,20 @@
#define NETCONFIG_NOTIFICATION_WIFI_FOUND_CONTENT \
dgettext(PACKAGE, "IDS_WIFI_SBODY_TAP_HERE_TO_CONNECT")
#define NETCONFIG_NOTIFICATION_WIFI_PORTAL_TITLE \
- dgettext(PACKAGE, "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB")
+ dgettext(PACKAGE, "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB")
#define NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT "\"%s\""
+#define STC_NOTIFICATION_WARNING_TITLE \
+ dgettext(PACKAGE, "IDS_COM_BODY_DATA_USAGE_WARNING")
+#define STC_NOTIFICATION_WARNING_CONTENT \
+ dgettext(PACKAGE, "IDS_SM_SBODY_TAP_HERE_TO_VIEW_YOUR_DATA_USAGE_ABB")
+#define STC_NOTIFICATION_RESTRICTION_OK_TITLE \
+ dgettext(PACKAGE, "IDS_SM_HEADER_MOBILE_DATA_TURNED_OFF_ABB2")
+#define STC_NOTIFICATION_RESTRICTION_OK_CONTENT \
+ dgettext(PACKAGE, "IDS_SM_SBODY_TAP_HERE_TO_TURN_IT_ON_AGAIN_ABB")
+#define STC_NOTIFICATION_RESTRICTION_ON_TITLE \
+ dgettext(PACKAGE, "IDS_SM_TMBODY_MOBILE_DATA_LIMIT_EXCEEDED_ABB")
+
#define USER_RESP_LEN 30
#define ICON_PATH_LEN 128
#define RESP_REMAIN_CONNECTED "RESP_REMAIN_CONNECTED"
@@ -95,9 +112,15 @@ static char *iface_name = NULL;
static Eina_Bool turn_on_roaming = FALSE;
static Eina_Bool do_not_show_popup = FALSE;
+/* data usage popup */
+static char *data_usage_app_id = NULL;
+static char *data_usage_iftype = NULL;
+
static int __net_popup_show_notification(app_control_h request, void *data);
static int __toast_popup_show(app_control_h request, void *data);
static int __net_popup_show_popup(app_control_h request, void *data);
+static void __net_popup_show_warning_noti(void);
+static void __net_popup_show_restriction_noti(app_control_h request, void *data);
static void __net_popup_add_found_ap_noti(void);
static void __net_popup_del_found_ap_noti(void);
static void __net_popup_add_portal_noti(app_control_h request);
@@ -186,6 +209,49 @@ int __net_popup_send_dbus_msg(const char *resp)
return 0;
}
+void __net_popup_send_data_usage_msg(const char *app_id,
+ const char *iftype)
+{
+ log_print(NET_POPUP, "__net_popup_send_data_usage_msg()\n");
+
+ int ret = STC_ERROR_NONE;
+ stc_h stc = NULL;
+ stc_restriction_rule_h rule = NULL;
+
+ ret = stc_initialize(&stc);
+ if (ret != STC_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to get operation ret= %d\n", ret);
+ return;
+ }
+
+ ret = stc_restriction_rule_create(stc, &rule);
+ if (ret != STC_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to create restriction rule ret= %d\n", ret);
+ return;
+ }
+
+ ret = stc_restriction_rule_set_app_id(rule, app_id);
+ if (ret != STC_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to set application ID ret= %d\n", ret);
+ return;
+ }
+
+ ret = stc_restriction_rule_set_iface_type(rule, iftype[0] - '0');
+ if (ret != STC_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to set interface type ret= %d\n", ret);
+ return;
+ }
+
+ ret = stc_unset_restriction(stc, rule);
+ if (ret != STC_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to unset restriction ret= %d\n", ret);
+ return;
+ }
+
+ log_print(NET_POPUP, "Success to unset restriction\n");
+ return;
+}
+
static bool __net_popup_create(void *data)
{
log_print(NET_POPUP, "__net_popup_create()\n");
@@ -324,6 +390,11 @@ static void __net_popup_service_cb(app_control_h request, void *data)
__toast_popup_show(request, data);
} else if (g_str_equal(type, "popup")) {
__net_popup_show_popup(request, data);
+ } else if (g_str_equal(type, "warning_noti")) {
+ __net_popup_show_warning_noti();
+ elm_exit();
+ } else if (g_str_equal(type, "restriction_noti")) {
+ __net_popup_show_restriction_noti(request, data);
} else if (g_str_equal(type, "add_found_ap_noti")) {
__net_popup_add_found_ap_noti();
elm_exit();
@@ -577,6 +648,21 @@ static int __toast_popup_show(app_control_h request, void *data)
g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
log_print(NET_POPUP, "alert wifi connected\n");
g_free(ap_name);
+ } else if (strcmp(mode, "warn threshold crossed") == 0) {
+ char *app_id = NULL;
+
+ ret = app_control_get_extra_data(request, "_APP_ID_", &app_id);
+
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
+ g_free(mode);
+ return 0;
+ }
+
+ g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_DATA_USAGE_WARNING);
+
+ log_print(NET_POPUP, "alert warn threshold crossed [%s]\n", app_id);
+ g_free(app_id);
} else if (strcmp(mode, "security restriction") == 0) {
ret = app_control_get_extra_data(request, "_RESTRICTED_TYPE_", &restricted_type);
if (APP_CONTROL_ERROR_NONE != ret) {
@@ -673,6 +759,24 @@ static int __net_popup_show_notification(app_control_h request, void *data)
log_print(NET_POPUP, "alert wifi connected\n");
g_free(ap_name);
+ } else if (strcmp(mode, "warn threshold crossed") == 0) {
+ char buf[ALERT_STR_LEN_MAX] = "";
+ char *app_id = NULL;
+
+ ret = app_control_get_extra_data(request, "_APP_ID_", &app_id);
+
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
+ g_free(mode);
+ return 0;
+ }
+
+ g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_DATA_USAGE_WARNING);
+
+ notification_status_message_post(buf);
+
+ log_print(NET_POPUP, "alert warn threshold crossed [%s]\n", app_id);
+ g_free(app_id);
} else {
notification_status_message_post(mode);
log_print(NET_POPUP, "%s\n", mode);
@@ -1094,6 +1198,161 @@ void _btn_no_cb(void *data, Evas_Object *obj, void *event_info)
elm_exit();
}
+static void __data_usage_notification(notification_type_e type,
+ notification_ly_type_e ly_type, const char *title_text, const char *title_key,
+ const char *content_text, const char *content_key, const char *launch_appid)
+{
+ int ret = 0;
+ int noti_flags = 0;
+ char icon_path[ICON_PATH_LEN];
+ notification_h noti = NULL;
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+ app_control_h service_handle = NULL;
+
+ noti = notification_create(type);
+ if (noti == NULL) {
+ log_print(NET_POPUP, "Failed to create notification");
+ return;
+ }
+
+ noti_err = notification_set_time(noti, time(NULL));
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to notification_set_time : %d", noti_err);
+ goto error;
+ }
+
+ g_snprintf(icon_path, sizeof(icon_path), "%s%s",
+ STC_NOTI_DATA_USAGE_ICON_PATH, STC_NOTI_DATA_USAGE_ICON_NAME);
+ noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to notification_set_image : %d", noti_err);
+ goto error;
+ }
+
+ noti_err = notification_set_layout(noti, ly_type);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to notification_set_layout : %d", noti_err);
+ goto error;
+ }
+
+ noti_err = notification_set_text_domain(noti, PACKAGE,
+ LOCALEDIR);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to notification_set_text_domain : %d", noti_err);
+ goto error;
+ }
+
+ noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
+ title_text, title_key,
+ NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to notification_set_title : %d", noti_err);
+ goto error;
+ }
+
+ if (content_text) {
+ noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
+ content_text, content_key,
+ NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to notification_set_content: %d", noti_err);
+ goto error;
+ }
+ }
+
+ noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |
+ NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
+ noti_err = notification_set_display_applist(noti, noti_flags);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to notification_set_display_applist: %d", noti_err);
+ goto error;
+ }
+
+ if (launch_appid) {
+ ret = app_control_create(&service_handle);
+ log_print(NET_POPUP, "Service create ret[%d]", ret);
+ if (ret != APP_CONTROL_ERROR_NONE)
+ goto error;
+
+ ret = app_control_set_app_id(service_handle, launch_appid);
+ log_print(NET_POPUP, "Service set app id ret = %d", ret);
+ if (ret != APP_CONTROL_ERROR_NONE)
+ goto error;
+
+ ret = app_control_add_extra_data(service_handle, "caller", "notification");
+ log_print(NET_POPUP, "Service data addition ret = %d", ret);
+ if (ret != APP_CONTROL_ERROR_NONE)
+ goto error;
+
+ noti_err = notification_set_launch_option(noti,
+ NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to notification_set_launch_option");
+ goto error;
+ }
+ }
+
+ noti_err = notification_post(noti);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ log_print(NET_POPUP, "Failed to insert notification[error# is %d]", noti_err);
+ goto error;
+ }
+
+ log_print(NET_POPUP, "Successfully added notification");
+
+error:
+
+ if (noti != NULL)
+ notification_free(noti);
+}
+
+static void __data_usage_btn_on_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ log_print(NET_POPUP, "__data_usage_btn_on_cb()");
+ Evas_Object *popup = (Evas_Object *)data;
+
+ __net_popup_init_dbus();
+ __net_popup_send_data_usage_msg(data_usage_app_id, data_usage_iftype);
+ __net_popup_deinit_dbus();
+
+ __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
+ NOTIFICATION_LY_ONGOING_EVENT,
+ STC_NOTIFICATION_RESTRICTION_ON_TITLE,
+ "IDS_SM_TMBODY_MOBILE_DATA_LIMIT_EXCEEDED_ABB",
+ NULL, NULL, NULL);
+
+ if (popup)
+ evas_object_del(popup);
+ if (obj)
+ evas_object_del(obj);
+
+ g_free(data_usage_app_id);
+ g_free(data_usage_iftype);
+
+ elm_exit();
+}
+
+static void __data_usage_btn_ok_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ log_print(NET_POPUP, "__data_usage_btn_ok_cb()");
+ Evas_Object *popup = (Evas_Object *)data;
+
+ __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
+ NOTIFICATION_LY_ONGOING_EVENT,
+ STC_NOTIFICATION_RESTRICTION_OK_TITLE,
+ "IDS_SM_HEADER_MOBILE_DATA_TURNED_OFF_ABB2",
+ STC_NOTIFICATION_RESTRICTION_OK_CONTENT,
+ "IDS_SM_SBODY_TAP_HERE_TO_TURN_IT_ON_AGAIN_ABB",
+ DATA_USAGE_APPID);
+
+ if (popup)
+ evas_object_del(popup);
+ if (obj)
+ evas_object_del(obj);
+
+ elm_exit();
+}
+
static void __net_popup_show_popup_with_user_resp(app_control_h request,
void *data)
{
@@ -1247,6 +1506,92 @@ static void __net_popup_show_vpn_popup(app_control_h request, void *data)
return;
}
+static void __net_popup_show_warning_noti(void)
+{
+ log_print(NET_POPUP, "__net_popup_show_warning_noti()\n");
+
+ __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
+ NOTIFICATION_LY_ONGOING_EVENT,
+ STC_NOTIFICATION_WARNING_TITLE,
+ "IDS_COM_BODY_DATA_USAGE_WARNING",
+ STC_NOTIFICATION_WARNING_CONTENT,
+ "IDS_SM_SBODY_TAP_HERE_TO_VIEW_YOUR_DATA_USAGE_ABB",
+ DATA_USAGE_APPID);
+}
+
+static void __net_popup_show_restriction_noti(app_control_h request, void *data)
+{
+ Evas_Object *win;
+ Evas_Object *popup;
+ Evas_Object *button1;
+ Evas_Object *button2;
+ char *title = NULL;
+ char *content = NULL;
+ char *limit = NULL;
+ char *on_btn = NULL;
+ char *ok_btn = NULL;
+ char buf[ALERT_STR_LEN_MAX] = "";
+
+ log_print(NET_POPUP, "__net_popup_show_data_usage_popup");
+
+ int ret = app_control_get_extra_data(request, "_APP_ID_", &data_usage_app_id);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
+ elm_exit();
+ return;
+ }
+
+ ret = app_control_get_extra_data(request, "_IF_TYPE_", &data_usage_iftype);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ log_print(NET_POPUP, "Failed to get _IF_TYPE_ ret = %d", ret);
+ elm_exit();
+ return;
+ }
+
+ ret = app_control_get_extra_data(request, "_RESTRICTION_LIMIT_", &limit);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ log_print(NET_POPUP, "Failed to get _RESTRICTION_LIMIT_ ret = %d", ret);
+ elm_exit();
+ return;
+ }
+
+ title = ALERT_STR_DATA_USAGE_TITLE;
+ g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_DATA_USAGE_CONTENT, limit);
+ content = buf;
+ on_btn = ALERT_STR_DATA_USAGE_TURN_ON_BUTTON;
+ ok_btn = ALERT_STR_OK;
+
+ log_print(NET_POPUP, "title(%s) content(%s) app_id(%s) iftype(%s) limit(%s)",
+ title, content, data_usage_app_id, data_usage_iftype, limit);
+
+ win = __net_popup_create_win();
+
+ popup = elm_popup_add(win);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ elm_object_text_set(popup, content);
+ elm_object_part_text_set(popup, "title,text", title);
+
+ /* ON button */
+ button1 = elm_button_add(popup);
+ elm_object_style_set(button1, "bottom");
+ elm_object_text_set(button1, on_btn);
+ elm_object_part_content_set(popup, "button1", button1);
+ evas_object_smart_callback_add(button1, "clicked", __data_usage_btn_on_cb, popup);
+
+ /* OK button */
+ button2 = elm_button_add(popup);
+ elm_object_style_set(button2, "bottom");
+ elm_object_text_set(button2, ok_btn);
+ elm_object_part_content_set(popup, "button2", button2);
+ evas_object_smart_callback_add(button2, "clicked", __data_usage_btn_ok_cb, popup);
+
+ evas_object_show(popup);
+ evas_object_show(win);
+
+ return;
+}
+
static int __net_popup_show_popup(app_control_h request, void *data)
{
log_print(NET_POPUP, "__net_popup_show_popup()\n");