From: Erfan Abdi Date: Thu, 2 Sep 2021 21:24:45 +0000 (+0430) Subject: tools: Fully restart services X-Git-Tag: 1.1.0~33 X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/commitdiff_plain/677710ab36bba687b04268704bd92b37638854d0?ds=inline tools: Fully restart services --- diff --git a/tools/actions/container_manager.py b/tools/actions/container_manager.py index 776ced9..567c986 100644 --- a/tools/actions/container_manager.py +++ b/tools/actions/container_manager.py @@ -162,8 +162,7 @@ def start(args): raise OSError("container failed to start") tools.config.save_session(session_cfg) - if not hasattr(args, 'hardwareLoop'): - services.hardware_manager.start(args) + services.hardware_manager.start(args) signal.signal(signal.SIGINT, signal_handler) while os.path.exists(tools.config.session_defaults["config_path"]): @@ -179,6 +178,7 @@ def start(args): logging.warning("session manager stopped, stopping container and waiting...") stop(args) + services.hardware_manager.stop(args) start(args) else: logging.error("WayDroid container is {}".format(status)) diff --git a/tools/actions/session_manager.py b/tools/actions/session_manager.py index 7d89757..6d24ca9 100644 --- a/tools/actions/session_manager.py +++ b/tools/actions/session_manager.py @@ -32,11 +32,18 @@ def start(args): cfg["session"]["lcd_density"] = dpi tools.config.save_session(cfg) - services.user_manager.start(args) - services.clipboard_manager.start(args) - + container_state = "IDLE" signal.signal(signal.SIGINT, signal_handler) while os.path.exists(tools.config.session_defaults["config_path"]): + session_cfg = tools.config.load_session() + if container_state != session_cfg["session"]["state"]: + if session_cfg["session"]["state"] == "RUNNING": + services.user_manager.start(args) + services.clipboard_manager.start(args) + elif session_cfg["session"]["state"] == "STOPPED": + services.user_manager.stop(args) + services.clipboard_manager.stop(args) + container_state = session_cfg["session"]["state"] time.sleep(1) services.user_manager.stop(args) services.clipboard_manager.stop(args) diff --git a/tools/interfaces/IClipboard.py b/tools/interfaces/IClipboard.py index 7d09d92..a123501 100644 --- a/tools/interfaces/IClipboard.py +++ b/tools/interfaces/IClipboard.py @@ -35,7 +35,8 @@ def add_service(args, sendClipboardData, getClipboardData): status = serviceManager.add_service_sync(SERVICE_NAME, response) if status: - logging.error("Failed to add service " + SERVICE_NAME) + logging.error("Failed to add service {}: {}".format( + SERVICE_NAME, status)) args.clipboardLoop.quit() response = serviceManager.new_local_object(INTERFACE, response_handler) @@ -44,5 +45,7 @@ def add_service(args, sendClipboardData, getClipboardData): status = serviceManager.add_presence_handler(binder_presence) if status: args.clipboardLoop.run() + serviceManager.remove_handler(status) + del serviceManager else: logging.error("Failed to add presence handler: {}".format(status)) diff --git a/tools/interfaces/IHardware.py b/tools/interfaces/IHardware.py index 347a89c..f7984db 100644 --- a/tools/interfaces/IHardware.py +++ b/tools/interfaces/IHardware.py @@ -53,7 +53,8 @@ def add_service(args, enableNFC, enableBluetooth, suspend, reboot, upgrade): status = serviceManager.add_service_sync(SERVICE_NAME, response) if status: - logging.error("Failed to add service " + SERVICE_NAME) + logging.error("Failed to add service {}: {}".format( + SERVICE_NAME, status)) args.hardwareLoop.quit() response = serviceManager.new_local_object(INTERFACE, response_handler) @@ -62,5 +63,7 @@ def add_service(args, enableNFC, enableBluetooth, suspend, reboot, upgrade): status = serviceManager.add_presence_handler(binder_presence) if status: args.hardwareLoop.run() + serviceManager.remove_handler(status) + del serviceManager else: logging.error("Failed to add presence handler: {}".format(status)) diff --git a/tools/interfaces/IUserMonitor.py b/tools/interfaces/IUserMonitor.py index 6652778..0a16031 100644 --- a/tools/interfaces/IUserMonitor.py +++ b/tools/interfaces/IUserMonitor.py @@ -37,7 +37,8 @@ def add_service(args, userUnlocked, packageStateChanged): status = serviceManager.add_service_sync(SERVICE_NAME, response) if status: - logging.error("Failed to add service " + SERVICE_NAME) + logging.error("Failed to add service {}: {}".format( + SERVICE_NAME, status)) args.userMonitorLoop.quit() response = serviceManager.new_local_object(INTERFACE, response_handler) @@ -46,6 +47,8 @@ def add_service(args, userUnlocked, packageStateChanged): status = serviceManager.add_presence_handler(binder_presence) if status: args.userMonitorLoop.run() + serviceManager.remove_handler(status) + del serviceManager else: logging.error("Failed to add presence handler: {}".format(status))