*/
#include <linux/netlink.h>
+#include <vconf.h>
+#include <vconf-keys.h>
#include "stc-default-connection.h"
#include "helper-nl.h"
#include "stc-manager-plugin.h"
#define MAX_INT_LENGTH 128
+#define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
typedef struct {
stc_app_key_s *app_key;
app_id);
}
-static void __stc_monitor_add_application_by_interface(const char *app_id)
+static void __add_application_by_interface(const char *app_id)
{
stc_app_key_s app_key;
stc_app_value_s app_value;
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;;
+}
+
+static void __set_background_state(guint state)
+{
+ g_system->background_state = state;
+}
+
+static gboolean __processes_tree_foreach_background(gpointer key, gpointer value,
+ gpointer data)
+{
+ stc_process_key_s *proc_key = (stc_process_key_s *)key;
+ stc_process_value_s *proc_value = (stc_process_value_s *)value;
+ stc_app_key_s *app_key = (stc_app_key_s *)data;
+
+ if (g_system->background_state)
+ place_pids_to_net_cgroup(proc_key->pid, STC_BACKGROUND_APP_ID);
+ else
+ place_pids_to_net_cgroup(proc_key->pid, app_key->app_id);
+
+ return FALSE;
+}
+
+static gboolean __apps_tree_foreach_background(gpointer key, gpointer value,
+ gpointer data)
+{
+ stc_app_key_s *app_key = (stc_app_key_s *)key;
+ stc_app_value_s *app_value = (stc_app_value_s *)value;
+
+ if (strstr(app_key->app_id, STC_BACKGROUND_APP_SUFFIX))
+ g_tree_foreach(app_value->processes, __processes_tree_foreach_background, app_key);
+
+ return FALSE;
+}
+
+static stc_error_e __process_update_background(void)
+{
+ ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
+
+ g_tree_foreach(g_system->apps, __apps_tree_foreach_background, NULL);
+
+ return STC_ERROR_NONE;
+}
+
stc_error_e stc_monitor_init(void)
{
stc_system_s *system = MALLOC0(stc_system_s, 1);
g_system = system;
- __stc_monitor_add_application_by_interface(STC_TOTAL_DATACALL);
- __stc_monitor_add_application_by_interface(STC_TOTAL_WIFI);
- __stc_monitor_add_application_by_interface(STC_TOTAL_BLUETOOTH);
+ __add_application_by_interface(STC_TOTAL_DATACALL);
+ __add_application_by_interface(STC_TOTAL_WIFI);
+ __add_application_by_interface(STC_TOTAL_BLUETOOTH);
/* creating restriction rules tree */
__update_contr_cb(NULL);
return STC_ERROR_FAIL;
}
+ __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE, &g_system->background_state);
+
__fill_restritions_list();
return STC_ERROR_NONE;
proc_lookup->ground = ground;
if (ground == STC_APP_STATE_BACKGROUND) {
- char *background_app_id = g_strconcat(app_key.app_id,
- STC_BACKGROUND_APP_SUFFIX,
- NULL);
- place_pids_to_net_cgroup(proc_key.pid, background_app_id);
- g_free(background_app_id);
+ if (__get_background_state()) {
+ place_pids_to_net_cgroup(proc_key.pid, STC_BACKGROUND_APP_ID);
+ } else {
+ char *background_app_id = g_strconcat(app_key.app_id,
+ STC_BACKGROUND_APP_SUFFIX, NULL);
+ place_pids_to_net_cgroup(proc_key.pid, background_app_id);
+ g_free(background_app_id);
+ }
} else {
place_pids_to_net_cgroup(proc_key.pid, app_key.app_id);
}
else
value.classid = STC_UNKNOWN_CLASSID;
+ if (value.classid == STC_BACKGROUND_APP_CLASSID) {
+ __set_background_state(TRUE);
+ __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state);
+ __process_update_background();
+ }
+
value.data_limit = info->data_limit;
value.data_warn_limit = info->data_warn_limit;
.roaming = info->roaming,
};
+ if (!strcmp(key.app_id, STC_BACKGROUND_APP_ID)) {
+ __set_background_state(FALSE);
+ __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state);
+ __process_update_background();
+ }
+
ret = __rstn_tree_remove(&key);
FREE(key.app_id);