[SM][Data Usage] IMSI obtaining 13/139813/4
authorRadek Kintop <r.kintop@samsung.com>
Thu, 20 Jul 2017 12:14:12 +0000 (14:14 +0200)
committerRadek Kintop <r.kintop@samsung.com>
Thu, 20 Jul 2017 16:52:27 +0000 (18:52 +0200)
Code for checking IMSI on telephony handles
has been added. It is necessary to distinguish between
SIM1 and SIM2 while obtaining STC rules and stats.

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

index 73ec3686b873e4af3f43eda5f4290b33c7709ca2..d91d994e0043c0c8e90ce5768a997ae5633e757b 100644 (file)
@@ -77,6 +77,8 @@ typedef struct {
        telephony_handle_list_s telephony_handles;
        int num_sim_cards_available; /* Number of SIM cards available.
                                                                        Necessary for the main view. */
+       char imsi_1[15 + 1]; /* IMSI numbers of sim cards*/
+       char imsi_2[15 + 1];
 
        /* These are lists of application items *
         * returned by Data Usage API (model).
index 3162ba4dddf43ccd9a1e87bfd417890b52f701be..797ac8635e4bd018fdebda9966a7a3e55e77bfeb 100644 (file)
@@ -23,6 +23,7 @@
 #include <stc.h>
 #include <stc_internal.h>
 #include <stdbool.h>
+#include <telephony.h>
 
 void get_data_amount_str(const char *prefix, int64_t num_bytes, char *txt_out, int len_max);
 
@@ -32,5 +33,8 @@ bool get_sim_apps_list(stc_h stc, stc_stats_info_cb stats_cb);
 bool get_wifi_apps_list(stc_h stc, stc_stats_info_cb stats_cb);
 bool get_sim_restrictions(stc_h stc, stc_restriction_info_cb restrictions_cb);
 bool get_wifi_restrictions(stc_h stc, stc_restriction_info_cb restrictions_cb);
+bool get_imsi_from_telephony_handle(telephony_h handle,
+                                                                       char out_buff[], int len_max);
+bool compare_imsis(const char *imsi_a, const char *imsi_b);
 
 #endif /* SMARTMANAGER_UTILS_H_ */
index b2a5a4661dd5a10b62ed687e740b4cebd91292dc..50cd3bcf41c41ec296e077e26322549cea7016f6 100644 (file)
@@ -114,21 +114,6 @@ static int _create(void *data)
        elm_genlist_mode_set(ad->wifi_genlist, ELM_LIST_COMPRESS);
        ad->sim_2_genlist = elm_genlist_add(ad->md.layout);
        elm_genlist_mode_set(ad->sim_2_genlist, ELM_LIST_COMPRESS);
-       _generate_list(ad, ad->sim_1_genlist,
-                                               &ad->gl_data_usage_itc, &ad->gl_text_itc,
-                                               &ad->item_sim_1_data_amount,
-                                               &ad->item_sim_1_data_usage_set,
-                                               "Set Data usage cycle, and Warning, Limit value");
-       _generate_list(ad, ad->sim_2_genlist,
-                                               &ad->gl_data_usage_itc, &ad->gl_text_itc,
-                                               &ad->item_sim_2_data_amount,
-                                               &ad->item_sim_2_data_usage_set,
-                                               "Set Data usage cycle, and Warning, Limit value");
-       _generate_list(ad, ad->wifi_genlist,
-                                               &ad->gl_data_usage_itc, &ad->gl_text_itc,
-                                               &ad->item_wifi_data_amount,
-                                               &ad->item_wifi_data_usage_set,
-                                               "Set Wi-Fi usage cycle");
 
        evas_object_show(ad->md.window);
 
index e61747031e66f96cdb4957218574be62d7f4cc75..a52cbb3faec273c33762b2f6ebc05bcb72d3f57b 100644 (file)
@@ -52,51 +52,57 @@ static Eina_Bool _delayed_timer_cb(void *data)
        static bool sim_restrictions_checked = false;
        bool tmp = false;
 
+       if (!sim_stats_checked) {
+               tmp = get_sim_apps_list(ad.stc, _stc_stats_info_cb);
+               if (tmp)
+                       sim_stats_checked = true;
+               return ECORE_CALLBACK_RENEW;
+       }
+
        if (!wifi_stats_checked) {
-               ad.wifi_limits.total_data_used = 0;
                tmp = get_wifi_apps_list(ad.stc, _stc_stats_info_cb);
                if (tmp)
                        wifi_stats_checked = true;
                return ECORE_CALLBACK_RENEW;
        }
 
-       if (!sim_stats_checked) {
+       if (!sim_total_stats_checked) {
                ad.sim_1_limits.total_data_used = 0;
                ad.sim_2_limits.total_data_used = 0;
-               tmp = get_sim_apps_list(ad.stc, _stc_stats_info_cb);
+               tmp = get_sim_total_stats(ad.stc, _total_stats_cb);
                if (tmp)
-                       sim_stats_checked = true;
+                       sim_total_stats_checked = true;
                return ECORE_CALLBACK_RENEW;
        }
 
        if (!wifi_total_stats_checked) {
+               ad.wifi_limits.total_data_used = 0;
                tmp = get_wifi_total_stats(ad.stc, _total_stats_cb);
                if (tmp)
                        wifi_total_stats_checked = true;
                return ECORE_CALLBACK_RENEW;
        }
 
-       if (!sim_total_stats_checked) {
-               tmp = get_sim_total_stats(ad.stc, _total_stats_cb);
+       if (!sim_restrictions_checked) {
+               ad.sim_1_limits.limit = 0;
+               ad.sim_1_limits.warning = 0;
+               ad.sim_2_limits.limit = 0;
+               ad.sim_2_limits.warning = 0;
+               tmp = get_sim_restrictions(ad.stc, _get_restrictions_cb);
                if (tmp)
-                       sim_total_stats_checked = true;
+                       sim_restrictions_checked = true;
                return ECORE_CALLBACK_RENEW;
        }
 
        if (!wifi_restrictions_checked) {
+               ad.wifi_limits.limit = 0;
+               ad.wifi_limits.warning = 0;
                tmp = get_wifi_restrictions(ad.stc, _get_restrictions_cb);
                if (tmp)
                        wifi_restrictions_checked = true;
                return ECORE_CALLBACK_RENEW;
        }
 
-       if (!sim_restrictions_checked) {
-               tmp = get_sim_restrictions(ad.stc, _get_restrictions_cb);
-               if (tmp)
-                       sim_restrictions_checked = true;
-               return ECORE_CALLBACK_RENEW;
-       }
-
        return ECORE_CALLBACK_CANCEL;
 }
 
@@ -131,11 +137,22 @@ static bool _create_app(void *data)
                                                TELEPHONY_NOTI_SIM_STATUS, _sim_state_change_cb, ad);
                SETTING_TRACE_DEBUG("telephony_set_noti_cb[0] %s",
                                                                get_error_message(ret));
+               if (get_imsi_from_telephony_handle(
+                                       ad->telephony_handles.handle[0],
+                                       ad->imsi_1, sizeof(ad->imsi_1))
+                       )
+                       SETTING_TRACE_DEBUG("IMSI_1 %s", ad->imsi_1);
+
                if (ad->telephony_handles.count > 1) {
                        ret = telephony_set_noti_cb(ad->telephony_handles.handle[1],
                                                TELEPHONY_NOTI_SIM_STATUS, _sim_state_change_cb, ad);
                        SETTING_TRACE_DEBUG("telephony_set_noti_cb[1] %s",
                                                                        get_error_message(ret));
+                       if (get_imsi_from_telephony_handle(
+                                       ad->telephony_handles.handle[1],
+                                       ad->imsi_1, sizeof(ad->imsi_1))
+                               )
+                               SETTING_TRACE_DEBUG("IMSI_2 %s", ad->imsi_2);
                }
                _count_available_sim_cards(ad);
        }
