summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>2022-09-15 23:51:05 +0300
committerDenis Kenzior <denkenz@gmail.com>2022-09-19 11:04:08 -0500
commit536f108011de7876b3bab3feb63c6fa1c3649046 (patch)
tree1ddaa81b422ee0e0fec4bc46a4e72f5e3b50e217
parente7b24363f6de59500a4ba1328c0489f2730630e1 (diff)
downloadofono-536f108011de7876b3bab3feb63c6fa1c3649046.tar.gz
voicecall: Make sure SIM ecc numbers are always read
It might happen that by the time ofono_voicecall_register() is called, SIM is already in OFONO_SIM_STATE_READY state so SIM emergency numbers are never read. Fix that by adding code that reads emergency numbers even in the above case. Also, make sure ECC file watch is properly removed and sim_context is free()-ed.
-rw-r--r--src/voicecall.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/voicecall.c b/src/voicecall.c
index 3da258d8..2cf035ad 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -64,6 +64,7 @@ struct ofono_voicecall {
struct ofono_sim_context *sim_context;
unsigned int sim_watch;
unsigned int sim_state_watch;
+ unsigned int ecc_watch;
const struct ofono_voicecall_driver *driver;
void *driver_data;
struct ofono_atom *atom;
@@ -2866,6 +2867,16 @@ static void voicecall_close_settings(struct ofono_voicecall *vc)
}
}
+static void unwatch_sim_ecc_numbers(struct ofono_voicecall *vc)
+{
+ if (!vc->sim_context)
+ return;
+
+ ofono_sim_remove_file_watch(vc->sim_context, vc->ecc_watch);
+ ofono_sim_context_free(vc->sim_context);
+ vc->sim_context = NULL;
+}
+
static void voicecall_unregister(struct ofono_atom *atom)
{
DBusConnection *conn = ofono_dbus_get_connection();
@@ -2890,6 +2901,7 @@ static void voicecall_unregister(struct ofono_atom *atom)
vc->sim = NULL;
+ unwatch_sim_ecc_numbers(vc);
free_sim_ecc_numbers(vc, FALSE);
if (vc->nw_en_list) {
@@ -2993,35 +3005,39 @@ static void read_sim_ecc_numbers(int id, void *userdata)
ecc_g3_read_cb, vc);
}
+static void watch_sim_ecc_numbers(struct ofono_voicecall *vc)
+{
+ if (vc->sim_context)
+ return;
+
+ vc->sim_context = ofono_sim_context_create(vc->sim);
+ read_sim_ecc_numbers(SIM_EFECC_FILEID, vc);
+
+ vc->ecc_watch = ofono_sim_add_file_watch(vc->sim_context,
+ SIM_EFECC_FILEID, read_sim_ecc_numbers,
+ vc, NULL);
+}
+
static void sim_state_watch(enum ofono_sim_state new_state, void *user)
{
struct ofono_voicecall *vc = user;
switch (new_state) {
case OFONO_SIM_STATE_INSERTED:
- if (vc->sim_context == NULL)
- vc->sim_context = ofono_sim_context_create(vc->sim);
-
- read_sim_ecc_numbers(SIM_EFECC_FILEID, vc);
-
- ofono_sim_add_file_watch(vc->sim_context, SIM_EFECC_FILEID,
- read_sim_ecc_numbers, vc, NULL);
+ watch_sim_ecc_numbers(vc);
break;
case OFONO_SIM_STATE_NOT_PRESENT:
case OFONO_SIM_STATE_RESETTING:
/* TODO: Must release all non-emergency calls */
- if (vc->sim_context) {
- ofono_sim_context_free(vc->sim_context);
- vc->sim_context = NULL;
- }
-
+ unwatch_sim_ecc_numbers(vc);
free_sim_ecc_numbers(vc, FALSE);
set_new_ecc(vc);
voicecall_close_settings(vc);
break;
case OFONO_SIM_STATE_READY:
+ watch_sim_ecc_numbers(vc);
voicecall_load_settings(vc);
break;
case OFONO_SIM_STATE_LOCKED_OUT: