[SM] Storing the app data usage. submit/tizen/20170707.064319
authorMichal Skorupinski <m.skorupinsk@samsung.com>
Fri, 23 Jun 2017 13:00:35 +0000 (15:00 +0200)
committerKiseok Chang <kiso.chang@samsung.com>
Thu, 6 Jul 2017 10:22:14 +0000 (19:22 +0900)
Change-Id: I2b6ead679bbd41a43f3e7c4a0e23a36992785a03
Signed-off-by: Michal Skorupinski <m.skorupinsk@samsung.com>
packaging/org.tizen.setting.spec
setting-smartmanager/smartmanager-data/CMakeLists.txt
setting-smartmanager/smartmanager-data/include/smartmanager-data.h
setting-smartmanager/smartmanager-data/src/smartmanager-data.c

index 4d59a20db3b31254f89073f1dc44f299fe538679..bfcc8a269bab7c7723663fd94c2988c71eaf074b 100755 (executable)
@@ -67,6 +67,7 @@ BuildRequires:  pkgconfig(ui-gadget-1)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(context)
 BuildRequires:  pkgconfig(minizip)
+BuildRequires:  pkgconfig(capi-network-stc)
 BuildRequires:  libcap-devel
 BuildRequires:  cmake
 BuildRequires:  edje-tools
index e6bb2d2660f10e8ec3ba3aaa832e782d8628779e..232af8e12eae0090fb062c46a05f9bd2482f8991 100644 (file)
@@ -11,8 +11,10 @@ pkg_check_modules(pkgs_smartmanager_data REQUIRED
        efl-extension
        dlog
        capi-appfw-application
+       capi-appfw-app-manager
        capi-system-system-settings
        capi-telephony
+       capi-network-stc
 )
 
 FOREACH(flag ${pkgs_smartmanager_data_CFLAGS})
index 6a9781187cc3462fb27dd516586c63e13cc3ce74..fddd9f58c75b88be0969bf64ef36d02eb54e3946 100644 (file)
@@ -11,6 +11,9 @@
 #include <app.h>
 #include <dlog.h>
 #include <telephony.h>
+#include <stc.h>
+#include <app_info.h>
+#include <app_manager.h>
 
 #ifdef  LOG_TAG
 #undef  LOG_TAG
@@ -29,7 +32,7 @@ typedef struct {
        char *pkgid;
        char *icon;
        char *label;
-       int data_usage_bytes;
+       long long data_usage_bytes;
        double percent;
 } data_usage_app_item_t;
 
@@ -92,6 +95,10 @@ typedef struct {
        setting_view *mobile_view;
        Evas_Object *mobile_data_setting_genlist;
 
+       // data statistics
+       stc_h stc;
+       long long total_data_sim;
+       long long total_data_wifi;
 } SmartMgrData;
 
 #endif /* SM_DATA_H_ */
index eb5e5ea93f32028bcdd61168b57aafaa01993d80..261ac2ecbc585893d82e6d267435a34b56943d5f 100644 (file)
@@ -25,11 +25,133 @@ static void _lang_changed(app_event_info_h event_info, void *data)
        free(locale);
 }
 
