api,sim: new 'Emergency Numbers' property

This commit is contained in:
Aleksander Morgado
2019-09-24 16:08:47 +02:00
parent 45cf1ba20a
commit 1f6c006976
8 changed files with 111 additions and 5 deletions

View File

@@ -258,6 +258,7 @@ static FieldInfo field_infos[] = {
[MMC_F_SIM_PROPERTIES_ICCID] = { "sim.properties.iccid", "iccid", MMC_S_SIM_PROPERTIES, },
[MMC_F_SIM_PROPERTIES_OPERATOR_ID] = { "sim.properties.operator-code", "operator id", MMC_S_SIM_PROPERTIES, },
[MMC_F_SIM_PROPERTIES_OPERATOR_NAME] = { "sim.properties.operator-name", "operator name", MMC_S_SIM_PROPERTIES, },
[MMC_F_SIM_PROPERTIES_EMERGENCY_NUMBERS] = { "sim.properties.emergency-numbers", "emergency numbers", MMC_S_SIM_PROPERTIES, },
[MMC_F_MODEM_LIST_DBUS_PATH] = { "modem-list", "modems", MMC_S_UNKNOWN, },
[MMC_F_SMS_LIST_DBUS_PATH] = { "modem.messaging.sms", "sms messages", MMC_S_UNKNOWN, },
[MMC_F_CALL_LIST_DBUS_PATH] = { "modem.voice.call", "calls", MMC_S_UNKNOWN, },

View File

@@ -275,6 +275,7 @@ typedef enum {
MMC_F_SIM_PROPERTIES_ICCID,
MMC_F_SIM_PROPERTIES_OPERATOR_ID,
MMC_F_SIM_PROPERTIES_OPERATOR_NAME,
MMC_F_SIM_PROPERTIES_EMERGENCY_NUMBERS,
/* Lists */
MMC_F_MODEM_LIST_DBUS_PATH,
MMC_F_SMS_LIST_DBUS_PATH,

View File

@@ -163,6 +163,7 @@ print_sim_info (MMSim *sim)
mmcli_output_string (MMC_F_SIM_PROPERTIES_ICCID, mm_sim_get_identifier (sim));
mmcli_output_string (MMC_F_SIM_PROPERTIES_OPERATOR_ID, mm_sim_get_operator_identifier (sim));
mmcli_output_string (MMC_F_SIM_PROPERTIES_OPERATOR_NAME, mm_sim_get_operator_name (sim));
mmcli_output_string_array (MMC_F_SIM_PROPERTIES_EMERGENCY_NUMBERS, (const gchar **) mm_sim_get_emergency_numbers (sim), FALSE);
mmcli_output_dump ();
}

View File

@@ -97,5 +97,15 @@
-->
<property name="OperatorName" type="s" access="read" />
<!--
EmergencyNumbers:
List of emergency numbers programmed in the SIM card.
These numbers should be treated as numbers for emergency calls in
addition to 112 and 911.
-->
<property name="EmergencyNumbers" type="as" access="read" />
</interface>
</node>

View File

@@ -245,6 +245,45 @@ mm_sim_dup_operator_name (MMSim *self)
/*****************************************************************************/
/**
* mm_sim_get_emergency_numbers:
* @self: A #MMSim.
*
* Gets the list of emergency call numbers programmed in the SIM card.
*
* <warning>The returned value is only valid until the property changes so
* it is only safe to use this function on the thread where
* @self was constructed. Use mm_sim_dup_emergency_numbers() if on another
* thread.</warning>
*
* Returns: (transfer none): The emergency numbers, or %NULL if none available. Do not free the returned value, it belongs to @self.
*/
const gchar * const *
mm_sim_get_emergency_numbers (MMSim *self)
{
g_return_val_if_fail (MM_IS_SIM (self), NULL);
return mm_gdbus_sim_get_emergency_numbers (MM_GDBUS_SIM (self));
}
/**
* mm_sim_dup_emergency_numbers:
* @self: A #MMSim.
*
* Gets a copy of the list of emergency call numbers programmed in the SIM card.
*
* Returns: (transfer full): The emergency numbers, or %NULL if none available. The returned value should be freed with g_strfreev().
*/
gchar **
mm_sim_dup_emergency_numbers (MMSim *self)
{
g_return_val_if_fail (MM_IS_SIM (self), NULL);
return mm_gdbus_sim_dup_emergency_numbers (MM_GDBUS_SIM (self));
}
/*****************************************************************************/
/**
* mm_sim_send_pin_finish:
* @self: A #MMSim.

View File

@@ -82,6 +82,9 @@ gchar *mm_sim_dup_operator_identifier (MMSim *self);
const gchar *mm_sim_get_operator_name (MMSim *self);
gchar *mm_sim_dup_operator_name (MMSim *self);
const gchar * const *mm_sim_get_emergency_numbers (MMSim *self);
gchar **mm_sim_dup_emergency_numbers (MMSim *self);
void mm_sim_send_pin (MMSim *self,
const gchar *pin,
GCancellable *cancellable,

View File

@@ -1341,6 +1341,7 @@ typedef enum {
INITIALIZATION_STEP_IMSI,
INITIALIZATION_STEP_OPERATOR_ID,
INITIALIZATION_STEP_OPERATOR_NAME,
INITIALIZATION_STEP_EMERGENCY_NUMBERS,
INITIALIZATION_STEP_LAST
} InitializationStep;
@@ -1414,6 +1415,32 @@ init_load_sim_identifier_ready (MMBaseSim *self,
interface_initialization_step (task);
}
static void
init_load_emergency_numbers_ready (MMBaseSim *self,
GAsyncResult *res,
GTask *task)
{
InitAsyncContext *ctx;
GError *error = NULL;
GStrv str_list;
str_list = MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers_finish (self, res, &error);
if (error) {
mm_warn ("couldn't load list of Emergency Numbers: '%s'", error->message);
g_error_free (error);
}
if (str_list) {
mm_gdbus_sim_set_emergency_numbers (MM_GDBUS_SIM (self), (const gchar *const *) str_list);
g_strfreev (str_list);
}
/* Go on to next step */
ctx = g_task_get_task_data (task);
ctx->step++;
interface_initialization_step (task);
}
#undef STR_REPLY_READY_FN
#define STR_REPLY_READY_FN(NAME,DISPLAY) \
static void \
@@ -1527,6 +1554,22 @@ interface_initialization_step (GTask *task)
/* Fall down to next step */
ctx->step++;
case INITIALIZATION_STEP_EMERGENCY_NUMBERS:
/* Emergency Numbers are meant to be loaded only once during the whole
* lifetime of the modem. Therefore, if we already have them loaded,
* don't try to load them again. */
if (mm_gdbus_sim_get_emergency_numbers (MM_GDBUS_SIM (self)) == NULL &&
MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers &&
MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers_finish) {
MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers (
self,
(GAsyncReadyCallback)init_load_emergency_numbers_ready,
task);
return;
}
/* Fall down to next step */
ctx->step++;
case INITIALIZATION_STEP_LAST:
/* We are done without errors! */
g_task_return_boolean (task, TRUE);

View File

@@ -83,6 +83,14 @@ struct _MMBaseSimClass {
GAsyncResult *res,
GError **error);
/* Load emergency numbers (async) */
void (* load_emergency_numbers) (MMBaseSim *self,
GAsyncReadyCallback callback,
gpointer user_data);
GStrv (* load_emergency_numbers_finish) (MMBaseSim *self,
GAsyncResult *res,
GError **error);
/* Change PIN (async) */
void (* change_pin) (MMBaseSim *self,
const gchar *old_pin,