First check the index size of signal map
[platform/core/connectivity/stc-manager.git] / plugin / appstatus / stc-plugin-appstatus.c
index d9764b4..ced6be6 100755 (executable)
@@ -87,9 +87,9 @@ static void __stc_gdbus_handle_aul_changestate(GDBusConnection *connection,
        else
                apptype = STC_APP_TYPE_GUI;
 
-       if (STC_DEBUG_LOG) {
-               STC_LOGD("\033[1;36mAPP STATUS\033[0;m: Pkg ID [\033[0;34m%s\033[0;m], "
-                       "App ID [\033[0;32m%s\033[0;m], PID [\033[1;33m%d\033[0;m], Status [%s], Type [%s]",
+       if (STC_STAT_LOG) {
+               STC_LOGD("\033[1;34mAPP STATUS\033[0;m: PkgID[\033[0;34m%s\033[0;m] "
+                       "AppID[\033[0;32m%s\033[0;m] PID[\033[1;33m%d\033[0;m] Status[%s] Type[%s]",
                        pkgid, appid, pid, statstr, pkgtype);
        }
 
@@ -127,10 +127,13 @@ signal_map_s signal_map[] = {
 static stc_error_e __ground_status_monitor_init(stc_s *stc)
 {
        guint i = 0;
+       guint size = 0;
 
        ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
 
-       for (i = 0; signal_map[i].member != NULL; i++) {
+       size = sizeof(signal_map) / sizeof(signal_map[0]);
+
+       for (i = 0; i < size && signal_map[i].member != NULL; i++) {
                signal_map[i].sub_id =
                        g_dbus_connection_signal_subscribe(stc->connection,
                                                           NULL,
@@ -152,10 +155,13 @@ static stc_error_e __ground_status_monitor_init(stc_s *stc)
 static stc_error_e __ground_status_monitor_deinit(stc_s *stc)
 {
        guint i = 0;
+       guint size = 0;
 
        ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
 
-       for (i = 0; signal_map[i].member != NULL; i++) {
+       size = sizeof(signal_map) / sizeof(signal_map[0]);
+
+       for (i = 0; i < size && signal_map[i].member != NULL; i++) {
                g_dbus_connection_signal_unsubscribe(stc->connection,
                                                     signal_map[i].sub_id);
                signal_map[i].sub_id = 0;
@@ -183,42 +189,26 @@ int stc_plugin_appstatus_deregister_changed_cb(stc_s *stc)
        return 0;
 }
 
-int stc_plugin_popup_send_warn_message(const char *content,
-               const char *type, const char *app_id, const char *iftype, const char *warn)
-{
-       int ret = 0;
-       bundle *b = bundle_create();
-
-       STC_LOGD("Warn message : content[%s] type[%s] app_id[%s] warn[%s]",
-               content, type, app_id, warn);
-
-       bundle_add(b, "_SYSPOPUP_CONTENT_", content);
-       bundle_add(b, "_SYSPOPUP_TYPE_", type);
-       bundle_add(b, "_APP_ID_", app_id);
-       bundle_add(b, "_IF_TYPE_", iftype);
-       bundle_add(b, "_WARN_LIMIT_", warn);
-
-       ret = syspopup_launch("net-popup", b);
-
-       bundle_free(b);
-
-       return ret;
-}
-
-int stc_plugin_popup_send_restriction_message(const char *content,
+int stc_plugin_popup_send_message(const char *content,
                const char *type, const char *app_id, const char *iftype, const char *limit)
 {
        int ret = 0;
        bundle *b = bundle_create();
 
-       STC_LOGD("Restriction message : content[%s] type[%s] app_id[%s] limit[%s]",
-               content, type, app_id, limit);
-
        bundle_add(b, "_SYSPOPUP_CONTENT_", content);
        bundle_add(b, "_SYSPOPUP_TYPE_", type);
        bundle_add(b, "_APP_ID_", app_id);
        bundle_add(b, "_IF_TYPE_", iftype);
-       bundle_add(b, "_RESTRICTION_LIMIT_", limit);
+
+       if (g_strcmp0(type, "warning_noti") == 0) {
+               bundle_add(b, "_WARN_LIMIT_", limit);
+               STC_LOGD("Warn message : content[%s] type[%s] app_id[%s] limit[%s]",
+                       content, type, app_id, limit);
+       } else {
+               bundle_add(b, "_RESTRICTION_LIMIT_", limit);
+               STC_LOGD("Restriction message : content[%s] type[%s] app_id[%s] limit[%s]",
+                       content, type, app_id, limit);
+       }
 
        ret = syspopup_launch("net-popup", b);
 
@@ -228,10 +218,8 @@ int stc_plugin_popup_send_restriction_message(const char *content,
 }
 
 API stc_plugin_appstatus_s stc_plugin_appstatus = {
-       .send_warn_message_to_net_popup =
-               stc_plugin_popup_send_warn_message,
-       .send_restriction_message_to_net_popup =
-               stc_plugin_popup_send_restriction_message,
+       .send_message_to_net_popup =
+               stc_plugin_popup_send_message,
        .register_state_changed_cb =
                stc_plugin_appstatus_register_changed_cb,
        .deregister_state_changed_cb =