]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/session_manager.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
8 import tools
.helpers
.ipc
9 from tools
import services
12 import dbus
.exceptions
13 from gi
.repository
import GLib
16 class DbusSessionManager(dbus
.service
.Object
):
17 def __init__(self
, looper
, bus
, object_path
, args
):
20 dbus
.service
.Object
.__init
__(self
, bus
, object_path
)
22 @dbus.service.method("id.waydro.SessionManager", in_signature
='', out_signature
='')
24 do_stop(self
.args
, self
.looper
)
25 stop_container(quit_session
=False)
27 def handle_disconnect(args
, looper
):
29 stop_container(quit_session
=False)
31 def service(args
, looper
):
32 bus
= dbus
.SessionBus()
33 bus
.set_exit_on_disconnect(False)
34 bus
.add_signal_receiver(lambda: handle_disconnect(args
, looper
),
35 signal_name
='Disconnected',
36 dbus_interface
='org.freedesktop.DBus.Local')
37 dbus_obj
= DbusSessionManager(looper
, dbus
.SessionBus(), '/SessionManager', args
)
40 def start(args
, unlocked_cb
=None, background
=True):
42 name
= dbus
.service
.BusName("id.waydro.Session", dbus
.SessionBus(), do_not_queue
=True)
43 except dbus
.exceptions
.NameExistsException
:
44 logging
.error("Session is already running")
49 session
= copy
.copy(tools
.config
.session_defaults
)
51 # TODO: also support WAYLAND_SOCKET?
52 wayland_display
= session
["wayland_display"]
53 if wayland_display
== "None" or not wayland_display
:
54 logging
.warning('WAYLAND_DISPLAY is not set, defaulting to "wayland-0"')
55 wayland_display
= session
["wayland_display"] = "wayland-0"
57 if os
.path
.isabs(wayland_display
):
58 wayland_socket_path
= wayland_display
60 xdg_runtime_dir
= session
["xdg_runtime_dir"]
61 if xdg_runtime_dir
== "None" or not xdg_runtime_dir
:
62 logging
.error(f
"XDG_RUNTIME_DIR is not set; please don't start a Waydroid session with 'sudo'!")
64 wayland_socket_path
= os
.path
.join(xdg_runtime_dir
, wayland_display
)
65 if not os
.path
.exists(wayland_socket_path
):
66 logging
.error(f
"Wayland socket '{wayland_socket_path}' doesn't exist; are you running a Wayland compositor?")
69 waydroid_data
= session
["waydroid_data"]
70 if not os
.path
.isdir(waydroid_data
):
71 os
.makedirs(waydroid_data
)
73 dpi
= tools
.helpers
.props
.host_get(args
, "ro.sf.lcd_density")
75 dpi
= os
.getenv("GRID_UNIT_PX")
77 dpi
= str(int(dpi
) * 20)
80 session
["lcd_density"] = dpi
82 session
["background_start"] = "true" if background
else "false"
84 mainloop
= GLib
.MainLoop()
86 def sigint_handler(data
):
87 do_stop(args
, mainloop
)
88 stop_container(quit_session
=False)
90 def sigusr_handler(data
):
91 do_stop(args
, mainloop
)
93 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGHUP
, sigint_handler
, None)
94 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGINT
, sigint_handler
, None)
95 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGTERM
, sigint_handler
, None)
96 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGUSR1
, sigusr_handler
, None)
98 tools
.helpers
.ipc
.DBusContainerService().Start(session
)
99 except dbus
.DBusException
as e
:
101 if e
.get_dbus_name().startswith("org.freedesktop.DBus.Python"):
102 logging
.error(e
.get_dbus_message().splitlines()[-1])
104 logging
.error("WayDroid container is not listening")
107 services
.user_manager
.start(args
, session
, unlocked_cb
)
108 services
.clipboard_manager
.start(args
)
109 service(args
, mainloop
)
111 def do_stop(args
, looper
):
112 services
.user_manager
.stop(args
)
113 services
.clipboard_manager
.stop(args
)
118 tools
.helpers
.ipc
.DBusSessionService().Stop()
119 except dbus
.DBusException
:
120 stop_container(quit_session
=True)
122 def stop_container(quit_session
):
124 tools
.helpers
.ipc
.DBusContainerService().Stop(quit_session
)
125 except dbus
.DBusException
: