[SM][Data Usage] Total data usage obtaining 23/136223/3
authorRadek Kintop <r.kintop@samsung.com>
Wed, 28 Jun 2017 15:12:05 +0000 (17:12 +0200)
committerKiseok Chang <kiso.chang@samsung.com>
Fri, 7 Jul 2017 05:47:44 +0000 (05:47 +0000)
Added STC API call to obtain total data
usage per interface.

Change-Id: If1fac92d59205ee60472efc31eca6acd9da9257a
Signed-off-by: Radek Kintop <r.kintop@samsung.com>
setting-smartmanager/smartmanager-data/include/smartmanager-data.h
setting-smartmanager/smartmanager-data/src/smartmanager-data.c

index 5fe436c6e0e976fe175156d0cd00b24947eef31b..4f65e9657d9bc53f5a3a1d9bbf3ff15abab3641e 100644 (file)
@@ -29,6 +29,9 @@
 
 typedef enum {
        MV_UPDATE_APPEND_NONE = 0,
+       MV_UPDATE_SIM_1_TOTAL_DATA_USAGE,
+       MV_UPDATE_SIM_2_TOTAL_DATA_USAGE,
+       MV_UPDATE_WIFI_TOTAL_DATA_USAGE,
        MV_UPDATE_CLEAR_ALL_SIM_1_APPS,
        MV_UPDATE_CLEAR_ALL_SIM_2_APPS,
        MV_UPDATE_CLEAR_ALL_WIFI_APPS,
index 62637835ff10647c077eaa60f31781ed5c4ec264..ab40161a562006165fdb38a0d7e9dbee2ec7774d 100644 (file)
@@ -18,6 +18,8 @@ static bool _append_stats_list_item(Eina_List **list, char *app_id, long long da
 static void _clear_all_stat_lists(SmartMgrData *ad);
 static void _delete_stat_item(data_usage_app_item_t *item);
 
+static void _get_total_stats(SmartMgrData *ad);
+
 static SmartMgrData ad = {0,};
 
 static void _lang_changed(app_event_info_h event_info, void *data)
@@ -50,14 +52,12 @@ static stc_callback_ret_e _stc_stats_info_cb(stc_error_e result, stc_stats_info_
        }
 
        if (iface == STC_IFACE_WIFI) {
-               ad.total_data_wifi += incoming + outgoing;
                if (_append_stats_list_item(&ad.wifi_apps, app_id, incoming + outgoing)
                        ) {
                        ad.main_view_update_type = MV_UPDATE_APPEND_WIFI_APP;
                        setting_view_update(ad.main_view, &ad);
                }
        } else if (iface == STC_IFACE_DATACALL) {
-               ad.total_data_sim += incoming + outgoing;
                if (_append_stats_list_item(&ad.sim_1_apps, app_id, incoming + outgoing)
                        ) {
                        ad.main_view_update_type = MV_UPDATE_APPEND_SIM_1_APP;
@@ -209,6 +209,7 @@ static bool _create_app(void *data)
        ad->main_view_update_type = MV_UPDATE_CLEAR_ALL_SIM_1_APPS;
        setting_view_update(ad->main_view, ad);
        _create_stats_list(STC_IFACE_DATACALL);
+       _get_total_stats(ad);
 
        ecore_timer_add(3.0, _timer_cb, NULL);
 
@@ -252,7 +253,7 @@ static void _sim_state_change_cb(telephony_h handle, telephony_noti_e noti_id,
 
        if (setting_view_node_get_cur_view() == ad->main_view) {
                SETTING_TRACE_DEBUG("_sim_state_change_cb: updating main view");
-               setting_view_update(setting_view_node_get_cur_view(), ad);
+               setting_view_update(ad->main_view, ad);
        } else {
                SETTING_TRACE_DEBUG("_sim_state_change_cb: going back to main view");
                setting_view_change(setting_view_node_get_cur_view(), ad->main_view,
@@ -382,3 +383,83 @@ static void _delete_stat_item(data_usage_app_item_t *item)
        free(item->label);
        free(item);
 }
+
+static stc_callback_ret_e _total_stats_cb(stc_error_e result,
+                                                               stc_stats_info_h info, void *user_data)
+{
+       SmartMgrData *ad = user_data;
+       int64_t incoming = 0;
+       int64_t outgoing = 0;
+       int ret = STC_ERROR_NONE;
+       stc_iface_type_e iface_type = STC_IFACE_UNKNOWN;
+       SETTING_TRACE("Obtaining total stats");
+
+       ret = stc_stats_info_get_iface_type(info, &iface_type);
+       if (STC_ERROR_NONE != ret) {
+               SETTING_TRACE_ERROR("get interface error: %s", get_error_message(ret));
+               return STC_CALLBACK_CANCEL;
+       }
+
+       ret = stc_stats_info_get_counter(info, &incoming, &outgoing);
+
+       if (STC_ERROR_NONE == ret) {
+               if (iface_type == STC_IFACE_DATACALL) {
+                       ad->main_view_update_type = MV_UPDATE_SIM_1_TOTAL_DATA_USAGE;
+                       ad->total_data_sim = incoming + outgoing;
+                       SETTING_TRACE("SIM total in: %lld out: %lld", incoming, outgoing);
+               }
+               if (iface_type == STC_IFACE_WIFI) {
+                       ad->main_view_update_type = MV_UPDATE_WIFI_TOTAL_DATA_USAGE;
+                       ad->total_data_wifi = incoming + outgoing;
+                       SETTING_TRACE("WIFI total in: %lld out: %lld", incoming, outgoing);
+               }
+               setting_view_update(ad->main_view, ad);
+       } else {
+               SETTING_TRACE_ERROR("get counter error: %s", get_error_message(ret));
+               return STC_CALLBACK_CANCEL;
+       }
+       return STC_CALLBACK_CONTINUE;
+}
+
+static void _get_total_stats(SmartMgrData *ad)
+{
+       stc_stats_rule_h rule = NULL;
+       time_t now = time(NULL);
+       int ret = STC_ERROR_NONE;
+
+       ret = stc_stats_rule_create(ad->stc, &rule);
+       if (ret != STC_ERROR_NONE) {
+               SETTING_TRACE_ERROR("stc_stats_rule_create() error: %s",
+                                                       get_error_message(ret));
+               return;
+       }
+
+       ret = stc_stats_rule_set_time_interval(rule,
+                                                                                       now - STC_TIME_PERIOD_MONTH, now);
+       if (ret != STC_ERROR_NONE) {
+               SETTING_TRACE_ERROR("stc_stats_rule_set_time_interval() error: %s",
+                                                       get_error_message(ret));
+               (void)stc_stats_rule_destroy(rule);
+               return;
+       }
+
+       ret = stc_stats_rule_set_iface_type(rule, STC_IFACE_DATACALL);
+       if (ret != STC_ERROR_NONE) {
+               SETTING_TRACE_ERROR("stc_stats_rule_set_iface_type() error: %s",
+                                                       get_error_message(ret));
+               (void)stc_stats_rule_destroy(rule);
+               return;
+       }
+       (void)stc_get_total_stats(ad->stc, rule, _total_stats_cb, ad);
+
+       ret = stc_stats_rule_set_iface_type(rule, STC_IFACE_WIFI);
+       if (ret != STC_ERROR_NONE) {
+               SETTING_TRACE_ERROR("stc_stats_rule_set_iface_type() error: %s",
+                                                       get_error_message(ret));
+               (void)stc_stats_rule_destroy(rule);
+               return;
+       }
+       (void)stc_get_total_stats(ad->stc, rule, _total_stats_cb, ad);
+
+       (void)stc_stats_rule_destroy(rule);
+}