From 635c60588fd549204a40ac210400b38f9b034741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:00:57 +0100 Subject: [PATCH 01/14] wwan/ofono: Modernize DBus prefix and callback names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gbp-Dch: Ignore Signed-off-by: Guido Günther Part-of: --- src/dbus/meson.build | 9 +- src/wwan/phosh-wwan-ofono.c | 201 ++++++++++++++++++------------------ 2 files changed, 99 insertions(+), 111 deletions(-) diff --git a/src/dbus/meson.build b/src/dbus/meson.build index f4ac9b282..8d0b85518 100644 --- a/src/dbus/meson.build +++ b/src/dbus/meson.build @@ -19,6 +19,7 @@ dbus_client_protos = [ ['login1-session-dbus', 'org.freedesktop.login1.Session.xml', 'org.freedesktop.login1'], ['gsd-color-dbus', 'org.gnome.SettingsDaemon.Color.xml', 'org.gnome.SettingsDaemon'], ['gnome-session-dbus', 'org.gnome.SessionManager.xml', 'org.gnome'], + ['phosh-wwan-ofono-dbus', 'org.ofono.xml', 'org'], ] # @@ -99,14 +100,6 @@ generated_dbus_sources += gnome.gdbus_codegen('mpris-dbus', install_header: bindings_lib, install_dir: dbus_inc_dir, namespace: 'PhoshMprisDBus') - -generated_dbus_sources += gnome.gdbus_codegen('phosh-wwan-ofono-dbus', - 'org.ofono.xml', - namespace: 'PhoshOfonoDBus', - install_header: bindings_lib, - install_dir: dbus_inc_dir, - interface_prefix: 'org.ofono') - generated_dbus_sources += gnome.gdbus_codegen('phosh-osk0-dbus', 'sm.puri.OSK0.xml', install_header: bindings_lib, diff --git a/src/wwan/phosh-wwan-ofono.c b/src/wwan/phosh-wwan-ofono.c index 6712323e5..df7c2eeac 100644 --- a/src/wwan/phosh-wwan-ofono.c +++ b/src/wwan/phosh-wwan-ofono.c @@ -41,9 +41,9 @@ enum { typedef struct _PhoshWWanOfono { PhoshWWanManager parent; - PhoshOfonoDBusNetworkRegistration *proxy_netreg; - PhoshOfonoDBusSimManager *proxy_sim; - PhoshOfonoDBusManager *proxy_manager; + PhoshDBusOfonoNetworkRegistration *proxy_netreg; + PhoshDBusOfonoSimManager *proxy_sim; + PhoshDBusOfonoManager *proxy_manager; /* Signals we connect to */ gulong manager_object_added_signal_id; @@ -130,7 +130,7 @@ phosh_wwan_ofono_update_operator (PhoshWWanOfono *self, GVariant *v) g_free (self->operator); self->operator = g_strdup (operator); - g_debug("Operator is '%s'", self->operator); + g_debug ("Operator is '%s'", self->operator); g_object_notify (G_OBJECT (self), "operator"); } } @@ -180,7 +180,7 @@ phosh_wwan_ofono_update_present (PhoshWWanOfono *self, gboolean present) static void -phosh_wwan_ofono_dbus_netreg_update_prop (PhoshOfonoDBusNetworkRegistration *proxy, +phosh_wwan_ofono_dbus_netreg_update_prop (PhoshDBusOfonoNetworkRegistration *proxy, const char *property, GVariant *value, PhoshWWanOfono *self) @@ -196,10 +196,10 @@ phosh_wwan_ofono_dbus_netreg_update_prop (PhoshOfonoDBusNetworkRegistration *pro static void -phosh_wwan_ofono_dbus_netreg_prop_changed_cb (PhoshOfonoDBusNetworkRegistration *proxy, - const char *property, - GVariant *value, - PhoshWWanOfono *self) +on_netreg_prop_changed (PhoshDBusOfonoNetworkRegistration *proxy, + const char *property, + GVariant *value, + PhoshWWanOfono *self) { g_autoptr (GVariant) inner = g_variant_get_variant (value); phosh_wwan_ofono_dbus_netreg_update_prop (proxy, property, inner, self); @@ -207,7 +207,7 @@ phosh_wwan_ofono_dbus_netreg_prop_changed_cb (PhoshOfonoDBusNetworkRegistration static void -phosh_wwan_ofono_dbus_sim_update_prop (PhoshOfonoDBusSimManager *proxy, +phosh_wwan_ofono_dbus_sim_update_prop (PhoshDBusOfonoSimManager *proxy, const char *property, GVariant *value, PhoshWWanOfono *self) @@ -223,12 +223,12 @@ phosh_wwan_ofono_dbus_sim_update_prop (PhoshOfonoDBusSimManager *proxy, static void -phosh_wwan_ofono_dbus_sim_prop_changed_cb (PhoshOfonoDBusSimManager *proxy, - const char *property, - GVariant *value, - PhoshWWanOfono *self) +on_sim_prop_changed (PhoshDBusOfonoSimManager *proxy, + const char *property, + GVariant *value, + PhoshWWanOfono *self) { - g_autoptr (GVariant) inner = g_variant_get_variant(value); + g_autoptr (GVariant) inner = g_variant_get_variant (value); phosh_wwan_ofono_dbus_sim_update_prop (proxy, property, inner, self); } @@ -313,30 +313,31 @@ phosh_wwan_ofono_destroy_modem (PhoshWWanOfono *self) static void -phosh_wwan_ofono_on_sim_get_properties_finish (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_sim_get_properties_ready (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { g_autoptr (GError) err = NULL; g_autoptr (GVariant) properties = NULL; g_autoptr (GVariant) value = NULL; + PhoshWWanOfono *self = PHOSH_WWAN_OFONO (user_data); char *property; GVariantIter i; - - if (!phosh_ofono_dbus_sim_manager_call_get_properties_finish ( - self->proxy_sim, - &properties, - res, - &err)) { - g_warning ("Failed to get sim proxy properties for %s: %s", - self->object_path, err->message); + gboolean success; + + success = phosh_dbus_ofono_sim_manager_call_get_properties_finish (self->proxy_sim, + &properties, + res, + &err); + if (!success) { + g_warning ("Failed to get sim proxy properties for %s: %s", self->object_path, err->message); g_object_unref (self); return; } g_variant_iter_init (&i, properties); while (g_variant_iter_next (&i, "{&sv}", &property, &value, NULL)) { - phosh_wwan_ofono_dbus_sim_update_prop(self->proxy_sim, property, value, self); + phosh_wwan_ofono_dbus_sim_update_prop (self->proxy_sim, property, value, self); g_clear_pointer (&value, g_variant_unref); } @@ -345,42 +346,38 @@ phosh_wwan_ofono_on_sim_get_properties_finish (GObject *source_object, static void -phosh_wwan_ofono_on_proxy_sim_new_for_bus_finish (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_proxy_sim_new_for_bus_ready (GObject *source_object, + GAsyncResult *res, + PhoshWWanOfono *self) { g_autoptr (GError) err = NULL; - self->proxy_sim = phosh_ofono_dbus_sim_manager_proxy_new_for_bus_finish ( - res, - &err); + self->proxy_sim = phosh_dbus_ofono_sim_manager_proxy_new_for_bus_finish (res, &err); - g_debug("proxy_sim finish '%p'", self->proxy_sim); + g_debug ("proxy_sim finish '%p'", self->proxy_sim); if (!self->proxy_sim) { - g_warning ("Failed to get sim proxy for %s: %s", - self->object_path, err->message); + g_warning ("Failed to get sim proxy for %s: %s", self->object_path, err->message); g_object_unref (self); return; } - phosh_ofono_dbus_sim_manager_call_get_properties ( - self->proxy_sim, - NULL, - (GAsyncReadyCallback)phosh_wwan_ofono_on_sim_get_properties_finish, - self); + phosh_dbus_ofono_sim_manager_call_get_properties (self->proxy_sim, + NULL, + on_sim_get_properties_ready, + self); self->proxy_sim_props_signal_id = g_signal_connect (self->proxy_sim, - "property-changed", - G_CALLBACK (phosh_wwan_ofono_dbus_sim_prop_changed_cb), - self); + "property-changed", + G_CALLBACK (on_sim_prop_changed), + self); } static void -phosh_wwan_ofono_on_netreg_get_properties_finish (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_netreg_get_properties_ready (GObject *source_object, + GAsyncResult *res, + PhoshWWanOfono *self) { g_autoptr (GError) err = NULL; g_autoptr (GVariant) properties = NULL; @@ -388,20 +385,19 @@ phosh_wwan_ofono_on_netreg_get_properties_finish (GObject *source_object, char *property; GVariantIter i; - if (!phosh_ofono_dbus_network_registration_call_get_properties_finish ( - self->proxy_netreg, - &properties, - res, - &err)) { - g_warning ("Failed to get netreg proxy properties for %s: %s", - self->object_path, err->message); + if (!phosh_dbus_ofono_network_registration_call_get_properties_finish ( + self->proxy_netreg, + &properties, + res, + &err)) { + g_warning ("Failed to get netreg proxy properties for %s: %s",self->object_path, err->message); g_object_unref (self); return; } g_variant_iter_init (&i, properties); while (g_variant_iter_next (&i, "{&sv}", &property, &value, NULL)) { - phosh_wwan_ofono_dbus_netreg_update_prop(self->proxy_netreg, property, value, self); + phosh_wwan_ofono_dbus_netreg_update_prop (self->proxy_netreg, property, value, self); g_clear_pointer (&value, g_variant_unref); } @@ -410,32 +406,32 @@ phosh_wwan_ofono_on_netreg_get_properties_finish (GObject *source_object, static void -phosh_wwan_ofono_on_proxy_netreg_new_for_bus_finish (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_proxy_netreg_new_for_bus_ready (GObject *source_object, + GAsyncResult *res, + PhoshWWanOfono *self) { g_autoptr (GError) err = NULL; - self->proxy_netreg = phosh_ofono_dbus_network_registration_proxy_new_for_bus_finish ( + self->proxy_netreg = phosh_dbus_ofono_network_registration_proxy_new_for_bus_finish ( res, &err); if (!self->proxy_netreg) { g_warning ("Failed to get netreg proxy for %s: %s", - self->object_path, err->message); + self->object_path, err->message); g_object_unref (self); return; } - phosh_ofono_dbus_network_registration_call_get_properties ( + phosh_dbus_ofono_network_registration_call_get_properties ( self->proxy_netreg, NULL, - (GAsyncReadyCallback)phosh_wwan_ofono_on_netreg_get_properties_finish, + (GAsyncReadyCallback)on_netreg_get_properties_ready, self); self->proxy_netreg_props_signal_id = g_signal_connect (self->proxy_netreg, "property-changed", - G_CALLBACK (phosh_wwan_ofono_dbus_netreg_prop_changed_cb), + G_CALLBACK (on_netreg_prop_changed), self); } @@ -448,22 +444,22 @@ phosh_wwan_ofono_init_modem (PhoshWWanOfono *self, const char *object_path) self->object_path = g_strdup (object_path); self->locked = FALSE; - phosh_ofono_dbus_network_registration_proxy_new_for_bus ( + phosh_dbus_ofono_network_registration_proxy_new_for_bus ( G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, BUS_NAME, object_path, NULL, - (GAsyncReadyCallback)phosh_wwan_ofono_on_proxy_netreg_new_for_bus_finish, + (GAsyncReadyCallback)on_proxy_netreg_new_for_bus_ready, g_object_ref (self)); - phosh_ofono_dbus_sim_manager_proxy_new_for_bus ( + phosh_dbus_ofono_sim_manager_proxy_new_for_bus ( G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, BUS_NAME, object_path, NULL, - (GAsyncReadyCallback)phosh_wwan_ofono_on_proxy_sim_new_for_bus_finish, + (GAsyncReadyCallback)on_proxy_sim_new_for_bus_ready, g_object_ref (self)); phosh_wwan_ofono_update_present (self, TRUE); @@ -471,10 +467,10 @@ phosh_wwan_ofono_init_modem (PhoshWWanOfono *self, const char *object_path) static void -phosh_wwan_ofono_modem_added_cb (PhoshWWanOfono *self, - const char *modem_object_path, - GVariant *modem_properties, - PhoshOfonoDBusManager *proxy_manager) +on_modem_added (PhoshWWanOfono *self, + const char *modem_object_path, + GVariant *modem_properties, + PhoshDBusOfonoManager *proxy_manager) { g_debug ("Modem added at path: %s", modem_object_path); if (self->object_path == NULL) { @@ -485,9 +481,9 @@ phosh_wwan_ofono_modem_added_cb (PhoshWWanOfono *self, static void -phosh_wwan_ofono_modem_removed_cb (PhoshWWanOfono *self, - const char *modem_object_path, - PhoshOfonoDBusManager *proxy_manager) +on_modem_removed (PhoshWWanOfono *self, + const char *modem_object_path, + PhoshDBusOfonoManager *proxy_manager) { g_debug ("Modem removed at path: %s", modem_object_path); if (!g_strcmp0 (modem_object_path, self->object_path)) { @@ -498,22 +494,23 @@ phosh_wwan_ofono_modem_removed_cb (PhoshWWanOfono *self, static void -phosh_wwan_ofono_on_get_modems_finish (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_get_modems_ready (GObject *source_object, + GAsyncResult *res, + PhoshWWanOfono *self) { g_autoptr (GError) err = NULL; g_autoptr (GVariant) modems = NULL; GVariantIter i; const char *modem_object_path = NULL; - - if (!phosh_ofono_dbus_manager_call_get_modems_finish ( - self->proxy_manager, - &modems, - res, - &err)) { - g_warning ("GetModems call failed: %s", err->message); - return; + gboolean success; + + success = phosh_dbus_ofono_manager_call_get_modems_finish (self->proxy_manager, + &modems, + res, + &err); + if (!success) { + g_warning ("GetModems call failed: %s", err->message); + return; } g_variant_iter_init (&i, modems); @@ -528,14 +525,14 @@ phosh_wwan_ofono_on_get_modems_finish (GObject *source_object, static void -phosh_wwan_ofono_on_ofono_manager_created (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_ofono_manager_created (GObject *source_object, + GAsyncResult *res, + PhoshWWanOfono *self) { g_autoptr (GError) err = NULL; g_debug ("manager created for %p", source_object); - self->proxy_manager = phosh_ofono_dbus_manager_proxy_new_for_bus_finish ( + self->proxy_manager = phosh_dbus_ofono_manager_proxy_new_for_bus_finish ( res, &err); @@ -544,22 +541,20 @@ phosh_wwan_ofono_on_ofono_manager_created (GObject *source_object, return; } - self->manager_object_added_signal_id = - g_signal_connect_swapped (self->proxy_manager, - "modem-added", - G_CALLBACK (phosh_wwan_ofono_modem_added_cb), - self); + self->manager_object_added_signal_id = g_signal_connect_swapped (self->proxy_manager, + "modem-added", + G_CALLBACK (on_modem_added), + self); - self->manager_object_removed_signal_id = - g_signal_connect_swapped (self->proxy_manager, - "modem-removed", - G_CALLBACK (phosh_wwan_ofono_modem_removed_cb), - self); + self->manager_object_removed_signal_id = g_signal_connect_swapped (self->proxy_manager, + "modem-removed", + G_CALLBACK (on_modem_removed), + self); - phosh_ofono_dbus_manager_call_get_modems ( + phosh_dbus_ofono_manager_call_get_modems ( self->proxy_manager, NULL, - (GAsyncReadyCallback)phosh_wwan_ofono_on_get_modems_finish, + (GAsyncReadyCallback)on_get_modems_ready, self); } @@ -571,13 +566,13 @@ phosh_wwan_ofono_constructed (GObject *object) G_OBJECT_CLASS (phosh_wwan_ofono_parent_class)->constructed (object); - phosh_ofono_dbus_manager_proxy_new_for_bus ( + phosh_dbus_ofono_manager_proxy_new_for_bus ( G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, BUS_NAME, OBJECT_PATH, NULL, - (GAsyncReadyCallback)phosh_wwan_ofono_on_ofono_manager_created, + (GAsyncReadyCallback)on_ofono_manager_created, self); } -- GitLab From 2325a25bda292ce3378c42e93963e19b292f597f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Fri, 20 Dec 2024 15:08:45 +0100 Subject: [PATCH 02/14] wwan/ofono: Avoid GAsyncReadyCallback casts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather cast the user data argument which gives us a type check and fewer lines of code instead. Signed-off-by: Guido Günther Part-of: --- src/wwan/phosh-wwan-ofono.c | 43 ++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/wwan/phosh-wwan-ofono.c b/src/wwan/phosh-wwan-ofono.c index df7c2eeac..3670b0f98 100644 --- a/src/wwan/phosh-wwan-ofono.c +++ b/src/wwan/phosh-wwan-ofono.c @@ -199,8 +199,10 @@ static void on_netreg_prop_changed (PhoshDBusOfonoNetworkRegistration *proxy, const char *property, GVariant *value, - PhoshWWanOfono *self) + gpointer user_data) { + PhoshWWanOfono *self = PHOSH_WWAN_OFONO (user_data); + g_autoptr (GVariant) inner = g_variant_get_variant (value); phosh_wwan_ofono_dbus_netreg_update_prop (proxy, property, inner, self); } @@ -313,9 +315,7 @@ phosh_wwan_ofono_destroy_modem (PhoshWWanOfono *self) static void -on_sim_get_properties_ready (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +on_sim_get_properties_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { g_autoptr (GError) err = NULL; g_autoptr (GVariant) properties = NULL; @@ -346,10 +346,9 @@ on_sim_get_properties_ready (GObject *source_object, static void -on_proxy_sim_new_for_bus_ready (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_proxy_sim_new_for_bus_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { + PhoshWWanOfono *self = PHOSH_WWAN_OFONO (user_data); g_autoptr (GError) err = NULL; self->proxy_sim = phosh_dbus_ofono_sim_manager_proxy_new_for_bus_finish (res, &err); @@ -375,10 +374,9 @@ on_proxy_sim_new_for_bus_ready (GObject *source_object, static void -on_netreg_get_properties_ready (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_netreg_get_properties_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { + PhoshWWanOfono *self = PHOSH_WWAN_OFONO (user_data); g_autoptr (GError) err = NULL; g_autoptr (GVariant) properties = NULL; g_autoptr (GVariant) value = NULL; @@ -406,10 +404,9 @@ on_netreg_get_properties_ready (GObject *source_object, static void -on_proxy_netreg_new_for_bus_ready (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_proxy_netreg_new_for_bus_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { + PhoshWWanOfono *self = PHOSH_WWAN_OFONO (user_data); g_autoptr (GError) err = NULL; self->proxy_netreg = phosh_dbus_ofono_network_registration_proxy_new_for_bus_finish ( @@ -426,7 +423,7 @@ on_proxy_netreg_new_for_bus_ready (GObject *source_object, phosh_dbus_ofono_network_registration_call_get_properties ( self->proxy_netreg, NULL, - (GAsyncReadyCallback)on_netreg_get_properties_ready, + on_netreg_get_properties_ready, self); self->proxy_netreg_props_signal_id = g_signal_connect (self->proxy_netreg, @@ -450,7 +447,7 @@ phosh_wwan_ofono_init_modem (PhoshWWanOfono *self, const char *object_path) BUS_NAME, object_path, NULL, - (GAsyncReadyCallback)on_proxy_netreg_new_for_bus_ready, + on_proxy_netreg_new_for_bus_ready, g_object_ref (self)); phosh_dbus_ofono_sim_manager_proxy_new_for_bus ( @@ -459,7 +456,7 @@ phosh_wwan_ofono_init_modem (PhoshWWanOfono *self, const char *object_path) BUS_NAME, object_path, NULL, - (GAsyncReadyCallback)on_proxy_sim_new_for_bus_ready, + on_proxy_sim_new_for_bus_ready, g_object_ref (self)); phosh_wwan_ofono_update_present (self, TRUE); @@ -494,10 +491,9 @@ on_modem_removed (PhoshWWanOfono *self, static void -on_get_modems_ready (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_get_modems_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { + PhoshWWanOfono *self = PHOSH_WWAN_OFONO (user_data); g_autoptr (GError) err = NULL; g_autoptr (GVariant) modems = NULL; GVariantIter i; @@ -525,10 +521,9 @@ on_get_modems_ready (GObject *source_object, static void -on_ofono_manager_created (GObject *source_object, - GAsyncResult *res, - PhoshWWanOfono *self) +on_ofono_manager_created (GObject *source_object, GAsyncResult *res, gpointer user_data) { + PhoshWWanOfono *self = PHOSH_WWAN_OFONO (user_data); g_autoptr (GError) err = NULL; g_debug ("manager created for %p", source_object); @@ -554,7 +549,7 @@ on_ofono_manager_created (GObject *source_object, phosh_dbus_ofono_manager_call_get_modems ( self->proxy_manager, NULL, - (GAsyncReadyCallback)on_get_modems_ready, + on_get_modems_ready, self); } @@ -572,7 +567,7 @@ phosh_wwan_ofono_constructed (GObject *object) BUS_NAME, OBJECT_PATH, NULL, - (GAsyncReadyCallback)on_ofono_manager_created, + on_ofono_manager_created, self); } -- GitLab From 047ec0339e852b1d32b69de2e9b7775510cd4f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Fri, 20 Dec 2024 15:11:49 +0100 Subject: [PATCH 03/14] wwan/ofono: Avoid dangling indents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lines are all below 100 chars Gbp-Dch: Ignore Signed-off-by: Guido Günther Part-of: --- src/wwan/phosh-wwan-ofono.c | 73 +++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/src/wwan/phosh-wwan-ofono.c b/src/wwan/phosh-wwan-ofono.c index 3670b0f98..b25bd3196 100644 --- a/src/wwan/phosh-wwan-ofono.c +++ b/src/wwan/phosh-wwan-ofono.c @@ -383,11 +383,10 @@ on_netreg_get_properties_ready (GObject *source_object, GAsyncResult *res, gpoin char *property; GVariantIter i; - if (!phosh_dbus_ofono_network_registration_call_get_properties_finish ( - self->proxy_netreg, - &properties, - res, - &err)) { + if (!phosh_dbus_ofono_network_registration_call_get_properties_finish (self->proxy_netreg, + &properties, + res, + &err)) { g_warning ("Failed to get netreg proxy properties for %s: %s",self->object_path, err->message); g_object_unref (self); return; @@ -409,22 +408,19 @@ on_proxy_netreg_new_for_bus_ready (GObject *source_object, GAsyncResult *res, gp PhoshWWanOfono *self = PHOSH_WWAN_OFONO (user_data); g_autoptr (GError) err = NULL; - self->proxy_netreg = phosh_dbus_ofono_network_registration_proxy_new_for_bus_finish ( - res, - &err); + self->proxy_netreg = phosh_dbus_ofono_network_registration_proxy_new_for_bus_finish (res, + &err); if (!self->proxy_netreg) { - g_warning ("Failed to get netreg proxy for %s: %s", - self->object_path, err->message); + g_warning ("Failed to get netreg proxy for %s: %s", self->object_path, err->message); g_object_unref (self); return; } - phosh_dbus_ofono_network_registration_call_get_properties ( - self->proxy_netreg, - NULL, - on_netreg_get_properties_ready, - self); + phosh_dbus_ofono_network_registration_call_get_properties (self->proxy_netreg, + NULL, + on_netreg_get_properties_ready, + self); self->proxy_netreg_props_signal_id = g_signal_connect (self->proxy_netreg, "property-changed", @@ -441,23 +437,21 @@ phosh_wwan_ofono_init_modem (PhoshWWanOfono *self, const char *object_path) self->object_path = g_strdup (object_path); self->locked = FALSE; - phosh_dbus_ofono_network_registration_proxy_new_for_bus ( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - BUS_NAME, - object_path, - NULL, - on_proxy_netreg_new_for_bus_ready, - g_object_ref (self)); - - phosh_dbus_ofono_sim_manager_proxy_new_for_bus ( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - BUS_NAME, - object_path, - NULL, - on_proxy_sim_new_for_bus_ready, - g_object_ref (self)); + phosh_dbus_ofono_network_registration_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + BUS_NAME, + object_path, + NULL, + on_proxy_netreg_new_for_bus_ready, + g_object_ref (self)); + + phosh_dbus_ofono_sim_manager_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + BUS_NAME, + object_path, + NULL, + on_proxy_sim_new_for_bus_ready, + g_object_ref (self)); phosh_wwan_ofono_update_present (self, TRUE); } @@ -561,14 +555,13 @@ phosh_wwan_ofono_constructed (GObject *object) G_OBJECT_CLASS (phosh_wwan_ofono_parent_class)->constructed (object); - phosh_dbus_ofono_manager_proxy_new_for_bus ( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - BUS_NAME, - OBJECT_PATH, - NULL, - on_ofono_manager_created, - self); + phosh_dbus_ofono_manager_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + BUS_NAME, + OBJECT_PATH, + NULL, + on_ofono_manager_created, + self); } -- GitLab From d74fcca449845f0b23b819285665b0cd3cced382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:00:58 +0100 Subject: [PATCH 04/14] data: Move schema to mobi.phosh too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We keep the old schema paths to not break existing setups. Signed-off-by: Guido Günther Part-of: --- data/meson.build | 6 +++--- ....puri.phosh.gschema.xml => mobi.phosh.shell.gschema.xml} | 0 debian/phosh.install | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename data/{sm.puri.phosh.gschema.xml => mobi.phosh.shell.gschema.xml} (100%) diff --git a/data/meson.build b/data/meson.build index e2a339127..cdf49e1a3 100644 --- a/data/meson.build +++ b/data/meson.build @@ -106,11 +106,11 @@ generate_enums_schema = gnome.mkenums('sm.puri.phosh.enums.xml', #workaround due to https://github.com/mesonbuild/meson/issues/1687 copy_schema = custom_target('copy-gschema-to-builddir', - input: 'sm.puri.phosh.gschema.xml', - output: 'sm.puri.phosh.gschema.xml', + input: 'mobi.phosh.shell.gschema.xml', + output: 'mobi.phosh.shell.gschema.xml', command: ['cp', '@INPUT@', '@OUTPUT@'] ) -schemas = ['sm.puri.phosh.gschema.xml'] +schemas = ['mobi.phosh.shell.gschema.xml'] compile_schemas = custom_target('glib-compile-schemas', build_by_default: true, output: 'gschemas.compiled', diff --git a/data/sm.puri.phosh.gschema.xml b/data/mobi.phosh.shell.gschema.xml similarity index 100% rename from data/sm.puri.phosh.gschema.xml rename to data/mobi.phosh.shell.gschema.xml diff --git a/debian/phosh.install b/debian/phosh.install index db40a5128..dce51fffa 100644 --- a/debian/phosh.install +++ b/debian/phosh.install @@ -7,7 +7,7 @@ usr/share/locale usr/share/wayland-sessions/phosh.desktop usr/share/phosh/phoc.ini usr/share/glib-2.0/schemas/sm.puri.phosh.enums.xml -usr/share/glib-2.0/schemas/sm.puri.phosh.gschema.xml +usr/share/glib-2.0/schemas/mobi.phosh.shell.gschema.xml usr/share/gnome-session/sessions/phosh.session usr/share/applications/mobi.phosh.Shell.desktop usr/share/dbus-1/services/mobi.phosh.Shell.CalendarServer.service -- GitLab From c8f6b01189f7ae7bfaa8607b3837a7c862f2924a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:00:59 +0100 Subject: [PATCH 05/14] data: Use consistent indent in schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gbp-Dch: Ignore Signed-off-by: Guido Günther Part-of: --- data/mobi.phosh.shell.gschema.xml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/data/mobi.phosh.shell.gschema.xml b/data/mobi.phosh.shell.gschema.xml index 8ec838b54..f16b3b1e0 100644 --- a/data/mobi.phosh.shell.gschema.xml +++ b/data/mobi.phosh.shell.gschema.xml @@ -1,6 +1,5 @@ - + [ 'org.gnome.Calls.desktop', 'sm.puri.Chatty.desktop', @@ -29,13 +28,13 @@ [] - List of desktop file IDs for applications that are adaptive for phone - usage but not marked as such in their desktop file. + List of desktop file IDs for applications that are adaptive for phone + usage but not marked as such in their desktop file. The applications corresponding to these identifiers will be displayed in the app grid panel even when in mobile mode that only - lists touch capable apps that adapt to small screen sizes. + lists touch capable apps that adapt to small screen sizes. @@ -103,11 +102,9 @@ sooner, greater than 1.0 make the unfold trigger later. - - + false Whether emergency calls are enabled @@ -118,9 +115,7 @@ - - + false Whether to scramble the keypad @@ -138,7 +133,6 @@ or password by simply swiping up. - @@ -147,8 +141,7 @@ - + ['urgency'] What notification properties wake up the screen @@ -175,8 +168,7 @@ - + [] List of enabled lockscreen plugins -- GitLab From e38fde32c8c4f75c17af26eeb9ec30d29e419f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:00:59 +0100 Subject: [PATCH 06/14] data: Move enums into canonical namespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- data/meson.build | 4 ++-- data/mobi.phosh.shell.gschema.xml | 12 ++++++------ debian/phosh.install | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/data/meson.build b/data/meson.build index cdf49e1a3..1979883d8 100644 --- a/data/meson.build +++ b/data/meson.build @@ -92,11 +92,11 @@ configure_file( schema_enum_headers = files( '..' / 'src' / 'phosh-settings-enums.h', ) -generate_enums_schema = gnome.mkenums('sm.puri.phosh.enums.xml', +generate_enums_schema = gnome.mkenums('mobi.phosh.shell.enums.xml', sources: schema_enum_headers, comments: '', fhead: '', - vhead: ' <@type@ id="sm.puri.phosh.@EnumName@">', + vhead: ' <@type@ id="mobi.phosh.shell.@EnumName@">', vprod: ' ', vtail: ' ', ftail: '', diff --git a/data/mobi.phosh.shell.gschema.xml b/data/mobi.phosh.shell.gschema.xml index f16b3b1e0..e90e208e0 100644 --- a/data/mobi.phosh.shell.gschema.xml +++ b/data/mobi.phosh.shell.gschema.xml @@ -13,7 +13,7 @@ - + ['adaptive'] How to filter apps in the overview. The default 'adaptive' shows only @@ -38,7 +38,7 @@ - + 'modemmanager' Which backend to use for interfacing with the cellular modem @@ -84,7 +84,7 @@ - + 'device' What information to use to layout UI elements. @@ -135,14 +135,14 @@ - + - + ['urgency'] What notification properties wake up the screen @@ -158,7 +158,7 @@ will wake up the screen. - + 'critical' Notification urgency that wakes up the screen diff --git a/debian/phosh.install b/debian/phosh.install index dce51fffa..3c3c9beac 100644 --- a/debian/phosh.install +++ b/debian/phosh.install @@ -6,7 +6,7 @@ usr/share/icons/hicolor/symbolic/apps/mobi.phosh.Shell-symbolic.svg usr/share/locale usr/share/wayland-sessions/phosh.desktop usr/share/phosh/phoc.ini -usr/share/glib-2.0/schemas/sm.puri.phosh.enums.xml +usr/share/glib-2.0/schemas/mobi.phosh.shell.enums.xml usr/share/glib-2.0/schemas/mobi.phosh.shell.gschema.xml usr/share/gnome-session/sessions/phosh.session usr/share/applications/mobi.phosh.Shell.desktop -- GitLab From 43d95303225880492afb0fca63652b5844439b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:01:00 +0100 Subject: [PATCH 07/14] docs: Update schema locations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- docs/phosh.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/phosh.rst b/docs/phosh.rst index d48957291..240806d68 100644 --- a/docs/phosh.rst +++ b/docs/phosh.rst @@ -36,13 +36,13 @@ OPTIONS CONFIGURATION ------------- -``phosh`` is configured via ``GSettings``. The core settings are within th ``sm.puri.phosh`` schema. +``phosh`` is configured via ``GSettings``. The core settings are within the ``mobi.phosh.shell`` and ``sm.puri.phosh`` schema. See also https://gitlab.gnome.org/World/Phosh/phosh/-/wikis/Configuration Plugins ^^^^^^^ -Plugins are configured via the ``sm.puri.phosh.plugins`` gsettings +Plugins are configured via the ``mobi.phosh.plugins`` and ``sm.puri.phosh.plugins`` gsettings schema. The ``lock-screen`` key enables the plugins on the lock screen e.g. -- GitLab From a15a9f4759241559b048a8ddace93bfde50eb6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:01:01 +0100 Subject: [PATCH 08/14] system-modal-dialog: Allow to get dialog title This makes it consistent with the setter Part-of: --- src/system-modal-dialog.c | 23 +++++++++++++++++++++-- src/system-modal-dialog.h | 15 ++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/system-modal-dialog.c b/src/system-modal-dialog.c index a9fe26646..bd0e9f04d 100644 --- a/src/system-modal-dialog.c +++ b/src/system-modal-dialog.c @@ -126,11 +126,10 @@ phosh_system_modal_dialog_get_property (GObject *obj, GParamSpec *pspec) { PhoshSystemModalDialog *self = PHOSH_SYSTEM_MODAL_DIALOG (obj); - PhoshSystemModalDialogPrivate *priv = phosh_system_modal_dialog_get_instance_private (self); switch (prop_id) { case PROP_TITLE: - g_value_set_string (value, priv->title); + g_value_set_string (value, phosh_system_modal_dialog_get_title (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); @@ -365,6 +364,26 @@ phosh_system_modal_dialog_get_buttons (PhoshSystemModalDialog *self) return gtk_container_get_children (GTK_CONTAINER (priv->box_buttons)); } +/** + * phosh_system_modal_dialog_get_title: + * @self: The dialog + * + * Get the dialog's title. + * + * Returns: The dialog's title + * + * Since: 0.44.0 + */ +const char * +phosh_system_modal_dialog_get_title (PhoshSystemModalDialog *self) +{ + PhoshSystemModalDialogPrivate *priv; + + g_return_val_if_fail (PHOSH_IS_SYSTEM_MODAL_DIALOG (self), NULL); + priv = phosh_system_modal_dialog_get_instance_private (PHOSH_SYSTEM_MODAL_DIALOG (self)); + + return priv->title; +} void phosh_system_modal_dialog_set_title (PhoshSystemModalDialog *self, const gchar *title) diff --git a/src/system-modal-dialog.h b/src/system-modal-dialog.h index af3573ccf..a601a59a2 100644 --- a/src/system-modal-dialog.h +++ b/src/system-modal-dialog.h @@ -23,10 +23,11 @@ struct _PhoshSystemModalDialogClass { }; -GtkWidget *phosh_system_modal_dialog_new (void); -void phosh_system_modal_dialog_set_content (PhoshSystemModalDialog *self, GtkWidget *content); -void phosh_system_modal_dialog_add_button (PhoshSystemModalDialog *self, GtkWidget *button, gint position); -void phosh_system_modal_dialog_set_title (PhoshSystemModalDialog *self, const gchar *title); -void phosh_system_modal_dialog_remove_button (PhoshSystemModalDialog *self, GtkWidget *button); -GList *phosh_system_modal_dialog_get_buttons (PhoshSystemModalDialog *self); -void phosh_system_modal_dialog_close (PhoshSystemModalDialog *self); +GtkWidget *phosh_system_modal_dialog_new (void); +void phosh_system_modal_dialog_set_content (PhoshSystemModalDialog *self, GtkWidget *content); +void phosh_system_modal_dialog_add_button (PhoshSystemModalDialog *self, GtkWidget *button, gint position); +void phosh_system_modal_dialog_set_title (PhoshSystemModalDialog *self, const gchar *title); +const char *phosh_system_modal_dialog_get_title (PhoshSystemModalDialog *self); +void phosh_system_modal_dialog_remove_button (PhoshSystemModalDialog *self, GtkWidget *button); +GList *phosh_system_modal_dialog_get_buttons (PhoshSystemModalDialog *self); +void phosh_system_modal_dialog_close (PhoshSystemModalDialog *self); -- GitLab From 51da91508604bb95143ff1420282ec3df859d485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:01:01 +0100 Subject: [PATCH 09/14] wwan-mm: Switch to MM objects This frees us from creating the proxies manually and gives somewhat nicer function names. Part-of: --- src/wwan/phosh-wwan-mm.c | 143 ++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 79 deletions(-) diff --git a/src/wwan/phosh-wwan-mm.c b/src/wwan/phosh-wwan-mm.c index ee70a0c86..dfa118d63 100644 --- a/src/wwan/phosh-wwan-mm.c +++ b/src/wwan/phosh-wwan-mm.c @@ -44,12 +44,13 @@ static GParamSpec *props[PROP_LAST_PROP]; typedef struct _PhoshWWanMM { PhoshWWanManager parent; - MmGdbusModem *proxy_modem; - MmGdbusModem3gpp *proxy_3gpp; + MMObject *object; + MMModem *modem; + MMModem3gpp *modem_3gpp; + MMManager *manager; GCancellable *cancel; - char *object_path; guint signal_quality; const char *access_tec; gboolean unlocked; @@ -68,15 +69,11 @@ G_DEFINE_TYPE_WITH_CODE (PhoshWWanMM, phosh_wwan_mm, PHOSH_TYPE_WWAN_MANAGER, static void phosh_wwan_mm_update_signal_quality (PhoshWWanMM *self) { - GVariant *v; - g_return_if_fail (self); - g_return_if_fail (self->proxy_modem); - v = mm_gdbus_modem_get_signal_quality (self->proxy_modem); - if (v) { - g_variant_get (v, "(ub)", &self->signal_quality, NULL); - g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SIGNAL_QUALITY]); - } + g_return_if_fail (self->modem); + + self->signal_quality = mm_modem_get_signal_quality (self->modem, NULL); + g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SIGNAL_QUALITY]); } @@ -114,9 +111,9 @@ phosh_wwan_mm_update_access_tec (PhoshWWanMM *self) guint access_tec; g_return_if_fail (self); - g_return_if_fail (self->proxy_modem); + g_return_if_fail (self->modem); - access_tec = mm_gdbus_modem_get_access_technologies (self->proxy_modem); + access_tec = mm_modem_get_access_technologies (self->modem); self->access_tec = phosh_wwan_mm_user_friendly_access_tec (access_tec); g_debug ("Access tec is %s", self->access_tec); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACCESS_TEC]); @@ -129,8 +126,8 @@ phosh_wwan_mm_update_operator (PhoshWWanMM *self) const char *operator; g_return_if_fail (self); - g_return_if_fail (self->proxy_3gpp); - operator = mm_gdbus_modem3gpp_get_operator_name (self->proxy_3gpp); + g_return_if_fail (self->modem_3gpp); + operator = mm_modem_3gpp_get_operator_name (self->modem_3gpp); if (g_strcmp0 (operator, self->operator)) { g_debug("Operator is '%s'", operator); @@ -148,11 +145,11 @@ phosh_wwan_mm_update_lock_status (PhoshWWanMM *self) int state; g_return_if_fail (self); - g_return_if_fail (self->proxy_modem); + g_return_if_fail (self->modem); /* Whether any kind of PIN is required */ - unlock_required = mm_gdbus_modem_get_unlock_required (self->proxy_modem); + unlock_required = mm_modem_get_unlock_required (self->modem); /* Whether the sim card is currently locked */ - state = mm_gdbus_modem_get_state (self->proxy_modem); + state = mm_modem_get_state (self->modem); self->unlocked = !!(unlock_required == MM_MODEM_LOCK_NONE || (state != MM_MODEM_STATE_LOCKED && state != MM_MODEM_STATE_FAILED)); @@ -167,8 +164,8 @@ phosh_wwan_mm_update_sim_status (PhoshWWanMM *self) const char *sim; g_return_if_fail (self); - g_return_if_fail (self->proxy_modem); - sim = mm_gdbus_modem_get_sim (self->proxy_modem); + g_return_if_fail (self->modem); + sim = mm_modem_get_sim_path (self->modem); g_debug ("SIM path %s", sim); self->sim = !!g_strcmp0 (sim, "/"); g_debug ("SIM is %spresent", self->sim ? "" : "not "); @@ -197,7 +194,7 @@ phosh_wwan_mm_update_enabled (PhoshWWanMM *self) g_return_if_fail (self); - state = mm_gdbus_modem_get_state (self->proxy_modem); + state = mm_modem_get_state (self->modem); enabled = (state > MM_MODEM_STATE_ENABLING) ? TRUE : FALSE; g_debug ("Modem is %senabled, state: %d", enabled ? "" : "not ", state); @@ -294,15 +291,17 @@ phosh_wwan_mm_get_property (GObject *object, static void phosh_wwan_mm_destroy_modem (PhoshWWanMM *self) { - if (self->proxy_modem) - g_signal_handlers_disconnect_by_data (self->proxy_modem, self); - g_clear_object (&self->proxy_modem); + if (self->modem_3gpp) + g_signal_handlers_disconnect_by_data (self->modem_3gpp, self); + g_clear_object (&self->modem_3gpp); - if (self->proxy_3gpp) - g_signal_handlers_disconnect_by_data (self->proxy_3gpp, self); - g_clear_object (&self->proxy_3gpp); + if (self->modem) + g_signal_handlers_disconnect_by_data (self->modem, self); + g_clear_object (&self->modem); - g_clear_pointer (&self->object_path, g_free); + if (self->object) + g_signal_handlers_disconnect_by_data (self->object, self); + g_clear_object (&self->object); phosh_wwan_mm_update_present (self, FALSE); @@ -327,37 +326,26 @@ phosh_wwan_mm_destroy_modem (PhoshWWanMM *self) static void -on_3gpp_proxy_new_for_bus_finish (GObject *source_object, GAsyncResult *res, PhoshWWanMM *self) +modem_init_3gpp (PhoshWWanMM *self, MMObject *object) { - g_autoptr (GError) err = NULL; - - self->proxy_3gpp = mm_gdbus_modem3gpp_proxy_new_for_bus_finish (res, &err); - if (!self->proxy_3gpp) { - g_warning ("Failed to get 3gpp proxy for %s: %s", self->object_path, err->message); - g_object_unref (self); - } + self->modem_3gpp = mm_object_get_modem_3gpp (object); + g_return_if_fail (self->modem_3gpp); - g_signal_connect (self->proxy_3gpp, + g_signal_connect (self->modem_3gpp, "g-properties-changed", G_CALLBACK (on_3gpp_props_changed), self); phosh_wwan_mm_update_operator (self); - g_object_unref (self); } static void -on_modem_proxy_new_for_bus_finish (GObject *source_object, GAsyncResult *res, PhoshWWanMM *self) +modem_init_modem (PhoshWWanMM *self, MMObject *object) { - g_autoptr (GError) err = NULL; + self->modem = mm_object_get_modem (object); + g_return_if_fail (self->modem); - self->proxy_modem = mm_gdbus_modem_proxy_new_for_bus_finish (res, &err); - if (!self->proxy_modem) { - g_warning ("Failed to get modem proxy for %s: %s", self->object_path, err->message); - g_object_unref (self); - } - - g_signal_connect (self->proxy_modem, + g_signal_connect (self->modem, "g-properties-changed", G_CALLBACK (on_modem_props_changed), self); @@ -367,45 +355,44 @@ on_modem_proxy_new_for_bus_finish (GObject *source_object, GAsyncResult *res, Ph phosh_wwan_mm_update_sim_status (self); phosh_wwan_mm_update_present (self, TRUE); phosh_wwan_mm_update_enabled (self); - g_object_unref (self); } static void -phosh_wwan_mm_init_modem (PhoshWWanMM *self, const char *object_path) +on_mm_object_interface_added (PhoshWWanMM *self, GDBusInterface* interface, MMObject *object) { - g_return_if_fail (object_path); - - self->object_path = g_strdup (object_path); - - mm_gdbus_modem_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - BUS_NAME, - object_path, - self->cancel, - (GAsyncReadyCallback)on_modem_proxy_new_for_bus_finish, - g_object_ref (self)); - - mm_gdbus_modem3gpp_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - BUS_NAME, - object_path, - self->cancel, - (GAsyncReadyCallback)on_3gpp_proxy_new_for_bus_finish, - g_object_ref (self)); + g_return_if_fail (PHOSH_IS_WWAN_MM (self)); + + if (self->object != object) + return; + + if (MM_IS_MODEM_3GPP (interface)) { + modem_init_3gpp (self, object); + return; + } } static void on_mm_object_added (PhoshWWanMM *self, GDBusObject *object, MMManager *manager) { - const char *modem_object_path; + g_debug ("Modem added at path: %s", g_dbus_object_get_object_path (object)); + + if (!self->object) { + g_debug ("Tracking modem at: %s", g_dbus_object_get_object_path (object)); + + self->object = g_object_ref (MM_OBJECT (object)); + /* Modem interface is always present */ + modem_init_modem (self, MM_OBJECT (object)); + + g_signal_connect (object, + "interface-added", + G_CALLBACK (on_mm_object_interface_added), + self); - modem_object_path = g_dbus_object_get_object_path (object); - g_debug ("Modem added at path: %s", modem_object_path); - if (self->object_path == NULL) { - g_debug ("Tracking modem at: %s", modem_object_path); - phosh_wwan_mm_init_modem (self, modem_object_path); + /* Coldplug interfaces */ + if (mm_object_peek_modem_3gpp (MM_OBJECT (object))) + modem_init_3gpp (self, MM_OBJECT (object)); } } @@ -413,12 +400,10 @@ on_mm_object_added (PhoshWWanMM *self, GDBusObject *object, MMManager *manager) static void on_mm_object_removed (PhoshWWanMM *self, GDBusObject *object, MMManager *manager) { - const char *modem_object_path; + g_debug ("Modem removed at path: %s", g_dbus_object_get_object_path (object)); - modem_object_path = g_dbus_object_get_object_path (object); - g_debug ("Modem removed at path: %s", modem_object_path); - if (!g_strcmp0 (modem_object_path, self->object_path)) { - g_debug ("Dropping modem at: %s", modem_object_path); + if (self->object == MM_OBJECT (object)) { + g_debug ("Dropping modem at: %s", g_dbus_object_get_object_path (object)); phosh_wwan_mm_destroy_modem (self); } } -- GitLab From 2cee7fd04532a61a658748da9e715f32f8952770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:01:02 +0100 Subject: [PATCH 10/14] wwan-manager: Add signal to notify about new CBMs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The wwan manager should able to notify other parts of the shell that a new cell broadcast message was received. Signed-off-by: Guido Günther Part-of: --- src/wwan/wwan-manager.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/wwan/wwan-manager.c b/src/wwan/wwan-manager.c index 7c55abd6e..c521c5fe4 100644 --- a/src/wwan/wwan-manager.c +++ b/src/wwan/wwan-manager.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2021 Purism SPC + * 2023-2024 The Phosh Developers * * SPDX-License-Identifier: GPL-3.0-or-later * @@ -16,6 +17,12 @@ #include +enum { + NEW_CBM, + N_SIGNALS +}; +static guint signals[N_SIGNALS]; + #define is_type_wwan_connection(s) \ (g_strcmp0 ((s), NM_SETTING_GSM_SETTING_NAME) == 0 || \ g_strcmp0 ((s), NM_SETTING_CDMA_SETTING_NAME) == 0) @@ -376,8 +383,29 @@ phosh_wwan_manager_class_init (PhoshWWanManagerClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); + + /** + * PhoshWwanManager::new-cbm + * @self: The wwan manager + * @message: The message text + * @channel: The channel specifying the source of the CBM + * + * This signal is emitted when a new cell broadcast message is + * received. + * + * Since: 0.44.0 + */ + signals[NEW_CBM] = g_signal_new ("new-cbm", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, + 2, + G_TYPE_STRING, + G_TYPE_UINT); } + static void phosh_wwan_manager_init (PhoshWWanManager *self) { -- GitLab From 55e7502e2158d27740d568a99e1dc6b813091e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:01:03 +0100 Subject: [PATCH 11/14] wwan-mm: Track new CBMs Track new cell broadcast messages and emit 'new-cbm' when the received message is complete This needs a recent ModemManager with Cell Broadcast support so we compile that in conditionally based on whether we find the necessary API in libmm-glib. We can drop this once this feature made it into a released MM version. Part-of: --- meson.build | 23 ++++++ src/wwan/phosh-wwan-mm.c | 157 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) diff --git a/meson.build b/meson.build index d02b41774..bb1da75e3 100644 --- a/meson.build +++ b/meson.build @@ -198,6 +198,20 @@ struct rfkill_event_ext e; have_rfkill_event_ext = cc.compiles(code, name : 'Have rfkill_event_ext') have_memfd_create = cc.has_function('memfd_create', prefix: '''#define _GNU_SOURCE #include ''') +have_mm_cbm = true +# Check CBM support thoroughly as API isn't in a released MM version yet +foreach f: [ + 'mm_cbm_get_channel', + 'mm_cbm_get_path', + 'mm_cbm_get_text', + 'mm_modem_cell_broadcast_list', + 'mm_object_get_modem_cell_broadcast', + 'mm_object_peek_modem_cell_broadcast', +] + if not cc.has_function(f, dependencies: mm_glib_dep) + have_mm_cbm = false + endif +endforeach config_h = configuration_data() config_h.set_quoted('GETTEXT_PACKAGE', 'phosh') @@ -210,6 +224,8 @@ config_h.set('PHOSH_HAVE_MEMFD_CREATE', have_memfd_create, description: 'Whether we have memdfd_create on Linux') config_h.set('PHOSH_USES_ASAN', get_option('b_sanitize') == 'address', description: 'Whether ASAN was enabled via meson') +config_h.set('PHOSH_HAVE_MM_CBM', have_mm_cbm, + description: 'Whether ModemManager supports Cell Broadcast') config_h.set_quoted('PHOSH_DATA_DIR', datadir, description: 'Systemwide data dir') config_h.set_quoted('PHOSH_APP_ID', app_id) @@ -248,6 +264,13 @@ summary({ section: 'Build', ) +summary({ + 'ModemManager with Cellbroadcast support': have_mm_cbm, + }, + bool_yn: true, + section: 'Versions', +) + summary({ 'Compositor:': get_option('compositor'), }, diff --git a/src/wwan/phosh-wwan-mm.c b/src/wwan/phosh-wwan-mm.c index dfa118d63..1ae81c8d8 100644 --- a/src/wwan/phosh-wwan-mm.c +++ b/src/wwan/phosh-wwan-mm.c @@ -47,6 +47,9 @@ typedef struct _PhoshWWanMM { MMObject *object; MMModem *modem; MMModem3gpp *modem_3gpp; +#ifdef PHOSH_HAVE_MM_CBM + MMModemCellBroadcast *cellbroadcast; +#endif MMManager *manager; GCancellable *cancel; @@ -58,6 +61,8 @@ typedef struct _PhoshWWanMM { gboolean present; gboolean enabled; char *operator; + + GListStore *cbms; } PhoshWWanMM; @@ -291,6 +296,11 @@ phosh_wwan_mm_get_property (GObject *object, static void phosh_wwan_mm_destroy_modem (PhoshWWanMM *self) { +#ifdef PHOSH_HAVE_MM_CBM + if (self->cellbroadcast) + g_signal_handlers_disconnect_by_data (self->cellbroadcast, self); + g_clear_object (&self->cellbroadcast); +#endif if (self->modem_3gpp) g_signal_handlers_disconnect_by_data (self->modem_3gpp, self); g_clear_object (&self->modem_3gpp); @@ -303,6 +313,8 @@ phosh_wwan_mm_destroy_modem (PhoshWWanMM *self) g_signal_handlers_disconnect_by_data (self->object, self); g_clear_object (&self->object); + g_clear_object (&self->cbms); + phosh_wwan_mm_update_present (self, FALSE); self->enabled = FALSE; @@ -357,6 +369,142 @@ modem_init_modem (PhoshWWanMM *self, MMObject *object) phosh_wwan_mm_update_enabled (self); } +#ifdef PHOSH_HAVE_MM_CBM +static void +emit_new_cbm_received (PhoshWWanMM *self, MMCbm *cbm) +{ + g_signal_emit_by_name (self, "new-cbm", mm_cbm_get_text (cbm), mm_cbm_get_channel (cbm)); +} + + +static void +on_cbm_state_updated (PhoshWWanMM *self, GParamSpec *pspec, MMCbm *cbm) +{ + guint pos; + + if (mm_cbm_get_state (cbm) != MM_CBM_STATE_RECEIVED) + return; + + g_debug ("Received cbm %u: %s", mm_cbm_get_channel (cbm), mm_cbm_get_text (cbm)); + emit_new_cbm_received (self, cbm); + + /* Once notified we can drop the CBM from the store */ + g_signal_handlers_disconnect_by_data (cbm, self); + g_return_if_fail (g_list_store_find (self->cbms, cbm, &pos)); + g_list_store_remove (self->cbms, pos); +} + + +static void +track_cbm (PhoshWWanMM *self, MMCbm *cbm) +{ + g_debug ("New cbm at %s", mm_cbm_get_path (cbm)); + g_list_store_insert (self->cbms, 0, cbm); + g_signal_connect_object (cbm, + "notify::state", + G_CALLBACK (on_cbm_state_updated), + self, + G_CONNECT_SWAPPED); + on_cbm_state_updated (self, NULL, cbm); +} + + +typedef struct { + PhoshWWanMM *self; + char *cbm_path; +} PhoshWWanMMCbmListData; + + +static void +cbm_list_data_free (PhoshWWanMMCbmListData *data) +{ + g_free (data->cbm_path); + g_free (data); +} + + +static void +on_cbms_listed (GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + MMModemCellBroadcast *cell_broadcast = MM_MODEM_CELL_BROADCAST (source_object); + PhoshWWanMMCbmListData *data = user_data; + PhoshWWanMM *self = data->self; + g_autolist (MMObject) cbm_list = NULL; + g_autoptr (GError) err = NULL; + MMCbm *cbm = NULL; + + cbm_list = mm_modem_cell_broadcast_list_finish (cell_broadcast, res, &err); + if (!cbm_list) { + phosh_async_error_warn (err, "Failed to fetch cell broadcast messages"); + return; + } + + for (GList *l = cbm_list; l; l = l->next) { + cbm = MM_CBM (l->data); + + if (data->cbm_path == NULL || g_strcmp0 (mm_cbm_get_path (cbm), data->cbm_path) == 0) { + track_cbm (self, cbm); + if (data->cbm_path) + break; + } + } + if (!cbm && data->cbm_path) { + g_warning ("Failed to find CBM at %s", data->cbm_path); + } + + cbm_list_data_free (data); +} + + +static void +on_cbm_added (PhoshWWanMM *self, const char *cbm_path, MMModemCellBroadcast *modem_cb) +{ + g_autolist (MMObject) cbm_list = NULL; + PhoshWWanMMCbmListData *data = g_new0 (PhoshWWanMMCbmListData, 1); + + g_return_if_fail (PHOSH_IS_WWAN_MANAGER (self)); + + *data = (PhoshWWanMMCbmListData){ + .self = self, + .cbm_path = g_strdup (cbm_path), + }; + + mm_modem_cell_broadcast_list (self->cellbroadcast, + self->cancel, + on_cbms_listed, + data); +} + + +static void +modem_init_cellbroadcast (PhoshWWanMM *self, MMObject *object) +{ + PhoshWWanMMCbmListData *data = g_new0 (PhoshWWanMMCbmListData, 1); + + self->cellbroadcast = mm_object_get_modem_cell_broadcast (object); + g_assert (self->cellbroadcast); + + self->cbms = g_list_store_new (MM_TYPE_CBM); + + g_debug ("Enabling cell broadcast interface"); + g_signal_connect_object (self->cellbroadcast, + "added", + G_CALLBACK (on_cbm_added), + self, + G_CONNECT_SWAPPED); + + /* Cold plug existing CBMs */ + *data = (PhoshWWanMMCbmListData){ + .self = self, + .cbm_path = NULL, + }; + mm_modem_cell_broadcast_list (self->cellbroadcast, + self->cancel, + on_cbms_listed, + data); +} +#endif + static void on_mm_object_interface_added (PhoshWWanMM *self, GDBusInterface* interface, MMObject *object) @@ -369,6 +517,11 @@ on_mm_object_interface_added (PhoshWWanMM *self, GDBusInterface* interface, MMOb if (MM_IS_MODEM_3GPP (interface)) { modem_init_3gpp (self, object); return; +#ifdef PHOSH_HAVE_MM_CBM + } else if (MM_IS_MODEM_CELL_BROADCAST (interface)) { + modem_init_cellbroadcast (self, object); + return; +#endif } } @@ -393,6 +546,10 @@ on_mm_object_added (PhoshWWanMM *self, GDBusObject *object, MMManager *manager) /* Coldplug interfaces */ if (mm_object_peek_modem_3gpp (MM_OBJECT (object))) modem_init_3gpp (self, MM_OBJECT (object)); +#ifdef PHOSH_HAVE_MM_CBM + if (mm_object_peek_modem_cell_broadcast (MM_OBJECT (object))) + modem_init_cellbroadcast (self, MM_OBJECT (object)); +#endif } } -- GitLab From fc9497be746fecf83323f837055f7f155d9568b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:01:03 +0100 Subject: [PATCH 12/14] data: Add setting for cell broadcast messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- data/mobi.phosh.shell.gschema.xml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/data/mobi.phosh.shell.gschema.xml b/data/mobi.phosh.shell.gschema.xml index e90e208e0..da7991802 100644 --- a/data/mobi.phosh.shell.gschema.xml +++ b/data/mobi.phosh.shell.gschema.xml @@ -1,4 +1,18 @@ + + + + false + Whether cell broadcast messages should be displayed + + When this is disabled the shell will not show any cell + broadcast messages, including important security warnings. + + + + + + [ 'org.gnome.Calls.desktop', @@ -184,5 +198,4 @@ - -- GitLab From b281cc5d3c59cdf3b04284b4c250051bf3ecd806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:01:04 +0100 Subject: [PATCH 13/14] cell-broadcast-prompt: New dialog for cell broadcast message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- po/POTFILES.in | 1 + src/cell-broadcast-prompt.c | 170 ++++++++++++++++++++++++++++++++ src/cell-broadcast-prompt.h | 17 ++++ src/meson.build | 2 + src/phosh.gresources.xml | 1 + src/ui/cell-broadcast-prompt.ui | 36 +++++++ 6 files changed, 227 insertions(+) create mode 100644 src/cell-broadcast-prompt.c create mode 100644 src/cell-broadcast-prompt.h create mode 100644 src/ui/cell-broadcast-prompt.ui diff --git a/po/POTFILES.in b/po/POTFILES.in index a479e4fc2..68bca7d5d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -78,6 +78,7 @@ src/ui/app-grid-button.ui src/ui/app-grid.ui src/ui/audio-settings.ui src/ui/bt-status-page.ui +src/ui/cell-broadcast-prompt.ui src/ui/emergency-menu.ui src/ui/emergency-contact-row.ui src/ui/end-session-dialog.ui diff --git a/src/cell-broadcast-prompt.c b/src/cell-broadcast-prompt.c new file mode 100644 index 000000000..18d4de65e --- /dev/null +++ b/src/cell-broadcast-prompt.c @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2024 Guido Günther + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#define G_LOG_DOMAIN "phosh-cell-broadcast-prompt" + +#include "phosh-config.h" + +#include "cell-broadcast-prompt.h" + +#include + +/** + * PhoshCellBroadcastPrompt: + * + * A modal prompt to display cell broadcast messages + * + * The #PhoshCellBroadcastPrompt is used to show cell + * broacast messages from the mobile network. + * + * Since it's about emergencies it can be shown above the + * lock screen. + */ + +enum { + PROP_0, + PROP_MESSAGE, + PROP_LAST_PROP, +}; +static GParamSpec *props[PROP_LAST_PROP]; + + +enum { + CLOSED, + N_SIGNALS +}; +static guint signals[N_SIGNALS] = { 0 }; + + +struct _PhoshCellBroadcastPrompt { + PhoshSystemModalDialog parent; + + GtkLabel *lbl_msg; + char *message; +}; +G_DEFINE_TYPE (PhoshCellBroadcastPrompt, phosh_cell_broadcast_prompt, PHOSH_TYPE_SYSTEM_MODAL_DIALOG); + + +static void +set_message (PhoshCellBroadcastPrompt *self, const char *message) +{ + g_return_if_fail (PHOSH_IS_CELL_BROADCAST_PROMPT (self)); + + if (!g_strcmp0 (self->message, message)) + return; + + g_clear_pointer (&self->message, g_free); + self->message = g_strdup (message); + + gtk_label_set_label (self->lbl_msg, message); + + g_object_notify_by_pspec (G_OBJECT (self), props[PROP_MESSAGE]); +} + + +static void +phosh_cell_broadcast_prompt_set_property (GObject *obj, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PhoshCellBroadcastPrompt *self = PHOSH_CELL_BROADCAST_PROMPT (obj); + + switch (prop_id) { + case PROP_MESSAGE: + set_message (self, g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); + break; + } +} + + +static void +phosh_cell_broadcast_prompt_get_property (GObject *obj, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PhoshCellBroadcastPrompt *self = PHOSH_CELL_BROADCAST_PROMPT (obj); + + switch (prop_id) { + case PROP_MESSAGE: + g_value_set_string (value, self->message ?: ""); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); + break; + } +} + + +static void +on_ok_clicked (PhoshCellBroadcastPrompt *self) +{ + g_signal_emit (self, signals[CLOSED], 0); +} + + +static void +phosh_cell_broadcast_prompt_finalize (GObject *obj) +{ + PhoshCellBroadcastPrompt *self = PHOSH_CELL_BROADCAST_PROMPT (obj); + + g_free (self->message); + + G_OBJECT_CLASS (phosh_cell_broadcast_prompt_parent_class)->finalize (obj); +} + + +static void +phosh_cell_broadcast_prompt_class_init (PhoshCellBroadcastPromptClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->get_property = phosh_cell_broadcast_prompt_get_property; + object_class->set_property = phosh_cell_broadcast_prompt_set_property; + object_class->finalize = phosh_cell_broadcast_prompt_finalize; + + props[PROP_MESSAGE] = + g_param_spec_string ("message", "", "", + "", + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_CONSTRUCT_ONLY); + + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); + + signals[CLOSED] = g_signal_new ("closed", + G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, + NULL, G_TYPE_NONE, 0); + + gtk_widget_class_set_template_from_resource (widget_class, + "/mobi/phosh/ui/cell-broadcast-prompt.ui"); + gtk_widget_class_bind_template_child (widget_class, PhoshCellBroadcastPrompt, lbl_msg); + gtk_widget_class_bind_template_callback (widget_class, on_ok_clicked); + + gtk_widget_class_set_css_name (widget_class, "phosh-cell-broadcast-prompt"); +} + + +static void +phosh_cell_broadcast_prompt_init (PhoshCellBroadcastPrompt *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + + +GtkWidget * +phosh_cell_broadcast_prompt_new (const char *message, const char *title) +{ + return g_object_new (PHOSH_TYPE_CELL_BROADCAST_PROMPT, + "message", message, + "title", title, + NULL); +} diff --git a/src/cell-broadcast-prompt.h b/src/cell-broadcast-prompt.h new file mode 100644 index 000000000..d5599913e --- /dev/null +++ b/src/cell-broadcast-prompt.h @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include +#include "system-modal-dialog.h" + +#define PHOSH_TYPE_CELL_BROADCAST_PROMPT (phosh_cell_broadcast_prompt_get_type ()) + +G_DECLARE_FINAL_TYPE (PhoshCellBroadcastPrompt, phosh_cell_broadcast_prompt, PHOSH, + CELL_BROADCAST_PROMPT, PhoshSystemModalDialog) + +GtkWidget *phosh_cell_broadcast_prompt_new (const char *message, const char *title); diff --git a/src/meson.build b/src/meson.build index 8e7b0241e..dff0e8e21 100644 --- a/src/meson.build +++ b/src/meson.build @@ -105,6 +105,7 @@ libphosh_tool_headers = files( 'call.h', 'calls-manager.h', 'call-notification.h', + 'cell-broadcast-prompt.h', 'clamp.h', 'connectivity-info.h', 'drag-surface.h', @@ -182,6 +183,7 @@ libphosh_tool_sources = files( 'call.c', 'calls-manager.c', 'call-notification.c', + 'cell-broadcast-prompt.c', 'clamp.c', 'connectivity-info.c', 'drag-surface.c', diff --git a/src/phosh.gresources.xml b/src/phosh.gresources.xml index 79e1bb8d7..7bb48e6a4 100644 --- a/src/phosh.gresources.xml +++ b/src/phosh.gresources.xml @@ -12,6 +12,7 @@ ui/bt-device-row.ui ui/bt-status-page.ui ui/call-notification.ui + ui/cell-broadcast-prompt.ui ui/emergency-contact-row.ui ui/emergency-menu.ui ui/end-session-dialog.ui diff --git a/src/ui/cell-broadcast-prompt.ui b/src/ui/cell-broadcast-prompt.ui new file mode 100644 index 000000000..5a8a81f9d --- /dev/null +++ b/src/ui/cell-broadcast-prompt.ui @@ -0,0 +1,36 @@ + + + + + -- GitLab From e9e5ac846d60455da4622e5b16c85a31d9140d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 15 Dec 2024 13:01:05 +0100 Subject: [PATCH 14/14] cell-broadcast-manager: New class handle display of CBM information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Acts on signals from the WWAN stack to show cell broadcast messages (CBMs) as system modal dialogs or (later on) notifications. Signed-off-by: Guido Günther Part-of: --- src/cell-broadcast-manager.c | 173 +++++++++++++++++++++++++++++++++++ src/cell-broadcast-manager.h | 20 ++++ src/meson.build | 2 + src/shell.c | 4 + 4 files changed, 199 insertions(+) create mode 100644 src/cell-broadcast-manager.c create mode 100644 src/cell-broadcast-manager.h diff --git a/src/cell-broadcast-manager.c b/src/cell-broadcast-manager.c new file mode 100644 index 000000000..03a750b85 --- /dev/null +++ b/src/cell-broadcast-manager.c @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#define G_LOG_DOMAIN "phosh-cell-broadcast-manager" + +#include "phosh-config.h" + +#include "cell-broadcast-manager.h" +#include "cell-broadcast-prompt.h" +#include "feedback-manager.h" +#include "shell.h" +#include "wwan/wwan-manager.h" + +#include + +#define PHOSH_CELL_BROOADCAST_SCHEMA_ID "mobi.phosh.shell.cell-broadcast" + +/** + * PhoshCellBroadcastManager: + * + * Handles the display of Cell Broadcast messages + * + * Since: 0.44.0 + */ + +enum { + PROP_0, + PROP_ENABLED, + PROP_LAST_PROP +}; +static GParamSpec *props[PROP_LAST_PROP]; + +struct _PhoshCellBroadcastManager { + GObject parent; + + gboolean enabled; + GSettings *settings; +}; +G_DEFINE_TYPE (PhoshCellBroadcastManager, phosh_cell_broadcast_manager, G_TYPE_OBJECT) + + +static const char * +id_to_title (guint id) +{ + /* Translators: These strings aren't translated */ + switch (id) { + /* TODO: Mapping by country */ + case 4383: + case 4370: + return "National Emergency Alert"; + case 4371: + return "Emergency Alert"; + default: + return "Cell broadcast"; + } +} + + +static void +on_new_cbm (PhoshCellBroadcastManager *self, const char *message, guint id) +{ + GtkWidget *prompt; + + g_debug ("New cbm: %s", message); + + if (!self->enabled) + return; + + prompt = phosh_cell_broadcast_prompt_new (message, id_to_title (id)); + g_signal_connect (prompt, "closed", G_CALLBACK (gtk_widget_destroy), NULL); + gtk_widget_show (prompt); + phosh_trigger_feedback ("message-new-cellbroadcast"); + phosh_shell_activate_action (phosh_shell_get_default (), "screensaver.wakeup-screen", NULL); + + /* We rely on the Chat application to remove the CBM later on */ +} + + +static void +phosh_cell_broadcast_manager_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + PhoshCellBroadcastManager *self = PHOSH_CELL_BROADCAST_MANAGER (object); + + switch (property_id) { + case PROP_ENABLED: + self->enabled = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phosh_cell_broadcast_manager_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + PhoshCellBroadcastManager *self = PHOSH_CELL_BROADCAST_MANAGER (object); + + switch (property_id) { + case PROP_ENABLED: + g_value_set_boolean (value, self->enabled); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phosh_cell_broadcast_manager_finalize (GObject *object) +{ + PhoshCellBroadcastManager *self = PHOSH_CELL_BROADCAST_MANAGER (object); + + g_clear_object (&self->settings); + + G_OBJECT_CLASS (phosh_cell_broadcast_manager_parent_class)->finalize (object); +} + + +static void +phosh_cell_broadcast_manager_class_init (PhoshCellBroadcastManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = phosh_cell_broadcast_manager_get_property; + object_class->set_property = phosh_cell_broadcast_manager_set_property; + object_class->finalize = phosh_cell_broadcast_manager_finalize; + + /** + * PhoshCellbroadcastmanager:enabled: + * + * Whether display of cell broadcast messages is enabled + */ + props[PROP_ENABLED] = + g_param_spec_boolean ("enabled", "", "", + FALSE, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); +} + + +static void +phosh_cell_broadcast_manager_init (PhoshCellBroadcastManager *self) +{ + PhoshShell *shell = phosh_shell_get_default (); + PhoshWWan *wwan = phosh_shell_get_wwan (shell); + + self->settings = g_settings_new (PHOSH_CELL_BROOADCAST_SCHEMA_ID); + g_settings_bind (self->settings, "enabled", self, "enabled", G_SETTINGS_BIND_GET); + + g_signal_connect_object (wwan, "new-cbm", G_CALLBACK (on_new_cbm), self, G_CONNECT_SWAPPED); +} + + +PhoshCellBroadcastManager * +phosh_cell_broadcast_manager_new (void) +{ + return g_object_new (PHOSH_TYPE_CELL_BROADCAST_MANAGER, NULL); +} diff --git a/src/cell-broadcast-manager.h b/src/cell-broadcast-manager.h new file mode 100644 index 000000000..54be67032 --- /dev/null +++ b/src/cell-broadcast-manager.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define PHOSH_TYPE_CELL_BROADCAST_MANAGER (phosh_cell_broadcast_manager_get_type ()) + +G_DECLARE_FINAL_TYPE (PhoshCellBroadcastManager, phosh_cell_broadcast_manager, + PHOSH, CELL_BROADCAST_MANAGER, GObject) + +PhoshCellBroadcastManager *phosh_cell_broadcast_manager_new (void); + +G_END_DECLS diff --git a/src/meson.build b/src/meson.build index dff0e8e21..d63bd6d30 100644 --- a/src/meson.build +++ b/src/meson.build @@ -105,6 +105,7 @@ libphosh_tool_headers = files( 'call.h', 'calls-manager.h', 'call-notification.h', + 'cell-broadcast-manager.h', 'cell-broadcast-prompt.h', 'clamp.h', 'connectivity-info.h', @@ -183,6 +184,7 @@ libphosh_tool_sources = files( 'call.c', 'calls-manager.c', 'call-notification.c', + 'cell-broadcast-manager.c', 'cell-broadcast-prompt.c', 'clamp.c', 'connectivity-info.c', diff --git a/src/shell.c b/src/shell.c index 42608529e..02f92b506 100644 --- a/src/shell.c +++ b/src/shell.c @@ -35,6 +35,7 @@ #include "bt-manager.h" #include "connectivity-info.h" #include "calls-manager.h" +#include "cell-broadcast-manager.h" #include "docked-info.h" #include "docked-manager.h" #include "emergency-calls-manager.h" @@ -177,6 +178,7 @@ typedef struct PhoshLayoutManager *layout_manager; PhoshStyleManager *style_manager; PhoshLauncherEntryManager *launcher_entry_manager; + PhoshCellBroadcastManager *cell_broadcast_manager; /* sensors */ PhoshSensorProxyManager *sensor_proxy_manager; @@ -511,6 +513,7 @@ phosh_shell_dispose (GObject *object) g_clear_object (&priv->notification_banner); /* dispose managers in opposite order of declaration */ + g_clear_object (&priv->cell_broadcast_manager); g_clear_object (&priv->launcher_entry_manager); g_clear_object (&priv->power_menu_manager); g_clear_object (&priv->emergency_calls_manager); @@ -776,6 +779,7 @@ setup_idle_cb (PhoshShell *self) priv->suspend_manager = phosh_suspend_manager_new (); priv->emergency_calls_manager = phosh_emergency_calls_manager_new (); priv->power_menu_manager = phosh_power_menu_manager_new (); + priv->cell_broadcast_manager = phosh_cell_broadcast_manager_new (); setup_primary_monitor_signal_handlers (self); -- GitLab