]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/session_manager.py
6709e14f1c174761c73b91c5a543ea2f99529635
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
10 import tools
.helpers
.ipc
11 from tools
import services
14 import dbus
.exceptions
15 from gi
.repository
import GLib
18 class DbusSessionManager(dbus
.service
.Object
):
19 def __init__(self
, looper
, bus
, object_path
, args
):
22 dbus
.service
.Object
.__init
__(self
, bus
, object_path
)
24 @dbus.service.method("id.waydro.SessionManager", in_signature
='', out_signature
='')
26 do_stop(self
.args
, self
.looper
)
27 stop_container(quit_session
=False)
29 def service(args
, looper
):
30 dbus_obj
= DbusSessionManager(looper
, dbus
.SessionBus(), '/SessionManager', args
)
33 def start(args
, unlocked_cb
=None):
35 name
= dbus
.service
.BusName("id.waydro.Session", dbus
.SessionBus(), do_not_queue
=True)
36 except dbus
.exceptions
.NameExistsException
:
37 logging
.error("Session is already running")
42 session
= copy
.copy(tools
.config
.session_defaults
)
44 # TODO: also support WAYLAND_SOCKET?
45 wayland_display
= session
["wayland_display"]
46 if wayland_display
== "None" or not wayland_display
:
47 logging
.warning('WAYLAND_DISPLAY is not set, defaulting to "wayland-0"')
48 wayland_display
= session
["wayland_display"] = "wayland-0"
50 if os
.path
.isabs(wayland_display
):
51 wayland_socket_path
= wayland_display
53 xdg_runtime_dir
= session
["xdg_runtime_dir"]
54 if xdg_runtime_dir
== "None" or not xdg_runtime_dir
:
55 logging
.error(f
"XDG_RUNTIME_DIR is not set; please don't start a Waydroid session with 'sudo'!")
57 wayland_socket_path
= os
.path
.join(xdg_runtime_dir
, wayland_display
)
58 if not os
.path
.exists(wayland_socket_path
):
59 logging
.error(f
"Wayland socket '{wayland_socket_path}' doesn't exist; are you running a Wayland compositor?")
62 waydroid_data
= session
["waydroid_data"]
63 if not os
.path
.isdir(waydroid_data
):
64 os
.makedirs(waydroid_data
)
66 dpi
= tools
.helpers
.props
.host_get(args
, "ro.sf.lcd_density")
68 dpi
= os
.getenv("GRID_UNIT_PX")
70 dpi
= str(int(dpi
) * 20)
73 session
["lcd_density"] = dpi
75 mainloop
= GLib
.MainLoop()
77 def sigint_handler(data
):
78 do_stop(args
, mainloop
)
79 stop_container(quit_session
=False)
81 def sigusr_handler(data
):
82 do_stop(args
, mainloop
)
84 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGINT
, sigint_handler
, None)
85 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGTERM
, sigint_handler
, None)
86 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGUSR1
, sigusr_handler
, None)
88 tools
.helpers
.ipc
.DBusContainerService().Start(session
)
89 except dbus
.DBusException
as e
:
91 if e
.get_dbus_name().startswith("org.freedesktop.DBus.Python"):
92 logging
.error(e
.get_dbus_message().splitlines()[-1])
94 logging
.error("WayDroid container is not listening")
97 services
.user_manager
.start(args
, session
, unlocked_cb
)
98 services
.clipboard_manager
.start(args
)
99 service(args
, mainloop
)
101 def do_stop(args
, looper
):
102 services
.user_manager
.stop(args
)
103 services
.clipboard_manager
.stop(args
)
108 tools
.helpers
.ipc
.DBusSessionService().Stop()
109 except dbus
.DBusException
:
110 stop_container(quit_session
=True)
112 def stop_container(quit_session
):
114 tools
.helpers
.ipc
.DBusContainerService().Stop(quit_session
)
115 except dbus
.DBusException
: