Added new vconf key for VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
[platform/core/connectivity/stc-manager.git] / src / monitor / stc-monitor.c
index 5885fc9..694bf5c 100755 (executable)
 
 #define GRANULARITY 10
 #define MAX_INT_LENGTH 128
+
+#ifndef VCONFKEY_STC_BACKGROUND_STATE
 #define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
+#endif
+
+#ifndef VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
+#define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction"
+#endif
 
 typedef struct {
        time_t now;
@@ -58,6 +65,34 @@ typedef struct {
 
 static stc_system_s *g_system = NULL;
 
+//LCOV_EXCL_START
+static int __vconf_get_int(const char *key, int *value)
+{
+       int ret = 0;
+
+       ret = vconf_get_int(key, value);
+       if (ret != VCONF_OK) {
+               STC_LOGE("Failed to get vconfkey [%s] value", key); //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
+       }
+
+       return 0;
+}
+
+static int __vconf_set_int(const char *key, int value)
+{
+       int ret = 0;
+
+       ret = vconf_set_int(key, value);
+       if (ret != VCONF_OK) {
+               STC_LOGE("Failed to set vconfkey [%s] value", key); //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
+       }
+
+       return 0;
+}
+//LCOV_EXCL_STOP
+
 static nfacct_rule_jump __get_jump_by_intend(struct nfacct_rule *counter)
 {
        if (counter->intend == NFACCT_WARN)
@@ -608,6 +643,22 @@ static void __del_iptables_rule(int64_t classid, nfacct_rule_intend intend,
        __del_ip6tables_out(&counter);
 }
 
+static void __set_rstn_noti_state(int value)
+{
+       int state = STC_RSTN_STATE_INIT;
+
+       if (__vconf_get_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, &state))
+               return;
+
+       if (state == value) {
+               STC_LOGI("No need to change a restriction status: %d", state);
+               return;
+       }
+
+       vconf_set_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, value);
+       return;
+}
+
 typedef struct {
        time_t month_start_ts;
        time_t week_start_ts;
@@ -689,7 +740,7 @@ static void __process_restriction(enum traffic_restriction_type rstn_type,
                        memset(&stat, 0, sizeof(cumulative_data_s));
                        stat.month_start_ts = rstn_value->month_start_ts;
                        stat.week_start_ts = g_system->last_week_ts;
-                       stat.week_start_ts = g_system->last_day_ts;
+                       stat.day_start_ts = g_system->last_day_ts;
 
                        memset(&rule, 0, sizeof(table_statistics_select_rule));
                        rule.from = rstn_value->month_start_ts;
@@ -753,6 +804,8 @@ static void __process_restriction(enum traffic_restriction_type rstn_type,
                for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++)
                        if (rstn_value->limit[i] >= 0)
                                rstn_value->counter[i] = 0;
+
+               __set_rstn_noti_state(STC_RSTN_STATE_UNSET);
        }
        break;
        default:
@@ -891,11 +944,11 @@ static void __action_when_rstn_limit_exceeded(stc_rstn_limit_type_e limit_type,
                                                classid_bytes_context_s *context)
 {
        gboolean rv;
-       char iftype[MAX_INT_LENGTH];
-       char byte[MAX_INT_LENGTH];
-       const char *signal_name;
-       const char *net_popup_content;
-       const char *net_popup_type;
+       char iftype[MAX_INT_LENGTH] = { 0, };
+       char byte[MAX_INT_LENGTH] = { 0, };
+       const char *signal_name = NULL;
+       const char *net_popup_content = NULL;
+       const char *net_popup_type = NULL;
        stc_s *stc = (stc_s *)stc_get_manager();
 
        if (stc == NULL) {
@@ -934,12 +987,19 @@ static void __action_when_rstn_limit_exceeded(stc_rstn_limit_type_e limit_type,
                context->counter->intend = NFACCT_COUNTER;
 
                rstn_value->limit_exceeded |= (1 << limit_type);
+
+               __set_rstn_noti_state(STC_RSTN_STATE_SET);
        }
        break;
        default:
                break;
        }
 
+       if (signal_name == NULL) {
+               STC_LOGE("Invalid parameter: limit_type");
+               return;
+       }
+
        /* emit signal */
        rv = stc_manager_dbus_emit_signal(stc->connection,
                                                  STC_DBUS_SERVICE_RESTRICTION_PATH,
@@ -1859,33 +1919,6 @@ static void __add_application_by_interface(const char *app_id)
        FREE(app_key.app_id);
 }
 
-static int __vconf_get_int(const char *key, int *value)
-{
-       int ret = 0;
-
-       ret = vconf_get_int(key, value);
-       if (ret != VCONF_OK) {
-               STC_LOGE("Failed to get vconfkey [%s] value", key); //LCOV_EXCL_LINE
-               return -1; //LCOV_EXCL_LINE
-       }
-
-       return 0;
-}
-
-//LCOV_EXCL_START
-static int __vconf_set_int(const char *key, int value)
-{
-       int ret = 0;
-
-       ret = vconf_set_int(key, value);
-       if (ret != VCONF_OK) {
-               STC_LOGE("Failed to set vconfkey [%s] value", key); //LCOV_EXCL_LINE
-               return -1; //LCOV_EXCL_LINE
-       }
-
-       return 0;
-}
-
 static guint __get_background_state(void)
 {
        return g_system->background_state;;