diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:45:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:45:20 +0000 |
commit | ae1c76ff830d146d41e88d6fba724c0a54bce868 (patch) | |
tree | 3c354bec95af07be35fc71a4b738268496f1a1c4 /panels/bluetooth/dbusmock-templates | |
parent | Initial commit. (diff) | |
download | gnome-control-center-upstream.tar.xz gnome-control-center-upstream.zip |
Adding upstream version 1:43.6.upstream/1%43.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'panels/bluetooth/dbusmock-templates')
-rw-r--r-- | panels/bluetooth/dbusmock-templates/gsd_rfkill.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/panels/bluetooth/dbusmock-templates/gsd_rfkill.py b/panels/bluetooth/dbusmock-templates/gsd_rfkill.py new file mode 100644 index 0000000..1a57b4c --- /dev/null +++ b/panels/bluetooth/dbusmock-templates/gsd_rfkill.py @@ -0,0 +1,75 @@ +'''gsd-rfkill mock template + +This creates the expected methods and properties of the main +org.gnome.SettingsDaemon.Rfkill object. +''' + +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 3 of the License, or (at your option) any +# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text +# of the license. + +__author__ = 'Bastien Nocera' +__copyright__ = '(c) 2022, Red Hat Inc.' + +import dbus +import os +from dbusmock import mockobject + +BUS_NAME = 'org.gnome.SettingsDaemon.Rfkill' +MAIN_OBJ = '/org/gnome/SettingsDaemon/Rfkill' +MAIN_IFACE = 'org.gnome.SettingsDaemon.Rfkill' +SYSTEM_BUS = False + +ADAPTER_IFACE = 'org.bluez.Adapter1' + +def rfkill_changed(*args, **kwargs): + [iface, changed, _invalidated] = args + + rfkill = mockobject.objects[MAIN_OBJ] + adapter = dbus.bus.BusConnection(os.environ['DBUS_SYSTEM_BUS_ADDRESS']).get_object('org.bluez', '/org/bluez/hci0') + try: + adapter.Get(ADAPTER_IFACE, 'Name') + except: + adapter = None + + if 'BluetoothAirplaneMode' in changed: + if adapter and rfkill.props[MAIN_IFACE]['BluetoothAirplaneMode'] == 1: + adapter.UpdateProperties(ADAPTER_IFACE, + {'Powered': dbus.Boolean(False), + 'Blocked': dbus.Boolean(True)}) + elif adapter: + adapter.UpdateProperties(ADAPTER_IFACE, + {'Blocked': dbus.Boolean(False)}) + if 'BluetoothHardwareAirplaneMode' in changed: + if rfkill.props[MAIN_IFACE]['BluetoothAirplaneMode'] == 0: + rfkill.Set(MAIN_IFACE, 'BluetoothAirplaneMode', dbus.Boolean(False)) + +def load(mock, parameters): + # Loaded! + mock.loaded = True + + props = { + 'AirplaneMode': parameters.get('AirplaneMode', dbus.Boolean(False)), + 'HardwareAirplaneMode': parameters.get('HardwareAirplaneMode', dbus.Boolean(False)), + 'HasAirplaneMode': parameters.get('HasAirplaneMode', dbus.Boolean(True)), + # True if not desktop, server, vm or container + 'ShouldShowAirplaneMode': parameters.get('ShouldShowAirplaneMode', dbus.Boolean(True)), + 'BluetoothAirplaneMode': parameters.get('BluetoothAirplaneMode', dbus.Boolean(False)), + 'BluetoothHardwareAirplaneMode': parameters.get('BluetoothAirplaneMode', dbus.Boolean(False)), + 'BluetoothHasAirplaneMode': parameters.get('BluetoothHasAirplaneMode', dbus.Boolean(True)), + 'WwanAirplaneMode': parameters.get('WwanAirplaneMode', dbus.Boolean(False)), + 'WwanHardwareAirplaneMode': parameters.get('WwanHardwareAirplaneMode', dbus.Boolean(False)), + 'WwanHasAirplaneMode': parameters.get('WwanHasAirplaneMode', dbus.Boolean(False)), + } + mock.AddProperties(MAIN_IFACE, dbus.Dictionary(props, signature='sv')) + + rfkill = mockobject.objects[MAIN_OBJ] + rfkill.hci0_power = True + + session_bus = dbus.SessionBus() + session_bus.add_signal_receiver(rfkill_changed, + signal_name='PropertiesChanged', + path=MAIN_OBJ, + dbus_interface='org.freedesktop.DBus.Properties') |