@@ -212,6 +229,20 @@ static void _sim_state_change_cb(telephony_h handle, telephony_noti_e noti_id,
                return;
 
        _count_available_sim_cards(ad);
+
+       if (get_imsi_from_telephony_handle(
+                               ad->telephony_handles.handle[0],
+                               ad->imsi_1, sizeof(ad->imsi_1))
+               )
+               SETTING_TRACE_DEBUG("IMSI_1 %s", ad->imsi_1);
+
+       if (ad->num_sim_cards_available)
+               if (get_imsi_from_telephony_handle(
+                               ad->telephony_handles.handle[1],
+                               ad->imsi_1, sizeof(ad->imsi_1))
+                       )
+                       SETTING_TRACE_DEBUG("IMSI_2 %s", ad->imsi_2);
+
        ad->main_view_update_type = MV_UPDATE_SIM_STATE_CHANGED;
        if (setting_view_node_get_cur_view() == ad->main_view) {
                SETTING_TRACE_DEBUG("_sim_state_change_cb: updating main view");
@@ -360,8 +391,8 @@ static void _delete_stat_item(data_usage_app_item_t *item)
 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;
+       char *imsi = NULL;
        int64_t incoming = 0;
        int64_t outgoing = 0;
        stc_iface_type_e iface = STC_IFACE_UNKNOWN;
@@ -396,6 +427,7 @@ static stc_callback_ret_e _stc_stats_info_cb(stc_error_e result,
                free(app_id);
                return STC_CALLBACK_CONTINUE;
        }
+       SETTING_TRACE_DEBUG("Obtained iface: %d", iface);
 
        if (iface == STC_IFACE_WIFI) {
                if (_append_stats_list_item(&ad.wifi_apps, app_id, incoming + outgoing)
@@ -403,17 +435,31 @@ static stc_callback_ret_e _stc_stats_info_cb(stc_error_e result,
                        ad.main_view_update_type = MV_UPDATE_APPEND_WIFI_APP;
                        setting_view_update(ad.main_view, &ad);
                }
-       } else if (iface == STC_IFACE_DATACALL) {
-               if (_append_stats_list_item(&ad.sim_1_apps, app_id, incoming + outgoing)
-                       ) {
-                       ad.main_view_update_type = MV_UPDATE_APPEND_SIM_1_APP;
-                       setting_view_update(ad.main_view, &ad);
+       }
+       if (iface == STC_IFACE_DATACALL) {
+
+               ret = stc_stats_info_get_imsi(info, &imsi);
+               if (STC_ERROR_NONE == ret) {
+
+                       SETTING_TRACE_DEBUG("Obtained IMSI: %s", imsi);
+                       /* TODO: uncomment when api stc works: */
+                       /*if (compare_imsis(ad.imsi_1, imsi))*/
+                               if (_append_stats_list_item(&ad.sim_1_apps, app_id, incoming + outgoing)) {
+                                       ad.main_view_update_type = MV_UPDATE_APPEND_SIM_1_APP;
+                                       setting_view_update(ad.main_view, &ad);
+                               }
+                               /*if (compare_imsis(ad.imsi_2, imsi))
+                               if (_append_stats_list_item(&ad.sim_2_apps, app_id, incoming + outgoing)) {
+                                       ad.main_view_update_type = MV_UPDATE_APPEND_SIM_2_APP;
+                                       setting_view_update(ad.main_view, &ad);
+                               }*/
+               } else {
+                       SETTING_TRACE_ERROR("stc_stats_info_get_imsi() error: %s",
+                                                                               get_error_message(ret));
                }
-       } else {
-               SETTING_TRACE_ERROR("Unknown interface: %d", iface);
+               free(imsi);
        }
 
-       SETTING_TRACE_END;
        return STC_CALLBACK_CONTINUE;
 }
 
@@ -422,6 +468,7 @@ static stc_callback_ret_e _total_stats_cb(stc_error_e result,
 {
        int64_t incoming = 0;
        int64_t outgoing = 0;
+       char *imsi = NULL;
        int ret = STC_ERROR_NONE;
        stc_iface_type_e iface_type = STC_IFACE_UNKNOWN;
 
@@ -437,14 +484,31 @@ static stc_callback_ret_e _total_stats_cb(stc_error_e result,
                SETTING_TRACE_ERROR("get interface error: %s", get_error_message(ret));
                return STC_CALLBACK_CANCEL;
        }
-
+       SETTING_TRACE_DEBUG("Obtained iface: %d", iface_type);
        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.sim_1_limits.total_data_used = incoming + outgoing;
-                       SETTING_TRACE("SIM total in: %lld out: %lld", incoming, outgoing);
+                       ret = stc_stats_info_get_imsi(info, &imsi);
+                       if (STC_ERROR_NONE == ret) {
+
+                               SETTING_TRACE_DEBUG("Obtained IMSI: %s", imsi);
+                               /* TODO: uncomment when api stc works: */
+                               /*if (compare_imsis(ad.imsi_1, imsi)) {*/
+                                       ad.main_view_update_type = MV_UPDATE_SIM_1_TOTAL_DATA_USAGE;
+                                       ad.sim_1_limits.total_data_used = incoming + outgoing;
+                                       SETTING_TRACE("SIM 1 total in: %lld out: %lld", incoming, outgoing);
+                               /*}
+                               if (compare_imsis(ad.imsi_2, imsi)) {
+                                       ad.main_view_update_type = MV_UPDATE_SIM_2_TOTAL_DATA_USAGE;
+                                       ad.sim_2_limits.total_data_used = incoming + outgoing;
+                                       SETTING_TRACE("SIM 2 total in: %lld out: %lld", incoming, outgoing);
+                               }*/
+                       } else {
+                               SETTING_TRACE_ERROR("stc_stats_info_get_imsi() error: %s",
+                                                                                       get_error_message(ret));
+                       }
+                       free(imsi);
                }
                if (iface_type == STC_IFACE_WIFI) {
                        ad.main_view_update_type = MV_UPDATE_WIFI_TOTAL_DATA_USAGE;
@@ -464,6 +528,7 @@ static stc_callback_ret_e _get_restrictions_cb(stc_error_e result,
 {
        int ret = STC_ERROR_NONE;
        char *app_id = NULL;
+       char *imsi = NULL;
        stc_iface_type_e iface_type = STC_IFACE_UNKNOWN;
        stc_restriction_status_e status = STC_RESTRICTION_UNKNOWN;
 
@@ -496,14 +561,33 @@ static stc_callback_ret_e _get_restrictions_cb(stc_error_e result,
        }
 */
        (void)stc_restriction_info_get_iface_type(info, &iface_type);
-
+       SETTING_TRACE_DEBUG("Obtained iface: %d", iface_type);
        if (iface_type == STC_IFACE_DATACALL) {
-               (void)stc_restriction_info_get_limit(info,
-                                                                                               &(ad.sim_1_limits.limit));
-               (void)stc_restriction_info_get_warning_limit(info,
-                                                                                               &(ad.sim_1_limits.warning));
-               ad.main_view_update_type = MV_UPDATE_SIM_1_WARN_N_LIMIT;
-               setting_view_update(ad.main_view, &ad);
+
+               ret = stc_restriction_info_get_imsi(info, &imsi);
+               if (STC_ERROR_NONE == ret) {
+                       SETTING_TRACE_DEBUG("Obtained IMSI: %s", imsi);
+                       /* TODO: uncomment when api stc works: */
+                       /*if (compare_imsis(ad.imsi_1, imsi)) {*/
+                               (void)stc_restriction_info_get_limit(info,
+                                                                                                       &(ad.sim_1_limits.limit));
+                               (void)stc_restriction_info_get_warning_limit(info,
+                                                                                                       &(ad.sim_1_limits.warning));
+                               ad.main_view_update_type = MV_UPDATE_SIM_1_WARN_N_LIMIT;
+                               /*}
+                       if (compare_imsis(ad.imsi_2, imsi)) {
+                               (void)stc_restriction_info_get_limit(info,
+                                                                                                       &(ad.sim_2_limits.limit));
+                               (void)stc_restriction_info_get_warning_limit(info,
+                                                                                                       &(ad.sim_2_limits.warning));
+                               ad.main_view_update_type = MV_UPDATE_SIM_2_WARN_N_LIMIT;
+                       }*/
+                       setting_view_update(ad.main_view, &ad);
+               } else {
+                       SETTING_TRACE_ERROR("stc_stats_info_get_imsi() error: %s",
+                                                                               get_error_message(ret));
+               }
+               free(imsi);
        }
 
        if (iface_type == STC_IFACE_WIFI) {
index a93c5b0c1e986758b554e6b7242938cb82461ede..ef7c57a06cd3b451f80b02cc3bdf5888378adf7f 100644 (file)
@@ -1,6 +1,8 @@
 #include "smartmanager-utils.h"
+#include "setting-common-general-func.h"
 #include "setting-debug.h"
 #include <stdio.h>
+#include <stdlib.h>
 
 static bool _create_stats_list(stc_h stc, stc_iface_type_e iface,
                                                                stc_stats_info_cb stats_cb);
@@ -11,8 +13,6 @@ static bool _get_restrictions(stc_h stc, stc_iface_type_e iface_type,
 
 void get_data_amount_str(const char *prefix, int64_t num_bytes, char *txt_out, int len_max)
 {
-       SETTING_TRACE_BEGIN;
-
        float amount = 0.0;
 
        if (num_bytes < 1024) {
@@ -34,8 +34,6 @@ void get_data_amount_str(const char *prefix, int64_t num_bytes, char *txt_out, i
        } else {
                snprintf(txt_out, len_max, "%s%0.2fKB", prefix, amount);
        }
-
-       SETTING_TRACE_END;
 }
 
 bool get_sim_total_stats(stc_h stc, stc_stats_info_cb stats_cb)
@@ -97,7 +95,7 @@ static bool _create_stats_list(stc_h stc, stc_iface_type_e iface,
                return true;
        }
 
-       SETTING_TRACE_DEBUG("Obtaining per app data usage for ifce: %d", iface);
+       SETTING_TRACE_DEBUG("\033[1;33mObtaining per app data usage for ifce: %d", iface);
        ret = stc_foreach_stats(stc, rule, stats_cb, NULL);
        if (ret != STC_ERROR_NONE) {
                SETTING_TRACE_ERROR("stc_get_stats() error: %s",
@@ -143,7 +141,7 @@ static bool _get_total_stats(stc_h stc, stc_iface_type_e iface_type,
                return true;
        }
 
-       SETTING_TRACE_DEBUG("Obtaining total stats for ifce: %d", iface_type);
+       SETTING_TRACE_DEBUG("\033[1;34mObtaining total stats for ifce: %d", iface_type);
        ret = stc_get_total_stats(stc, rule, stats_cb, NULL);
        if (ret != STC_ERROR_NONE) {
                SETTING_TRACE_ERROR("stc_get_total_stats() error: %s",
@@ -192,7 +190,7 @@ static bool _get_restrictions(stc_h stc, stc_iface_type_e iface_type,
                return true;
        }
 
-       SETTING_TRACE_DEBUG("Obtaining restrictions for ifce: %d", iface_type);
+       SETTING_TRACE_DEBUG("\033[1;35mObtaining restrictions for ifce: %d", iface_type);
        ret = stc_foreach_restriction(stc, rule, restrictions_cb, NULL);
        if (STC_ERROR_NONE != ret) {
                SETTING_TRACE_ERROR("SIM stc_foreach_restriction() error: %s",
@@ -207,3 +205,34 @@ static bool _get_restrictions(stc_h stc, stc_iface_type_e iface_type,
        return true;
 }
 
+bool get_imsi_from_telephony_handle(telephony_h handle,
+                                                                       char out_buff[], int len_max)
+{
+       char *mcc_mnc = NULL;
+       char *msin = NULL;
+
+       if (!handle || len_max <= 0 || !out_buff)
+               return false;
+
+       if (telephony_sim_get_operator(handle, &mcc_mnc) < 0) {
+               SETTING_TRACE_ERROR("telephony_sim_get_operator(%p) error", handle);
+               return false;
+       }
+
+       if (telephony_sim_get_msin(handle, &msin) < 0) {
+               SETTING_TRACE_ERROR("telephony_sim_get_msin(%p) error", handle);
+               free(mcc_mnc);
+               return false;
+       }
+
+       snprintf(out_buff, len_max, "%s%s", mcc_mnc, msin);
+
+       free(mcc_mnc);
+       free(msin);
+       return true;
+}
+
+bool compare_imsis(const char *imsi_a, const char *imsi_b)
+{
+       return (0 == safeStrNCmp(imsi_a, imsi_b, 15));
+}