Add new vconf key for managing data restriction 86/192886/1
authorhyunuktak <hyunuk.tak@samsung.com>
Mon, 12 Nov 2018 08:55:39 +0000 (17:55 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Mon, 12 Nov 2018 08:55:42 +0000 (17:55 +0900)
Change-Id: I87e4ad6e93f879ead02feaa7299b5bc794619c72
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
src/monitor/include/stc-monitor.h [changed mode: 0644->0755]
src/monitor/stc-monitor.c

old mode 100644 (file)
new mode 100755 (executable)
index 4316420..8e6b3ba
@@ -40,6 +40,12 @@ 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
  */
index f953db4..a6eff3a 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;
@@ -59,6 +66,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)
@@ -494,6 +529,22 @@ static void __print_rstn(stc_rstn_key_s *rstn_key, stc_rstn_value_s *rstn_value)
                 rstn_key->roaming, rstn_key->subscriber_id);
 }
 
+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;
@@ -702,6 +753,8 @@ static void __process_restriction(enum traffic_restriction_type rst_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:
@@ -880,6 +933,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:
@@ -1745,32 +1800,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);
-               return -1;
-       }
-
-       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);
-               return -1;
-       }
-
-       return 0;
-}
-
 static guint __get_background_state(void)
 {
        return g_system->background_state;;