Added new vconf key for VCONFKEY_SETAPPL_DATA_RESTRICTION_INT 23/187323/1
authorhyunuktak <hyunuk.tak@samsung.com>
Wed, 22 Aug 2018 05:07:57 +0000 (14:07 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Wed, 22 Aug 2018 05:08:01 +0000 (14:08 +0900)
Change-Id: I1d869718893ada6c6b2b6ff979b1460672b34524
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
src/monitor/include/stc-monitor.h [changed mode: 0644->0755]
src/monitor/stc-monitor.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 3414c06..0977eba
@@ -40,6 +40,11 @@ typedef enum {
        STC_RSTN_LIMIT_TYPE_MAX
 } stc_rstn_limit_type_e;
 
+typedef enum {
+       STC_RSTN_STATE_INIT = -1,
+       STC_RSTN_STATE_UNSET,
+       STC_RSTN_STATE_SET,
+} stc_rstn_noti_state_e;
 
 /**
  * @brief key for processes tree
old mode 100644 (file)
new mode 100755 (executable)
index 2a42682..694bf5c
 
 #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;
@@ -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:
@@ -934,6 +987,8 @@ 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:
@@ -1864,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;;