2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <linux/netlink.h>
19 #include <vconf-keys.h>
21 #include "stc-default-connection.h"
22 #include "helper-nl.h"
23 #include "helper-nfacct-rule.h"
24 #include "helper-net-cls.h"
25 #include "helper-cgroup.h"
27 #include "table-statistics.h"
28 #include "table-counters.h"
29 #include "stc-monitor.h"
30 #include "stc-manager-plugin.h"
32 #define MAX_INT_LENGTH 128
33 #define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
36 stc_app_key_s *app_key;
37 stc_process_key_s *proc_key;
38 gboolean entry_removed;
39 } remove_pid_context_s;
42 struct nfacct_rule *counter;
44 gboolean data_limit_reached;
45 } classid_bytes_context_s;
47 static stc_system_s *g_system = NULL;
49 static nfacct_rule_jump __get_jump_by_intend(struct nfacct_rule *counter)
51 if (counter->intend == NFACCT_WARN)
52 return NFACCT_JUMP_ACCEPT;
53 else if (counter->intend == NFACCT_BLOCK)
54 return NFACCT_JUMP_REJECT;
56 return NFACCT_JUMP_UNKNOWN;
59 static stc_error_e __add_iptables_in(struct nfacct_rule *counter)
61 return produce_net_rule(counter, 0, 0,
62 NFACCT_ACTION_INSERT, __get_jump_by_intend(counter),
66 static stc_error_e __add_iptables_out(struct nfacct_rule *counter)
68 return produce_net_rule(counter, 0, 0,
69 NFACCT_ACTION_INSERT, __get_jump_by_intend(counter),
73 static stc_error_e __del_iptables_in(struct nfacct_rule *counter)
75 return produce_net_rule(counter, 0, 0,
76 NFACCT_ACTION_DELETE, __get_jump_by_intend(counter),
80 static stc_error_e __del_iptables_out(struct nfacct_rule *counter)
82 return produce_net_rule(counter, 0, 0,
83 NFACCT_ACTION_DELETE, __get_jump_by_intend(counter),
87 static int __processes_tree_key_compare(gconstpointer a, gconstpointer b,
88 gpointer UNUSED user_data)
90 stc_process_key_s *key_a = (stc_process_key_s *)a;
91 stc_process_key_s *key_b = (stc_process_key_s *)b;
93 return key_a->pid - key_b->pid;
96 static void __processes_tree_value_free(gpointer data)
98 stc_process_value_s *value = (stc_process_value_s *)data;
103 static void __processes_tree_key_free(gpointer data)
105 stc_process_key_s *key = (stc_process_key_s *)data;
110 static int __apps_tree_key_compare(gconstpointer a, gconstpointer b,
111 gpointer UNUSED user_data)
113 stc_app_key_s *key_a = (stc_app_key_s *)a;
114 stc_app_key_s *key_b = (stc_app_key_s *)b;
117 ret = g_strcmp0(key_a->pkg_id, key_b->pkg_id);
121 return g_strcmp0(key_a->app_id, key_b->app_id);
124 static void __apps_tree_value_free(gpointer data)
126 stc_app_value_s *value = (stc_app_value_s *)data;
128 g_tree_destroy(value->processes);
129 value->processes = NULL;
134 static void __apps_tree_key_free(gpointer data)
136 stc_app_key_s *key = (stc_app_key_s *)data;
143 static int __rstns_tree_key_compare(gconstpointer a, gconstpointer b,
144 gpointer UNUSED user_data)
146 stc_rstn_key_s *key_a = (stc_rstn_key_s *)a;
147 stc_rstn_key_s *key_b = (stc_rstn_key_s *)b;
150 ret = g_strcmp0(key_a->app_id, key_b->app_id);
154 ret = g_strcmp0(key_a->ifname, key_b->ifname);
158 ret = g_strcmp0(key_a->imsi, key_b->imsi);
162 ret = key_a->iftype - key_b->iftype;
169 static void __rstns_tree_value_free(gpointer data)
171 stc_rstn_value_s *value = (stc_rstn_value_s *)data;
176 static void __rstns_tree_key_free(gpointer data)
178 stc_rstn_key_s *key = (stc_rstn_key_s *)data;
186 static gboolean __processes_tree_foreach_print(gpointer key, gpointer value,
189 stc_process_key_s *proc_key = (stc_process_key_s *)key;
190 stc_process_value_s *proc_value = (stc_process_value_s *)value;
192 STC_LOGD("Process entry => PID [%d], Ground state [%d]",
193 proc_key->pid, proc_value->ground);
197 static void __processes_tree_printall(GTree *processes)
199 g_tree_foreach(processes, __processes_tree_foreach_print, NULL);
202 static gboolean __apps_tree_foreach_print(gpointer key, gpointer value,
205 stc_app_key_s *app_key = (stc_app_key_s *)key;
206 stc_app_value_s *app_value = (stc_app_value_s *)value;
208 STC_LOGD("Application info => Pkg ID [%s], App ID [%s],"
209 " Type [%d], classid [%d],"
210 " counter [ in (%lld), out (%lld)]",
211 app_key->pkg_id, app_key->app_id,
212 app_value->type, app_value->classid,
213 app_value->data_usage.in_bytes, app_value->data_usage.out_bytes);
215 __processes_tree_printall(app_value->processes);
220 static void __apps_tree_printall(void)
222 g_tree_foreach(g_system->apps, __apps_tree_foreach_print, NULL);
226 static gboolean __apps_tree_foreach_remove_pid(gpointer key, gpointer value,
229 remove_pid_context_s *context = (remove_pid_context_s *)data;
230 stc_app_value_s *app_value = (stc_app_value_s *)value;
232 if (!g_tree_remove(app_value->processes, context->proc_key)) {
233 STC_LOGD("key not found");
237 context->entry_removed = TRUE;
238 context->app_key = (stc_app_key_s *)key;
243 static stc_app_value_s * __application_lookup(GTree *apps,
244 const stc_app_key_s *key)
246 stc_app_value_s *lookup;
248 ret_value_msg_if(apps == NULL, NULL, "apps is null!");
250 lookup = g_tree_lookup(apps, key);
255 static stc_process_value_s * __process_lookup(GTree *processes,
256 const stc_process_key_s *key)
258 stc_process_value_s *lookup;
260 ret_value_msg_if(processes == NULL, NULL, "processes is null!");
262 lookup = g_tree_lookup(processes, key);
267 static gboolean __processes_tree_check_empty(gpointer key, gpointer value,
270 guint *pid_count = (guint *)data;
275 static gboolean __add_application_monitor(gpointer key, gpointer value,
278 stc_app_value_s *app_value = (stc_app_value_s *)value;
279 default_connection_s *connection = (default_connection_s *)data;
280 stc_s *stc = stc_get_manager();
282 if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
283 app_value->classid == STC_TOTAL_WIFI_CLASSID ||
284 app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
287 if (stc && connection && connection->ifname) {
288 struct nfacct_rule counter;
291 stc->carg = MALLOC0(counter_arg_s, 1);
292 if (stc->carg == NULL)
295 stc->carg->sock = stc_monitor_get_counter_socket();
298 memset(&counter, 0, sizeof(struct nfacct_rule));
300 counter.carg = stc->carg;
301 counter.classid = app_value->classid;
302 counter.intend = NFACCT_COUNTER;
303 counter.iftype = connection->type;
304 g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
306 __add_iptables_in(&counter);
307 __add_iptables_out(&counter);
313 static gboolean __remove_application_monitor(gpointer key, gpointer value,
316 stc_app_value_s *app_value = (stc_app_value_s *)value;
317 default_connection_s *connection = (default_connection_s *)data;
318 stc_s *stc = stc_get_manager();
320 if (stc && connection && connection->ifname) {
321 struct nfacct_rule counter;
324 stc->carg = MALLOC0(counter_arg_s, 1);
325 if (stc->carg == NULL)
328 stc->carg->sock = stc_monitor_get_counter_socket();
331 memset(&counter, 0, sizeof(struct nfacct_rule));
333 counter.carg = stc->carg;
334 counter.classid = app_value->classid;
335 counter.intend = NFACCT_COUNTER;
336 counter.iftype = connection->type;
337 g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
339 __del_iptables_in(&counter);
340 __del_iptables_out(&counter);
346 static void __print_rstn(stc_rstn_key_s *rstn_key, stc_rstn_value_s *rstn_value)
348 STC_LOGI("rstn info => rstn_id [%llu], "
349 "app_id [%s], classid [%lu], ifname [%s], "
350 "iftype [%d], rst_state [%d], "
351 "limit [ (%lld) bytes], "
352 "warn_limit [ (%lld) bytes], "
353 "counter [ (%lld) bytes], "
354 "roaming [%d], imsi [%s]",
355 rstn_value->restriction_id,
356 rstn_key->app_id, rstn_value->classid , rstn_key->ifname,
357 rstn_key->iftype, rstn_value->rst_state,
358 rstn_value->data_limit,
359 rstn_value->data_warn_limit,
360 rstn_value->data_counter,
361 rstn_key->roaming, rstn_key->imsi);
364 static void __process_restriction(enum traffic_restriction_type rst_type,
365 stc_rstn_key_s *rstn_key,
366 stc_rstn_value_s *rstn_value, void *data)
368 int64_t effective_data_limit, effective_data_warn_limit;
369 default_connection_s *old_connection = (default_connection_s *)data;
370 default_connection_s *connection = NULL;
372 if (old_connection != NULL)
373 connection = old_connection;
375 connection = stc_get_default_connection();
377 /* no default ifname */
378 if (connection->ifname == NULL)
381 /* rstn not applicable for this interface */
382 if (rstn_key->ifname != NULL && g_strcmp0("", rstn_key->ifname) != 0 &&
383 g_strcmp0(connection->ifname, rstn_key->ifname) != 0)
386 /* classid is invalid */
387 if (rstn_value->classid == STC_UNKNOWN_CLASSID)
390 effective_data_limit = rstn_value->data_limit;
391 effective_data_warn_limit = rstn_value->data_warn_limit;
393 if (rst_type == RST_SET) {
394 /* TODO: Change this to runtime memory */
395 table_counters_info info;
397 memset(&info, 0, sizeof(table_counters_info));
398 table_counters_get(rstn_value->restriction_id, &info);
400 effective_data_limit -= info.data_counter;
401 effective_data_warn_limit -= info.data_counter;
403 if (effective_data_limit < 0) {
404 effective_data_limit = 0;
405 rstn_value->data_limit_reached = TRUE;
408 if (effective_data_warn_limit < 0)
409 effective_data_warn_limit = 0;
411 STC_LOGD("datausage [%lld] bytes", info.data_counter);
414 STC_LOGD("rstn_id [%llu], effective_data_limit [%lld] bytes, "
415 "effective_data_warn_limit [%lld] bytes",
416 rstn_value->restriction_id, effective_data_limit,
417 effective_data_warn_limit);
421 if (effective_data_limit <= 0) {
422 char *default_ifname = stc_default_connection_get_ifname();
423 struct nfacct_rule counter;
424 stc_s *stc = stc_get_manager();
427 stc->carg = MALLOC0(counter_arg_s, 1);
428 if (stc->carg == NULL) {
429 g_free(default_ifname);
434 stc_monitor_get_counter_socket();
437 counter.carg = stc->carg;
438 counter.classid = rstn_value->classid;
439 counter.intend = NFACCT_BLOCK;
440 counter.iftype = rstn_key->iftype;
441 g_strlcpy(counter.ifname, default_ifname,
444 generate_counter_name(&counter);
445 g_free(default_ifname);
448 __add_iptables_in(&counter);
449 __add_iptables_out(&counter);
452 rstn_value->rst_state = STC_RESTRICTION_ACTIVATED;
453 rstn_value->data_limit_reached = FALSE;
460 char *default_ifname = stc_default_connection_get_ifname();
461 struct nfacct_rule counter;
462 stc_s *stc = stc_get_manager();
465 stc->carg = MALLOC0(counter_arg_s, 1);
466 if (stc->carg == NULL) {
467 g_free(default_ifname);
472 stc_monitor_get_counter_socket();
475 counter.carg = stc->carg;
476 counter.classid = rstn_value->classid;
477 counter.intend = NFACCT_BLOCK;
478 counter.iftype = rstn_key->iftype;
479 g_strlcpy(counter.ifname, default_ifname,
482 generate_counter_name(&counter);
483 g_free(default_ifname);
486 __del_iptables_in(&counter);
487 __del_iptables_out(&counter);
489 rstn_value->rst_state = STC_RESTRICTION_REMOVED;
490 rstn_value->data_limit_reached = FALSE;
498 static gboolean __remove_rstns_foreach_application(gpointer key,
502 stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
503 stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
504 gchar *app_id = (gchar *)data;
506 /* rstn rule is not for applications */
507 if (rstn_key->app_id == NULL)
510 /* rstn rule is not for this application */
511 if (g_strcmp0(rstn_key->app_id, app_id) != 0)
514 /* rstn rule is already removed */
515 if (rstn_value->rst_state == STC_RESTRICTION_REMOVED)
518 /* remove restriction from system */
519 __process_restriction(RST_UNSET, rstn_key, rstn_value, data);
521 __print_rstn(rstn_key, rstn_value);
526 static void __remove_rstns_for_application(gchar *app_id)
528 g_tree_foreach(g_system->rstns, __remove_rstns_foreach_application,
532 static stc_error_e __application_remove_if_empty(const stc_app_key_s *app_key)
534 stc_error_e ret = STC_ERROR_NONE;
536 stc_app_value_s *lookup;
538 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
540 lookup = __application_lookup(g_system->apps, app_key);
542 STC_LOGE("app_key not found");
543 return STC_ERROR_NO_DATA;
546 g_tree_foreach(lookup->processes, __processes_tree_check_empty,
550 /* remove nfacct rule for this classid */
551 __remove_application_monitor((gpointer) app_key, lookup,
552 stc_get_default_connection());
553 __remove_rstns_for_application(app_key->app_id);
556 if (!g_tree_remove(g_system->apps, app_key)) {
557 ret = STC_ERROR_NO_DATA;
558 STC_LOGE("key not found");
564 static stc_error_e __close_contr_sock(stc_system_s *system)
566 ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
568 /* close netlink socket for updating kernel counters */
569 if (system->contr_sock != -1) {
570 close(system->contr_sock);
571 system->contr_sock = -1;
574 if (system->contr_gsource_id != 0) {
575 g_source_remove(system->contr_gsource_id);
576 system->contr_gsource_id = 0;
579 return STC_ERROR_NONE;
582 static gboolean __process_contr_reply(GIOChannel *source,
583 GIOCondition condition,
586 static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
588 GIOChannel *gio = NULL;
589 ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
591 /* close netlink socket for updating kernel counters */
592 if (system->contr_sock != -1) {
593 close(system->contr_sock);
594 system->contr_sock = -1;
597 if (system->contr_gsource_id != 0) {
598 g_source_remove(system->contr_gsource_id);
599 system->contr_gsource_id = 0;
602 /* create netlink socket for updating kernel counters */
603 system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
604 if (!(system->contr_sock)) {
605 STC_LOGE("failed to open socket");
607 return STC_ERROR_FAIL;
610 gio = g_io_channel_unix_new(system->contr_sock);
611 system->contr_gsource_id =
612 g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
613 (GIOFunc) __process_contr_reply,
615 g_io_channel_unref(gio);
617 return STC_ERROR_NONE;
620 static gboolean __rstn_counter_update(stc_rstn_key_s *rstn_key,
621 stc_rstn_value_s *rstn_value,
622 classid_bytes_context_s *context)
624 switch (context->counter->iotype) {
625 case NFACCT_COUNTER_IN:
626 case NFACCT_COUNTER_OUT:
627 rstn_value->data_counter += context->bytes;
629 if (rstn_value->data_counter >= rstn_value->data_warn_limit &&
630 rstn_value->warn_limit_crossed_notified == FALSE) {
633 char iftype[MAX_INT_LENGTH];
634 char byte[MAX_INT_LENGTH];
635 stc_s *stc = (stc_s *)stc_get_manager();
636 ret_value_msg_if(stc == NULL, FALSE, "failed to get stc data");
639 rv = stc_manager_dbus_emit_signal(stc->connection,
640 STC_DBUS_SERVICE_RESTRICTION_PATH,
641 STC_DBUS_INTERFACE_RESTRICTION,
642 "WarnThresholdCrossed",
643 g_variant_new("(si)", rstn_key->app_id, rstn_key->iftype));
645 rstn_value->warn_limit_crossed_notified = TRUE;
647 snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype);
648 snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->data_warn_limit);
649 stc_send_warn_message_to_net_popup("warn threshold crossed",
655 if (rstn_value->data_counter >= rstn_value->data_limit &&
656 rstn_value->rstn_limit_crossed_notified == FALSE) {
659 char iftype[MAX_INT_LENGTH];
660 char byte[MAX_INT_LENGTH];
661 stc_s *stc = (stc_s *)stc_get_manager();
662 ret_value_msg_if(stc == NULL, FALSE, "failed to get stc data");
664 /* block immediately */
665 context->counter->intend = NFACCT_BLOCK;
666 __del_iptables_in(context->counter);
667 __del_iptables_out(context->counter);
668 __add_iptables_in(context->counter);
669 __add_iptables_out(context->counter);
670 context->counter->intend = NFACCT_COUNTER;
672 rstn_value->data_limit_reached = TRUE;
675 rv = stc_manager_dbus_emit_signal(stc->connection,
676 STC_DBUS_SERVICE_RESTRICTION_PATH,
677 STC_DBUS_INTERFACE_RESTRICTION,
678 "RestrictionThresholdCrossed",
679 g_variant_new("(si)", rstn_key->app_id, rstn_key->iftype));
681 rstn_value->rstn_limit_crossed_notified = TRUE;
683 snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype);
684 snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->data_limit);
685 stc_send_restriction_message_to_net_popup("restriction threshold crossed",
686 "restriction_noti", rstn_key->app_id,
690 g_system->rstns_tree_updated = TRUE;
691 __print_rstn(rstn_key, rstn_value);
694 STC_LOGE("unknown iotype");
700 static gboolean __interface_rstn_counter_update(stc_rstn_key_s *rstn_key,
701 stc_rstn_value_s *rstn_value,
702 classid_bytes_context_s *context)
704 if ((rstn_value->classid == STC_TOTAL_DATACALL_CLASSID &&
705 context->counter->iftype == STC_IFACE_DATACALL) ||
706 (rstn_value->classid == STC_TOTAL_WIFI_CLASSID &&
707 context->counter->iftype == STC_IFACE_WIFI) ||
708 (rstn_value->classid == STC_TOTAL_BLUETOOTH_CLASSID &&
709 context->counter->iftype == STC_IFACE_BLUETOOTH)) {
710 context->counter->classid = rstn_value->classid;
711 return __rstn_counter_update(rstn_key, rstn_value, context);
717 static gboolean __rstn_counter_update_foreach_classid(gpointer key,
722 stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
723 stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
724 classid_bytes_context_s *context = (classid_bytes_context_s *)data;
727 if (context->counter->intend != NFACCT_COUNTER)
728 goto try_next_callback;
730 if (rstn_value->data_limit_reached == TRUE) {
731 context->data_limit_reached = TRUE;
732 goto try_next_callback;
735 classid = context->counter->classid;
736 rv = __interface_rstn_counter_update(rstn_key, rstn_value, context);
738 context->counter->classid = classid;
739 if (rstn_value->classid != context->counter->classid)
740 goto try_next_callback;
742 rv = __rstn_counter_update(rstn_key, rstn_value, context);
748 static gboolean __update_app_statistics(gpointer key, gpointer value,
751 stc_app_key_s *app_key = (stc_app_key_s *)key;
752 stc_app_value_s *app_value = (stc_app_value_s *)value;
753 time_t *touch_time = (time_t *)data;
754 stc_db_classid_iftype_key stat_key;
755 stc_db_app_stats stat;
756 default_connection_s *default_connection = stc_get_default_connection();
758 memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key));
759 memset(&stat, 0 , sizeof(stc_db_app_stats));
761 stat_key.classid = app_value->classid;
762 stat_key.iftype = default_connection->type;
764 if (STC_IFACE_DATACALL == stat_key.iftype)
765 stat_key.imsi = g_strdup(default_connection->imsi);
767 stat_key.imsi = g_strdup("noneimsi");
769 g_strlcpy(stat_key.ifname, default_connection->ifname,
772 stat.app_id = g_strdup(app_key->app_id);
773 stat.snd_count = app_value->counter.out_bytes;
774 stat.rcv_count = app_value->counter.in_bytes;
775 stat.is_roaming = default_connection->roaming;
776 stat.ground = STC_APP_STATE_UNKNOWN;
778 table_statistics_insert(&stat_key, &stat, *touch_time);
780 app_value->counter.out_bytes = 0;
781 app_value->counter.in_bytes = 0;
789 static gboolean __flush_apps_stats_to_database(gpointer user_data)
791 time_t current_time = time(0);
793 if (g_system->apps_tree_updated == FALSE)
794 return G_SOURCE_REMOVE;
796 g_system->apps_tree_updated = FALSE;
799 g_tree_foreach(g_system->apps,
800 __update_app_statistics,
803 STC_LOGI("Flushed app stats to database");
804 return G_SOURCE_REMOVE;
807 static gboolean __update_counter_statistics(gpointer key, gpointer value,
810 stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
811 table_counters_info info = {
812 .restriction_id = rstn_value->restriction_id,
813 .data_counter = rstn_value->data_counter
816 table_counters_update_counters(&info);
821 static gboolean __flush_rstns_counter_to_database(gpointer user_data)
823 time_t current_time = time(0);
825 if (g_system->rstns_tree_updated == FALSE)
826 return G_SOURCE_REMOVE;
828 g_system->rstns_tree_updated = FALSE;
831 g_tree_foreach(g_system->rstns,
832 __update_counter_statistics,
835 STC_LOGI("Flushed rstns counters to database");
836 return G_SOURCE_REMOVE;
839 static void __app_counter_update(stc_app_key_s *app_key,
840 stc_app_value_s *app_value,
841 classid_bytes_context_s *context)
843 switch (context->counter->iotype) {
844 case NFACCT_COUNTER_IN:
845 app_value->data_usage.in_bytes += context->bytes;
846 app_value->counter.in_bytes = context->bytes;
847 g_system->apps_tree_updated = TRUE;
849 __apps_tree_foreach_print(app_key, app_value, NULL);
851 case NFACCT_COUNTER_OUT:
852 app_value->data_usage.out_bytes += context->bytes;
853 app_value->counter.out_bytes = context->bytes;
854 g_system->apps_tree_updated = TRUE;
856 __apps_tree_foreach_print(app_key, app_value, NULL);
859 STC_LOGE("unknown iotype");
863 static void __interface_counter_update(stc_app_key_s *app_key,
864 stc_app_value_s *app_value,
865 classid_bytes_context_s *context)
867 if ((app_value->classid == STC_TOTAL_DATACALL_CLASSID &&
868 context->counter->iftype == STC_IFACE_DATACALL) ||
869 (app_value->classid == STC_TOTAL_WIFI_CLASSID &&
870 context->counter->iftype == STC_IFACE_WIFI) ||
871 (app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID &&
872 context->counter->iftype == STC_IFACE_BLUETOOTH))
873 __app_counter_update(app_key, app_value, context);
876 static gboolean __apps_counter_update_foreach_classid(gpointer key,
880 stc_app_key_s *app_key = (stc_app_key_s *)key;
881 stc_app_value_s *app_value = (stc_app_value_s *)value;
882 classid_bytes_context_s *context = (classid_bytes_context_s *)data;
884 if (context->counter->intend != NFACCT_COUNTER)
885 goto try_next_callback;
887 __interface_counter_update(app_key, app_value, context);
889 if (app_value->classid != context->counter->classid)
890 goto try_next_callback;
892 __app_counter_update(app_key, app_value, context);
898 static void __fill_nfacct_result(char *cnt_name, int64_t bytes,
899 struct counter_arg *carg)
901 struct nfacct_rule counter = {
908 classid_bytes_context_s context = {
911 .data_limit_reached = FALSE,
914 STC_LOGD("cnt_name %s", cnt_name);
916 if (!recreate_counter_by_name(cnt_name, &counter)) {
917 STC_LOGE("Can't parse counter name %s", cnt_name);
921 STC_LOGI("classid %lu, iftype %u, iotype %d, intend %d, ifname %s, bytes %lld",
922 context.counter->classid, context.counter->iftype,
923 context.counter->iotype, context.counter->intend,
924 context.counter->ifname, context.bytes);
927 g_tree_foreach(g_system->rstns,
928 __rstn_counter_update_foreach_classid,
932 g_tree_foreach(g_system->apps,
933 __apps_counter_update_foreach_classid,
937 static int __fill_counters(struct rtattr *attr_list[__NFACCT_MAX],
940 struct counter_arg *carg = user_data;
941 char *cnt_name = (char *)RTA_DATA(attr_list[NFACCT_NAME]);
942 if (carg->initiate) {
944 * TODO: this will be used when daemon starts to update existing
945 * counter data if present.
947 populate_counters(cnt_name, carg);
951 (int64_t *)RTA_DATA(attr_list[NFACCT_BYTES]);
952 int bytes = be64toh(*bytes_p);
954 ++carg->serialized_counters;
955 __fill_nfacct_result(cnt_name, bytes, carg);
962 static int __post_fill_counters(void *user_data)
964 struct counter_arg *carg = user_data;
972 static void __process_network_counter(struct genl *ans,
973 struct counter_arg *carg)
975 struct netlink_serialization_params ser_params = {
978 .eval_attr = __fill_counters,
979 .post_eval_attr = __post_fill_counters,
982 netlink_serialization_command *netlink =
983 netlink_create_command(&ser_params);
985 STC_LOGE("Can not create command");
989 netlink->deserialize_answer(&(netlink->params));
992 static gboolean __process_contr_reply(GIOChannel *source,
993 GIOCondition condition,
996 int sock = g_io_channel_unix_get_fd(source);
999 stc_s *stc = stc_get_manager();
1001 if ((condition & G_IO_ERR) ||
1002 (condition & G_IO_HUP) ||
1003 (condition & G_IO_NVAL)) {
1004 /* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
1006 STC_LOGE("Counter socket received G_IO event, closing socket."
1007 "G_IO_ERR [%d], G_IO_HUP [%d], G_IO_NVAL [%s]",
1008 (condition & G_IO_ERR), (condition & G_IO_HUP),
1009 (condition & G_IO_NVAL));
1010 __close_and_reopen_contr_sock(g_system);
1015 STC_LOGE("Can't get stc data");
1019 ret = read_netlink(sock,
1020 &ans, sizeof(struct genl));
1021 /* STC_LOGD("Counter data received ret [%d]", ret); */
1025 stc->carg->ans_len = ret;
1026 __process_network_counter(&ans, stc->carg);
1028 g_idle_add(__flush_apps_stats_to_database, NULL);
1029 g_idle_add(__flush_rstns_counter_to_database, NULL);
1034 static gboolean __update_contr_cb(void *user_data)
1036 /* Here we just sent command, answer we receive in another callback */
1037 stc_s *stc = stc_get_manager();
1038 ret_value_msg_if(stc == NULL, STC_ERROR_FAIL, "Can't get stc data");
1040 stc->carg = MALLOC0(counter_arg_s, 1);
1041 if (stc->carg == NULL)
1042 return TRUE; /* we need to continue the timer */
1044 stc->carg->sock = stc_monitor_get_counter_socket();
1047 /* STC_LOGD("Get all counters"); */
1048 nfacct_send_get_all(stc->carg);
1050 /* we need to continue the timer */
1054 static gboolean __rstn_tree_foreach_print(gpointer key, gpointer value,
1057 stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
1058 stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
1060 __print_rstn(rstn_key, rstn_value);
1064 static void __rstn_tree_printall(void)
1066 g_tree_foreach(g_system->rstns, __rstn_tree_foreach_print, NULL);
1069 static stc_rstn_value_s * __rstn_lookup(GTree *rstns_tree,
1070 const stc_rstn_key_s *key)
1072 stc_rstn_value_s *lookup;
1074 ret_value_msg_if(rstns_tree == NULL, NULL, "rstns_tree is null!");
1076 lookup = g_tree_lookup(rstns_tree, key);
1081 static gboolean __remove_restriction(gpointer key, gpointer value,
1084 stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
1085 stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
1087 /* rstn rule is already removed */
1088 if (rstn_value->rst_state == STC_RESTRICTION_REMOVED)
1091 __process_restriction(RST_UNSET, rstn_key, rstn_value, data);
1092 __print_rstn(rstn_key, rstn_value);
1096 static gboolean __add_restriction_debug(gpointer key, gpointer value,
1099 stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
1100 stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
1102 /* rstn rule is activated */
1103 if (rstn_value->rst_state == STC_RESTRICTION_ACTIVATED)
1106 if (rstn_value->rst_state == STC_RESTRICTION_EXCLUDED)
1107 __process_restriction(RST_EXCLUDE, rstn_key, rstn_value, data);
1109 __process_restriction(RST_SET, rstn_key, rstn_value, data);
1111 __print_rstn(rstn_key, rstn_value);
1116 static gboolean __add_restriction(gpointer key, gpointer value, gpointer data)
1118 stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
1119 stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
1121 /* rstn rule is activated */
1122 if (rstn_value->rst_state == STC_RESTRICTION_ACTIVATED)
1125 if (rstn_value->rst_state == STC_RESTRICTION_EXCLUDED)
1126 __process_restriction(RST_EXCLUDE, rstn_key, rstn_value, data);
1128 __process_restriction(RST_SET, rstn_key, rstn_value, data);
1133 static stc_error_e __rstn_tree_remove(stc_rstn_key_s *key)
1135 stc_rstn_value_s *lookup_value;
1137 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
1139 lookup_value = __rstn_lookup(g_system->rstns, key);
1140 if (!lookup_value) {
1141 STC_LOGE("key not found");
1142 return STC_ERROR_NO_DATA;
1145 __remove_restriction(key, lookup_value, NULL);
1147 /* remove counter also */
1148 table_counters_delete(lookup_value->restriction_id);
1150 if (!g_tree_remove(g_system->rstns, key)) {
1151 STC_LOGD("key not found");
1152 return STC_ERROR_NO_DATA;
1155 return STC_ERROR_NONE;
1158 static stc_error_e __rstn_tree_add(stc_rstn_key_s *key,
1159 stc_rstn_value_s *value, gboolean debug)
1161 stc_rstn_value_s *rstn_value;
1163 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
1165 rstn_value = __rstn_lookup(g_system->rstns, key);
1167 stc_rstn_key_s *rstn_key = MALLOC0(stc_rstn_key_s, 1);
1169 STC_LOGE("rstn_key allocation failed");
1170 return STC_ERROR_OUT_OF_MEMORY;
1173 rstn_value = MALLOC0(stc_rstn_value_s, 1);
1175 STC_LOGE("rstn_value allocation failed");
1177 return STC_ERROR_OUT_OF_MEMORY;
1180 rstn_key->app_id = g_strdup(key->app_id);
1181 rstn_key->ifname = g_strdup(key->ifname);
1182 rstn_key->imsi = g_strdup(key->imsi);
1183 rstn_key->iftype = key->iftype;
1184 rstn_key->roaming = key->roaming;
1186 g_tree_insert(g_system->rstns, rstn_key, rstn_value);
1189 rstn_value->restriction_id = value->restriction_id;
1190 rstn_value->rst_state = value->rst_state;
1191 rstn_value->classid = value->classid;
1192 rstn_value->data_limit = value->data_limit;
1193 rstn_value->data_warn_limit = value->data_warn_limit;
1194 rstn_value->data_counter = 0;
1195 rstn_value->warn_limit_crossed_notified = FALSE;
1196 rstn_value->rstn_limit_crossed_notified = FALSE;
1199 __add_restriction_debug(key, rstn_value, NULL);
1201 __add_restriction(key, rstn_value, NULL);
1203 return STC_ERROR_NONE;
1206 static stc_cb_ret_e __insert_restriction_cb(const table_restrictions_info *info,
1209 stc_cb_ret_e ret = STC_CONTINUE;
1212 stc_rstn_value_s value;
1214 memset(&key, 0, sizeof(stc_rstn_key_s));
1215 memset(&value, 0, sizeof(stc_rstn_value_s));
1217 key.app_id = g_strdup(info->app_id);
1218 key.ifname = g_strdup(info->ifname);
1219 key.imsi = g_strdup(info->imsi);
1220 key.iftype = info->iftype;
1221 key.roaming = info->roaming;
1223 value.rst_state = info->rst_state;
1224 value.restriction_id = info->restriction_id;
1226 if (value.rst_state != STC_RESTRICTION_EXCLUDED && info->app_id)
1227 value.classid = get_classid_by_app_id(info->app_id, TRUE);
1229 value.classid = STC_UNKNOWN_CLASSID;
1231 value.data_limit = info->data_limit;
1232 value.data_warn_limit = info->data_warn_limit;
1234 if (__rstn_tree_add(&key, &value, FALSE) != STC_ERROR_NONE)
1243 static void __fill_restritions_list(void)
1245 table_restrictions_foreach(__insert_restriction_cb, NULL);
1246 //__rstn_tree_printall();
1249 static gboolean __add_rstn_foreach_application(gpointer key,
1253 stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
1254 stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
1255 gchar *app_id = (gchar *)data;
1257 /* rstn rule is not for applications */
1258 if (rstn_key->app_id == NULL)
1261 /* rstn rule is not for this application */
1262 if (g_strcmp0(rstn_key->app_id, app_id) != 0)
1265 /* rstn rule is already applied */
1266 if (rstn_value->rst_state == STC_RESTRICTION_ACTIVATED)
1269 /* add restriction to system */
1270 if (rstn_value->rst_state == STC_RESTRICTION_EXCLUDED)
1271 __process_restriction(RST_EXCLUDE, rstn_key, rstn_value, data);
1273 __process_restriction(RST_SET, rstn_key, rstn_value, data);
1275 __print_rstn(rstn_key, rstn_value);
1280 static void __add_rstns_for_application(gchar *app_id)
1282 g_tree_foreach(g_system->rstns, __add_rstn_foreach_application,
1286 static void __add_application_by_interface(const char *app_id)
1288 stc_app_key_s app_key;
1289 stc_app_value_s app_value;
1294 memset(&app_key, 0, sizeof(stc_app_key_s));
1295 memset(&app_value, 0, sizeof(stc_app_value_s));
1297 app_key.pkg_id = g_strdup(app_id);
1298 app_key.app_id = g_strdup(app_id);
1300 app_value.type = STC_APP_TYPE_NONE;
1301 app_value.processes = NULL;
1302 app_value.counter.in_bytes = 0;
1303 app_value.counter.out_bytes = 0;
1305 stc_monitor_application_add(app_key, app_value);
1307 FREE(app_key.pkg_id);
1308 FREE(app_key.app_id);
1311 static int __vconf_get_int(const char *key, int *value)
1315 ret = vconf_get_int(key, value);
1316 if (ret != VCONF_OK) {
1317 STC_LOGE("Failed to get vconfkey [%s] value", key);
1324 static int __vconf_set_int(const char *key, int value)
1328 ret = vconf_set_int(key, value);
1329 if (ret != VCONF_OK) {
1330 STC_LOGE("Failed to set vconfkey [%s] value", key);
1337 static guint __get_background_state(void)
1339 return g_system->background_state;;
1342 static void __set_background_state(guint state)
1344 g_system->background_state = state;
1347 static gboolean __processes_tree_foreach_background(gpointer key,
1351 stc_process_key_s *proc_key = (stc_process_key_s *)key;
1352 stc_app_key_s *app_key = (stc_app_key_s *)data;
1354 if (g_system->background_state)
1355 place_pids_to_net_cgroup(proc_key->pid, STC_BACKGROUND_APP_ID);
1357 place_pids_to_net_cgroup(proc_key->pid, app_key->app_id);
1362 static gboolean __apps_tree_foreach_background(gpointer key, gpointer value,
1365 stc_app_key_s *app_key = (stc_app_key_s *)key;
1366 stc_app_value_s *app_value = (stc_app_value_s *)value;
1368 if (strstr(app_key->app_id, STC_BACKGROUND_APP_SUFFIX))
1369 g_tree_foreach(app_value->processes,
1370 __processes_tree_foreach_background, app_key);
1375 static stc_error_e __process_update_background(void)
1377 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
1379 g_tree_foreach(g_system->apps, __apps_tree_foreach_background, NULL);
1381 return STC_ERROR_NONE;
1384 stc_error_e stc_monitor_init(void)
1386 stc_system_s *system = MALLOC0(stc_system_s, 1);
1387 GIOChannel *gio = NULL;
1389 ret_value_msg_if(system == NULL, STC_ERROR_OUT_OF_MEMORY, "stc_system_s malloc fail!");
1391 /* initializing cgroups */
1394 /* creating monitored application tree */
1395 system->apps = g_tree_new_full(__apps_tree_key_compare, NULL,
1396 __apps_tree_key_free,
1397 __apps_tree_value_free);
1399 system->rstns = g_tree_new_full(__rstns_tree_key_compare, NULL,
1400 __rstns_tree_key_free,
1401 __rstns_tree_value_free);
1403 /* create netlink socket for updating kernel counters */
1404 system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
1405 if (!(system->contr_sock)) {
1406 STC_LOGE("failed to open socket");
1408 return STC_ERROR_FAIL;
1411 gio = g_io_channel_unix_new(system->contr_sock);
1412 system->contr_gsource_id =
1413 g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
1414 (GIOFunc) __process_contr_reply,
1416 g_io_channel_unref(gio);
1420 __add_application_by_interface(STC_TOTAL_DATACALL);
1421 __add_application_by_interface(STC_TOTAL_WIFI);
1422 __add_application_by_interface(STC_TOTAL_BLUETOOTH);
1424 /* creating restriction rules tree */
1425 __update_contr_cb(NULL);
1427 /* registering periodic kernel counters update callback */
1428 g_system->contr_timer_id = g_timeout_add_seconds(CONTR_TIMER_INTERVAL,
1431 if (g_system->contr_timer_id == 0) {
1432 STC_LOGE("Failed to register kernel counters update timer");
1433 __close_contr_sock(g_system);
1434 return STC_ERROR_FAIL;
1437 __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE,
1438 (int *)&g_system->background_state);
1440 __fill_restritions_list();
1442 return STC_ERROR_NONE;
1445 stc_error_e stc_monitor_deinit(void)
1447 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
1449 /* close netlink socket for updating kernel counters */
1450 __close_contr_sock(g_system);
1452 /* remove kernel counters update timer */
1453 if (g_system->contr_timer_id > 0) {
1454 g_source_remove(g_system->contr_timer_id);
1455 g_system->contr_timer_id = 0;
1458 /* destroy monitored application tree */
1459 g_tree_destroy(g_system->apps);
1460 g_system->apps = NULL;
1462 /* destroy restriction rules tree */
1463 g_tree_destroy(g_system->rstns);
1464 g_system->rstns = NULL;
1468 return STC_ERROR_NONE;
1471 stc_error_e stc_monitor_application_add(const stc_app_key_s app_key,
1472 const stc_app_value_s app_value)
1474 stc_error_e ret = STC_ERROR_NONE;
1476 stc_app_value_s *value;
1477 stc_app_value_s *lookup;
1479 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
1481 lookup = __application_lookup(g_system->apps, &app_key);
1483 STC_LOGD("app_key already present");
1484 return STC_ERROR_NONE;
1487 key = MALLOC0(stc_app_key_s, 1);
1489 STC_LOGE("key allocation failed");
1490 return STC_ERROR_OUT_OF_MEMORY;
1493 value = MALLOC0(stc_app_value_s, 1);
1495 STC_LOGE("value allocation failed");
1497 return STC_ERROR_OUT_OF_MEMORY;
1500 key->app_id = g_strdup(app_key.app_id);
1501 key->pkg_id = g_strdup(app_key.pkg_id);
1503 value->type = app_value.type;
1504 value->data_usage.in_bytes = app_value.data_usage.in_bytes;
1505 value->data_usage.out_bytes = app_value.data_usage.out_bytes;
1507 value->processes = g_tree_new_full(__processes_tree_key_compare, NULL,
1508 __processes_tree_key_free,
1509 __processes_tree_value_free);
1511 /* create cgroup and update classid */
1512 value->classid = get_classid_by_app_id(app_key.app_id, TRUE);
1514 g_tree_insert(g_system->apps, key, value);
1516 /* add nfacct rule for this classid */
1517 __add_application_monitor(key, value, stc_get_default_connection());
1518 __add_rstns_for_application(app_key.app_id);
1523 stc_error_e stc_monitor_process_add(const stc_app_key_s app_key,
1524 const stc_process_key_s proc_key,
1525 const stc_process_value_s proc_value)
1527 stc_error_e ret = STC_ERROR_NONE;
1528 stc_app_value_s *app_lookup;
1529 stc_process_key_s *key;
1530 stc_process_value_s *value;
1531 stc_process_value_s *proc_lookup;
1533 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
1535 app_lookup = __application_lookup(g_system->apps, &app_key);
1537 STC_LOGD("app_key not found");
1538 return STC_ERROR_FAIL;
1541 proc_lookup = __process_lookup(app_lookup->processes, &proc_key);
1543 STC_LOGD("proc_key already present");
1544 return STC_ERROR_NONE;
1547 key = MALLOC0(stc_process_key_s, 1);
1549 STC_LOGE("key allocation failed");
1550 return STC_ERROR_OUT_OF_MEMORY;
1553 value = MALLOC0(stc_process_value_s, 1);
1555 STC_LOGE("value allocation failed");
1557 return STC_ERROR_OUT_OF_MEMORY;
1560 key->pid = proc_key.pid;
1562 value->ground = proc_value.ground;
1564 g_tree_insert(app_lookup->processes, key, value);
1566 /* add pid to application cgroup */
1567 place_pids_to_net_cgroup(proc_key.pid, app_key.app_id);
1572 stc_error_e stc_monitor_process_remove(pid_t pid)
1574 stc_error_e ret = STC_ERROR_NONE;
1575 stc_process_key_s proc_key = {
1579 remove_pid_context_s context = {
1581 .proc_key = &proc_key,
1582 .entry_removed = FALSE,
1585 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
1587 g_tree_foreach(g_system->apps, __apps_tree_foreach_remove_pid,
1590 if (context.entry_removed)
1591 __application_remove_if_empty(context.app_key);
1596 stc_error_e stc_monitor_process_update_ground(const stc_app_key_s app_key,
1597 const stc_process_key_s proc_key,
1598 stc_app_state_e ground)
1600 stc_error_e ret = STC_ERROR_NONE;
1601 stc_app_value_s *app_lookup;
1602 stc_process_value_s *proc_lookup;
1604 ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
1606 app_lookup = __application_lookup(g_system->apps, &app_key);
1608 STC_LOGD("app_key not found");
1609 return STC_ERROR_FAIL;
1612 proc_lookup = __process_lookup(app_lookup->processes, &proc_key);
1614 STC_LOGD("proc_key not found");
1615 return STC_ERROR_FAIL;
1618 if (proc_lookup->ground != ground)
1619 proc_lookup->ground = ground;
1621 if (ground == STC_APP_STATE_BACKGROUND && __get_background_state())
1622 place_pids_to_net_cgroup(proc_key.pid, STC_BACKGROUND_APP_ID);
1624 place_pids_to_net_cgroup(proc_key.pid, app_key.app_id);
1629 void stc_monitor_update_rstn_by_default_connection(void *data)
1631 static default_connection_s old_connection;
1632 default_connection_s *new_connection = (default_connection_s *)data;
1634 if (old_connection.path != NULL) {
1636 g_tree_foreach(g_system->apps,
1637 __remove_application_monitor,
1638 (gpointer)&old_connection);
1640 if (g_system->rstns)
1641 g_tree_foreach(g_system->rstns,
1642 __remove_restriction,
1643 (gpointer)&old_connection);
1646 FREE(old_connection.path);
1647 FREE(old_connection.ifname);
1648 old_connection.type = 0;
1649 old_connection.roaming = 0;
1651 if (new_connection != NULL && new_connection->path != NULL) {
1653 g_tree_foreach(g_system->apps,
1654 __add_application_monitor,
1655 (gpointer)new_connection);
1657 if (g_system->rstns)
1658 g_tree_foreach(g_system->rstns, __add_restriction,
1661 old_connection.path = g_strdup(new_connection->path);
1662 old_connection.ifname = g_strdup(new_connection->ifname);
1663 old_connection.type = new_connection->type;
1664 old_connection.roaming = new_connection->roaming;
1668 stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info)
1673 stc_rstn_value_s value;
1675 memset(&key, 0, sizeof(stc_rstn_key_s));
1676 memset(&value, 0, sizeof(stc_rstn_value_s));
1678 key.app_id = g_strdup(info->app_id);
1679 key.ifname = g_strdup(info->ifname);
1680 key.imsi = g_strdup(info->imsi);
1681 key.iftype = info->iftype;
1682 key.roaming = info->roaming;
1684 value.rst_state = info->rst_state;
1685 value.restriction_id = info->restriction_id;
1687 if (value.rst_state != STC_RESTRICTION_EXCLUDED && info->app_id)
1688 value.classid = get_classid_by_app_id(info->app_id, TRUE);
1690 value.classid = STC_UNKNOWN_CLASSID;
1692 if (value.classid == STC_BACKGROUND_APP_CLASSID) {
1693 __set_background_state(TRUE);
1694 __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state);
1695 __process_update_background();
1698 value.data_limit = info->data_limit;
1699 value.data_warn_limit = info->data_warn_limit;
1701 ret = __rstn_tree_add(&key, &value, TRUE);
1709 stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info)
1713 stc_rstn_key_s key = {
1714 .app_id = g_strdup(info->app_id),
1715 .ifname = g_strdup(info->ifname),
1716 .imsi = g_strdup(info->imsi),
1717 .iftype = info->iftype,
1718 .roaming = info->roaming,
1721 if (!strcmp(key.app_id, STC_BACKGROUND_APP_ID)) {
1722 __set_background_state(FALSE);
1723 __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state);
1724 __process_update_background();
1727 ret = __rstn_tree_remove(&key);
1735 int stc_monitor_get_counter_socket(void)
1737 return g_system->contr_sock;