+static void _append_stats_list_item(Evas_Object *list, char *app_id, long long data_usage_bytes)
+{
+       data_usage_app_item_t *dua = calloc(1, sizeof(data_usage_app_item_t));
+       app_info_h app_info;
+       int ret = app_info_create(app_id, &app_info);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] cause error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       dua->appid = app_id;
+       dua->data_usage_bytes = data_usage_bytes;
+
+       ret = app_info_get_package(app_info, &dua->pkgid);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] app_info_get_package() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       ret = app_info_get_label(app_info, &dua->label);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] app_info_get_label() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       ret = app_info_get_icon(app_info, &dua->icon);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] app_info_get_package() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       eina_list_append(list, dua);
+}
+
+static stc_callback_ret_e _stc_stats_info_cb(stc_error_e result, stc_stats_info_h info, void *user_data)
+{
+       SETTING_TRACE_BEGIN;
+       char *app_id = NULL;
+       int64_t incoming = 0;
+       int64_t outgoing = 0;
+       stc_iface_type_e iface_type = STC_IFACE_UNKNOWN;
+       Evas_Object *list = NULL;
+
+       int ret = stc_stats_info_get_app_id(info, &app_id);
+       if (ret != STC_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] stc_stats_info_get_app_id() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return STC_CALLBACK_CONTINUE;
+       }
+
+       ret = stc_stats_info_get_counter(info, &incoming, &outgoing);
+       if (ret != STC_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] stc_stats_info_get_counter() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return STC_CALLBACK_CONTINUE;
+       }
+
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] APP: %s in: %lld out: %lld",
+                       basename(__FILE__), __LINE__,
+                       app_id, incoming, outgoing);
+
+
+       ret = stc_stats_info_get_iface_type(info, &iface_type);
+       if (ret != STC_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] stc_stats_info_get_iface_type() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return STC_CALLBACK_CONTINUE;
+       }
+
+       if (iface_type == STC_IFACE_WIFI) {
+               list = ad.wifi_apps;
+               ad.total_data_wifi += incoming + outgoing;
+       } else if (iface_type == STC_IFACE_DATACALL) {
+               list = ad.sim_1_apps;
+               ad.total_data_sim += incoming + outgoing;
+       }
+
+       _append_stats_list_item(list, app_id, incoming + outgoing);
+
+       SETTING_TRACE_END;
+       return STC_CALLBACK_CONTINUE;
+}
+
+static void _create_stats_list(Eina_List *list, stc_iface_type_e iface)
+{
+       SETTING_TRACE_BEGIN;
+
+       stc_stats_rule_h rule;
+       int ret = stc_stats_rule_create(ad.stc, &rule);
+       if (ret != STC_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] stc_stats_rule_create() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       time_t now = time(NULL);
+
+       ret = stc_stats_rule_set_time_interval(rule, now - STC_TIME_PERIOD_MONTH, now - 1);
+       if (ret != STC_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] stc_stats_rule_set_time_interval() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       ret = stc_stats_rule_set_iface_type(rule, iface);
+       if (ret != STC_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] stc_stats_rule_set_iface_type() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       ret = stc_foreach_stats(ad.stc, rule, _stc_stats_info_cb, list);
+       if (ret != STC_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] stc_get_stats() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       SETTING_TRACE_END;
+}
+
 static bool _create_app(void *data)
 {
        SmartMgrData *ad = data;
        int ret = TELEPHONY_ERROR_NONE;
 
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] ==========================================================", basename(__FILE__), __LINE__);
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] ==========================================================", basename(__FILE__), __LINE__);
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] ==========================================================", basename(__FILE__), __LINE__);
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] BUILD: %s %s", basename(__FILE__), __LINE__, __DATE__, __TIME__);
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] ==========================================================", basename(__FILE__), __LINE__);
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] ==========================================================", basename(__FILE__), __LINE__);
+       dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] ==========================================================", basename(__FILE__), __LINE__);
+
        if (!ad)
                return false;
 
@@ -53,28 +175,18 @@ static bool _create_app(void *data)
                }
                _count_available_sim_cards(ad);
        }
-/* test only:
-       data_usage_app_item_t *tmp = calloc (1, sizeof(data_usage_app_item_t));
-       ad->sim_1_apps = eina_list_append(ad->sim_1_apps, tmp);
-       tmp->label = strdup("App1");
-       tmp->icon = strdup("/usr/apps/org.tizen.setting/shared/res/org.tizen.setting.png");
-       tmp->data_usage_bytes = 666;
-       tmp->percent = 15;
-
-       tmp = calloc (1, sizeof(data_usage_app_item_t));
-       ad->sim_1_apps = eina_list_append(ad->sim_1_apps, tmp);
-       tmp->label = strdup("App2");
-       tmp->icon = strdup("/usr/apps/org.tizen.setting/shared/res/org.tizen.setting.png");
-       tmp->data_usage_bytes = 1024;
-       tmp->percent = 40;
-
-       tmp = calloc (1, sizeof(data_usage_app_item_t));
-       ad->sim_1_apps = eina_list_append(ad->sim_1_apps, tmp);
-       tmp->label = strdup("App3");
-       tmp->icon = strdup("/usr/apps/org.tizen.setting/shared/res/org.tizen.setting.png");
-       tmp->data_usage_bytes = 6612354456;
-       tmp->percent = 97;
-*/
+
+       ret = stc_initialize(&ad->stc);
+       if (ret != STC_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] stc_initialize() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return false;
+       }
+
+       _create_stats_list(ad->wifi_apps, STC_IFACE_WIFI);
+       _create_stats_list(ad->sim_1_apps, STC_IFACE_DATACALL);
+
+       dlog_print(DLOG_DEBUG, LOG_TAG, "[%s:%d] STC INITIALIZED", basename(__FILE__), __LINE__);
+
        init_main_view(ad);
        setting_view_node_table_intialize();
        setting_view_node_table_register(ad->main_view, NULL);