[gnome-settings-daemon/benzea/fix-upower-device-add] power: Guard against events from the wrong device type



commit 632d78b9fb0875e89f7c38be1fe3b3bdc6eb4dfa
Author: Benjamin Berg <bberg redhat com>
Date:   Mon Sep 3 15:16:12 2018 +0200

    power: Guard against events from the wrong device type
    
    If a new device is added, then the warning level callback is called
    unconditionally. Because of this, it could happen that an external
    device (like a mouse) could cause the low battery mode in gsd-power to
    be entered. In particular, this will result in the screen to be dimmed
    very agressively.
    
    Fixes issue #83

 plugins/power/gsd-power-manager.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 67d475cf..64d19e0a 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -343,11 +343,15 @@ engine_ups_discharging (GsdPowerManager *manager, UpDevice *device)
 
         /* get device properties */
         g_object_get (device,
+                      "kind", &kind,
                       "percentage", &percentage,
                       "time-to-empty", &time_to_empty,
                       "icon-name", &icon_name,
                       NULL);
 
+        if (kind != UP_DEVICE_KIND_UPS)
+                return;
+
         /* only show text if there is a valid time */
         if (time_to_empty > 0)
                 remaining_text = gpm_get_timestring (time_to_empty);
@@ -790,8 +794,12 @@ static void
 engine_device_warning_changed_cb (UpDevice *device, GParamSpec *pspec, GsdPowerManager *manager)
 {
         UpDeviceLevel warning;
+        UpDeviceKind kind;
 
-        g_object_get (device, "warning-level", &warning, NULL);
+        g_object_get (device,
+                      "warning-level", &warning,
+                      "kind", &kind
+                      NULL);
 
         if (warning == UP_DEVICE_LEVEL_DISCHARGING) {
                 g_debug ("** EMIT: discharging");
@@ -814,7 +822,9 @@ engine_device_warning_changed_cb (UpDevice *device, GParamSpec *pspec, GsdPowerM
                 notify_close_if_showing (&manager->priv->notification_ups_discharging);
         }
 
-        main_battery_or_ups_low_changed (manager, (warning != UP_DEVICE_LEVEL_NONE));
+        if (kind == UP_DEVICE_KIND_BATTERY ||
+            kind == UP_DEVICE_KIND_UPS)
+                main_battery_or_ups_low_changed (manager, (warning != UP_DEVICE_LEVEL_NONE));
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]