From 1e052ef1fe9c40f661e750bace13bca3f44b09c9 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 2 Dec 2011 16:00:02 -0600 Subject: [PATCH] network: Split EFspn and EFspdi Refresh handling If both EFspn and EFspdi are changed, then we trigger reading of EFspn twice which leads to a memory leak. Instead, always read EFspdi if the relevant service is available. If EFspdi is changed, use a simple heuristic to update the 'Name' property if appropriate. This heuristic is not always correct, but in the worst case we will emit the same name. --- src/network.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/network.c b/src/network.c index 819547e..e190389 100644 --- a/src/network.c +++ b/src/network.c @@ -1726,10 +1726,6 @@ static void sim_spn_read_cb(int ok, int length, int record, if (!sim_spn_parse(data + 1, length - 1, &netreg->spn)) return; - ofono_sim_read(netreg->sim_context, SIM_EFSPDI_FILEID, - OFONO_SIM_FILE_STRUCTURE_TRANSPARENT, - sim_spdi_read_cb, netreg); - sim_spn_display_condition_parse(netreg, dcbyte); if (netreg->current_operator) @@ -2025,7 +2021,7 @@ static void sim_pnn_opl_changed(int id, void *userdata) sim_pnn_read_cb, netreg); } -static void sim_spn_spdi_changed(int id, void *userdata) +static void sim_spn_changed(int id, void *userdata) { struct ofono_netreg *netreg = userdata; gboolean had_spn = netreg->spn != NULL && strlen(netreg->spn) > 0; @@ -2036,9 +2032,6 @@ static void sim_spn_spdi_changed(int id, void *userdata) g_free(netreg->spn); netreg->spn = NULL; - sim_spdi_free(netreg->spdi); - netreg->spdi = NULL; - /* * We can't determine whether the property really changed * without checking the name, before and after. Instead we use a @@ -2052,6 +2045,22 @@ static void sim_spn_spdi_changed(int id, void *userdata) sim_spn_read_cb, netreg); } +static void sim_spdi_changed(int id, void *userdata) +{ + struct ofono_netreg *netreg = userdata; + + sim_spdi_free(netreg->spdi); + netreg->spdi = NULL; + + if (netreg->current_operator && + netreg->status == NETWORK_REGISTRATION_STATUS_ROAMING) + netreg_emit_operator_display_name(netreg); + + ofono_sim_read(netreg->sim_context, SIM_EFSPDI_FILEID, + OFONO_SIM_FILE_STRUCTURE_TRANSPARENT, + sim_spdi_read_cb, netreg); +} + static void emulator_cops_cb(struct ofono_emulator *em, struct ofono_emulator_request *req, void *userdata) { @@ -2161,12 +2170,23 @@ void ofono_netreg_register(struct ofono_netreg *netreg) ofono_sim_read(netreg->sim_context, SIM_EFSPN_FILEID, OFONO_SIM_FILE_STRUCTURE_TRANSPARENT, sim_spn_read_cb, netreg); + ofono_sim_add_file_watch(netreg->sim_context, SIM_EFSPN_FILEID, - sim_spn_spdi_changed, netreg, - NULL); - ofono_sim_add_file_watch(netreg->sim_context, SIM_EFSPDI_FILEID, - sim_spn_spdi_changed, netreg, + sim_spn_changed, netreg, NULL); + + if (__ofono_sim_service_available(netreg->sim, + SIM_UST_SERVICE_PROVIDER_DISPLAY_INFO, + SIM_SST_SERVICE_PROVIDER_DISPLAY_INFO)) { + ofono_sim_read(netreg->sim_context, SIM_EFSPDI_FILEID, + OFONO_SIM_FILE_STRUCTURE_TRANSPARENT, + sim_spdi_read_cb, netreg); + + ofono_sim_add_file_watch(netreg->sim_context, + SIM_EFSPDI_FILEID, + sim_spdi_changed, + netreg, NULL); + } } __ofono_atom_register(netreg->atom, netreg_unregister); -- 2.7.4