aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Morgado <aleksandermj@chromium.org>2023-12-19 21:58:37 +0000
committerAleksander Morgado <aleksander@aleksander.es>2024-01-25 15:40:30 +0000
commite8f1edc5c4976163a569f74cf49446bc67f88424 (patch)
tree5255bc9a640bdcd77726cadf5c8ed4fd68a96d87 /src
parent6f21b1d8fbaede153aa404c29286e223265573aa (diff)
iface-modem: allow low-power request while enabled
We now enable low-power mode request if we are enabled or even connected. In this case, an explicit modem disable operation is run, so that we don't end up with an enabled modem in low-power mode. This new "low-power+disable" single operation makes the two "disable+low-power" operation combo that was run until now much much quicker, because the modem unregisters from the network and disconnects PDNs in the same network interaction.
Diffstat (limited to 'src')
-rw-r--r--src/mm-iface-modem.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c
index fef64fc5..926474e9 100644
--- a/src/mm-iface-modem.c
+++ b/src/mm-iface-modem.c
@@ -2364,6 +2364,7 @@ typedef struct {
GDBusMethodInvocation *invocation;
MMIfaceModem *self;
MMModemPowerState power_state;
+ gboolean disable_after_update;
} HandleSetPowerStateContext;
static void
@@ -2376,6 +2377,23 @@ handle_set_power_state_context_free (HandleSetPowerStateContext *ctx)
}
static void
+disable_after_low_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ HandleSetPowerStateContext *ctx)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_disable_finish (self, res, &error)) {
+ mm_obj_warn (self, "failed disabling modem after low-power mode: %s", error->message);
+ mm_dbus_method_invocation_take_error (ctx->invocation, error);
+ } else {
+ mm_obj_info (self, "disabled modem");
+ mm_gdbus_modem_complete_set_power_state (ctx->skeleton, ctx->invocation);
+ }
+ handle_set_power_state_context_free (ctx);
+}
+
+static void
set_power_state_ready (MMIfaceModem *self,
GAsyncResult *res,
HandleSetPowerStateContext *ctx)
@@ -2385,11 +2403,22 @@ set_power_state_ready (MMIfaceModem *self,
if (!mm_iface_modem_set_power_state_finish (self, res, &error)) {
mm_obj_warn (self, "failed setting power state '%s': %s", mm_modem_power_state_get_string (ctx->power_state), error->message);
mm_dbus_method_invocation_take_error (ctx->invocation, error);
- } else {
- mm_obj_info (self, "set power state '%s'", mm_modem_power_state_get_string (ctx->power_state));
+ handle_set_power_state_context_free (ctx);
+ return;
+ }
+
+ mm_obj_info (self, "set power state '%s'", mm_modem_power_state_get_string (ctx->power_state));
+
+ if (!ctx->disable_after_update) {
mm_gdbus_modem_complete_set_power_state (ctx->skeleton, ctx->invocation);
+ handle_set_power_state_context_free (ctx);
+ return;
}
- handle_set_power_state_context_free (ctx);
+
+ mm_obj_info (self, "automatically disable modem after low-power mode...");
+ mm_base_modem_disable (MM_BASE_MODEM (self),
+ (GAsyncReadyCallback)disable_after_low_ready,
+ ctx);
}
static void
@@ -2422,8 +2451,16 @@ handle_set_power_state_auth_ready (MMBaseModem *self,
MM_IFACE_MODEM_STATE, &modem_state,
NULL);
- /* Going into LOW or ON only allowed in disabled and failed states */
- if ((ctx->power_state == MM_MODEM_POWER_STATE_LOW || ctx->power_state == MM_MODEM_POWER_STATE_ON) &&
+ /* Going into LOW is allowed even when enabled or connected, the modem will automatically
+ * transition to disabled state in that case. */
+ if (ctx->power_state == MM_MODEM_POWER_STATE_LOW &&
+ modem_state > MM_MODEM_STATE_DISABLED) {
+ mm_obj_info (self, "will automatically disable after setting low-power mode");
+ ctx->disable_after_update = TRUE;
+ }
+
+ /* Going into ON only allowed in disabled and failed states */
+ if (ctx->power_state == MM_MODEM_POWER_STATE_ON &&
modem_state != MM_MODEM_STATE_FAILED &&
modem_state != MM_MODEM_STATE_DISABLED) {
mm_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE,