]>
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
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
)
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
);
43 wayland_display
= session
["wayland_display"]
44 if wayland_display
== "None" or not wayland_display
:
45 logging
.warning('WAYLAND_DISPLAY is not set, defaulting to "wayland-0"')
46 waydroid_data
= session
["waydroid_data"]
47 if not os
.path
.isdir(waydroid_data
):
48 os
.makedirs(waydroid_data
)
49 dpi
= tools
.helpers
.props
.host_get(args
, "ro.sf.lcd_density")
51 dpi
= os
.getenv("GRID_UNIT_PX")
53 dpi
= str(int(dpi
) * 20)
56 session
["lcd_density"] = dpi
58 mainloop
= GLib
.MainLoop()
60 def sigint_handler(data
):
61 do_stop(args
, mainloop
)
64 def sigusr_handler(data
):
65 do_stop(args
, mainloop
)
67 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGINT
, sigint_handler
, None)
68 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGTERM
, sigint_handler
, None)
69 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGUSR1
, sigusr_handler
, None)
71 tools
.helpers
.ipc
.DBusContainerService().Start(session
)
72 except dbus
.DBusException
as e
:
73 if e
.get_dbus_name().startswith("org.freedesktop.DBus.Python"):
74 logging
.error(e
.get_dbus_message().splitlines()[-1])
76 logging
.error("WayDroid container is not listening")
79 services
.user_manager
.start(args
, session
, unlocked_cb
)
80 services
.clipboard_manager
.start(args
)
81 service(args
, mainloop
)
83 def do_stop(args
, looper
):
84 services
.user_manager
.stop(args
)
85 services
.clipboard_manager
.stop(args
)
90 tools
.helpers
.ipc
.DBusSessionService().Stop()
91 except dbus
.DBusException
:
96 tools
.helpers
.ipc
.DBusContainerService().Stop()
97 except dbus
.DBusException
: