* limitations under the License.
*/
+#include <vconf/vconf.h>
+
#include "stc-monitor.h"
#include "stc-default-connection.h"
+/* connman service dbus details */
#define CONNMAN_SERVICE "net.connman"
#define CONNMAN_PATH "/net/connman"
#define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged"
+/* telephony service dbus details */
+#define TELEPHONY_SERVICE "org.tizen.telephony"
+#define TELEPHONY_DEFAULT_PATH "/org/tizen/telephony"
+
+#define TELEPHONY_SERVICE_MANAGER TELEPHONY_SERVICE".Manager"
+#define TELEPHONY_SIM_INTERFACE TELEPHONY_SERVICE".Sim"
+
+#define TELEPHONY_GET_MODEMS "GetModems"
+#define TELEPHONY_GET_IMSI "GetIMSI"
+
+#define SIM_SLOT_SINGLE 1
+
+#define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE "db/telephony/dualsim/default_data_service"
+
default_connection_s g_default_connection;
guint g_default_connection_sub_id = 0;
+static int __telephony_get_current_sim(void)
+{
+ int sim_slot_count = 0;
+ int current_sim = 0;
+
+ if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0) {
+ STC_LOGD("failed to get sim slot count");
+ return -1;
+ }
+
+ if (sim_slot_count == SIM_SLOT_SINGLE) {
+ STC_LOGD("It's single sim model");
+ return current_sim;
+ }
+
+ if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, ¤t_sim) != 0) {
+ STC_LOGD("failed to get default data service = %d\n",
+ current_sim);
+ return -1;
+ }
+
+ return current_sim;
+}
+
+static void __telephony_get_modem_imsi(GDBusConnection *connection,
+ const char *default_modem_name)
+{
+ GVariant *message = NULL;
+ char tel_path[MAX_PATH_LENGTH];
+ const char *plmn = NULL;
+ int plmn_len = 0;
+ const char *msin = NULL;
+ int msin_len = 0;
+
+ snprintf(tel_path, sizeof(tel_path), "%s/%s", TELEPHONY_DEFAULT_PATH,
+ default_modem_name);
+ message = stc_manager_gdbus_call_sync(connection,
+ TELEPHONY_SERVICE,
+ tel_path,
+ TELEPHONY_SIM_INTERFACE,
+ TELEPHONY_GET_IMSI,
+ NULL);
+ if (message == NULL) {
+ STC_LOGE("Failed to get services informations");
+ goto done;
+ }
+
+ DEBUG_PARAMS(message);
+ DEBUG_PARAM_TYPE(message);
+ g_variant_get(message, "(&s&s)", &plmn, &msin);
+ plmn_len = strlen(plmn);
+ msin_len = strlen(msin);
+
+ if (msin_len + plmn_len >= IMSI_LENGTH) {
+ STC_LOGD("Incorrect length of mobile subscriber identifier + net id");
+ goto done;
+ }
+
+ snprintf(g_default_connection.imsi, IMSI_LENGTH, "%s%s", plmn, msin);
+
+done:
+ g_variant_unref(message);
+ return;
+}
+
+static void __telephony_update_default_modem_imsi(GDBusConnection *connection)
+{
+ GVariant *message = NULL;
+ GVariantIter *iter = NULL;
+ gchar *default_modem_name = NULL;
+ gchar *modem_name = NULL;
+ int current_sim = __telephony_get_current_sim();
+
+ if (current_sim < 0) {
+ STC_LOGI("Sim not found");
+ return;
+ }
+
+ message = stc_manager_gdbus_call_sync(connection,
+ TELEPHONY_SERVICE,
+ TELEPHONY_DEFAULT_PATH,
+ TELEPHONY_SERVICE_MANAGER,
+ TELEPHONY_GET_MODEMS,
+ NULL);
+ if (message == NULL) {
+ STC_LOGE("Failed to get services informations");
+ return;
+ }
+
+ g_variant_get(message, "(as)", &iter);
+ DEBUG_PARAMS(message);
+ DEBUG_PARAM_TYPE(message);
+ while (g_variant_iter_loop(iter, "s", &modem_name)) {
+ if (current_sim == 0) {
+ default_modem_name = g_strdup(modem_name);
+ FREE(modem_name);
+ break;
+ }
+ current_sim--;
+ }
+
+ __telephony_get_modem_imsi(connection, default_modem_name);
+
+ FREE(default_modem_name);
+ g_variant_iter_free(iter);
+ g_variant_unref(message);
+ return;
+}
+
static void __print_default_connection_info(void)
{
STC_LOGI("============= default connection info ============");
STC_LOGI("type [%d]", g_default_connection.type);
STC_LOGI("ifname [%s]", g_default_connection.ifname);
STC_LOGI("roaming [%u]", g_default_connection.roaming ? TRUE : FALSE);
+ if (g_default_connection.type == STC_IFACE_DATACALL)
+ STC_LOGI("imsi [%s]", g_default_connection.imsi);
STC_LOGI("==================================================");
}
g_variant_iter_free(iter);
g_variant_unref(message);
- if (__is_cellular_profile(g_default_connection.path))
+ if (__is_cellular_profile(g_default_connection.path)) {
g_default_connection.type = STC_IFACE_DATACALL;
- else if (__is_wifi_profile(g_default_connection.path))
+ __telephony_update_default_modem_imsi(connection);
+ } else if (__is_wifi_profile(g_default_connection.path)) {
g_default_connection.type = STC_IFACE_WIFI;
- else if (__is_ethernet_profile(g_default_connection.path))
+ } else if (__is_ethernet_profile(g_default_connection.path)) {
g_default_connection.type = STC_IFACE_WIRED;
- else if (__is_bluetooth_profile(g_default_connection.path))
+ } else if (__is_bluetooth_profile(g_default_connection.path)) {
g_default_connection.type = STC_IFACE_BLUETOOTH;
- else
+ } else {
g_default_connection.type = STC_IFACE_UNKNOWN;
+ }
__get_default_connection_info(connection, g_default_connection.path);
return STC_ERROR_NONE;
}
-stc_iface_type_e stc_default_connection_get_type(void)
-{
- return g_default_connection.type;
-}
-
gchar *stc_default_connection_get_ifname(void)
{
return g_strdup(g_default_connection.ifname);
}
-gboolean stc_default_connection_get_roaming(void)
-{
- return g_default_connection.roaming;
-}
-
default_connection_s *stc_get_default_connection(void)
{
return &g_default_connection;
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return FALSE;
+
stc->carg->sock = stc_monitor_get_counter_socket();
}
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return FALSE;
+
stc->carg->sock = stc_monitor_get_counter_socket();
}
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL) {
+ g_free(default_ifname);
+ return;
+ }
+
stc->carg->sock =
stc_monitor_get_counter_socket();
}
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL) {
+ g_free(default_ifname);
+ return;
+ }
+
stc->carg->sock =
stc_monitor_get_counter_socket();
}
time_t *touch_time = (time_t *)data;
stc_db_classid_iftype_key stat_key;
stc_db_app_stats stat;
- char *default_ifname = stc_default_connection_get_ifname();
+ default_connection_s *default_connection = stc_get_default_connection();
memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key));
memset(&stat, 0 , sizeof(stc_db_app_stats));
stat_key.classid = app_value->classid;
- stat_key.iftype = stc_default_connection_get_type();
+ stat_key.iftype = default_connection->type;
+
if (STC_IFACE_DATACALL == stat_key.iftype)
- stat_key.imsi = g_strdup("unknown");
+ stat_key.imsi = g_strdup(default_connection->imsi);
else
stat_key.imsi = g_strdup("noneimsi");
- g_strlcpy(stat_key.ifname, default_ifname, MAX_IFACE_LENGTH);
+
+ g_strlcpy(stat_key.ifname, default_connection->ifname,
+ MAX_IFACE_LENGTH);
stat.app_id = g_strdup(app_key->app_id);
stat.snd_count = app_value->counter.out_bytes;
stat.rcv_count = app_value->counter.in_bytes;
- stat.is_roaming = stc_default_connection_get_roaming();
+ stat.is_roaming = default_connection->roaming;
stat.ground = STC_APP_STATE_UNKNOWN;
table_statistics_insert(&stat_key, &stat, *touch_time);
FREE(stat.app_id);
FREE(stat_key.imsi);
- FREE(default_ifname);
return FALSE;
}
ret_value_msg_if(stc == NULL, STC_ERROR_FAIL, "Can't get stc data");
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return TRUE; /* we need to continue the timer */
+
stc->carg->sock = stc_monitor_get_counter_socket();
}
g_system->background_state = state;
}
-static gboolean __processes_tree_foreach_background(gpointer key, gpointer value,
- gpointer data)
+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)
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);
+ g_tree_foreach(app_value->processes,
+ __processes_tree_foreach_background, app_key);
return FALSE;
}
return STC_ERROR_FAIL;
}
- __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE, &g_system->background_state);
+ __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE,
+ (int *)&g_system->background_state);
__fill_restritions_list();