]> glassweightruler.freedombox.rocks Git - waydroid.git/commitdiff
tools: Fully restart services
authorErfan Abdi <erfangplus@gmail.com>
Thu, 2 Sep 2021 21:24:45 +0000 (01:54 +0430)
committerErfan Abdi <erfangplus@gmail.com>
Thu, 2 Sep 2021 21:34:24 +0000 (02:04 +0430)
tools/actions/container_manager.py
tools/actions/session_manager.py
tools/interfaces/IClipboard.py
tools/interfaces/IHardware.py
tools/interfaces/IUserMonitor.py

index 776ced94a61a6fc7e99080d9f1ec2a6b729f1ae2..567c9863fecfa9b5faebd53fa4ff46873a2664a9 100644 (file)
@@ -162,8 +162,7 @@ def start(args):
             raise OSError("container failed to start")
         tools.config.save_session(session_cfg)
 
             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"]):
 
         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)
 
         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))
         start(args)
     else:
         logging.error("WayDroid container is {}".format(status))
index 7d89757edeeb027f7854d5359c0d85fac4542190..6d24ca9e71e9e43dbee2f78bf60ee239de3f6add 100644 (file)
@@ -32,11 +32,18 @@ def start(args):
     cfg["session"]["lcd_density"] = dpi
     tools.config.save_session(cfg)
 
     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"]):
     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)
         time.sleep(1)
     services.user_manager.stop(args)
     services.clipboard_manager.stop(args)
index 7d09d920c27c20a859dd64f7ba85524d70e3be51..a1235015fe886a800da1fe65cb8f1e34963ef53e 100644 (file)
@@ -35,7 +35,8 @@ def add_service(args, sendClipboardData, getClipboardData):
             status = serviceManager.add_service_sync(SERVICE_NAME, response)
 
             if status:
             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)
                 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()
     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))
     else:
         logging.error("Failed to add presence handler: {}".format(status))
index 347a89c67c2be12f0f5fe80b8c11888d73e8df3d..f7984dba34cafa0e631258eb60fea9f5caef3aee 100644 (file)
@@ -53,7 +53,8 @@ def add_service(args, enableNFC, enableBluetooth, suspend, reboot, upgrade):
             status = serviceManager.add_service_sync(SERVICE_NAME, response)
 
             if status:
             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)
                 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()
     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))
     else:
         logging.error("Failed to add presence handler: {}".format(status))
index 665277801c711fd8e9459cd885a5f90d2a581a57..0a16031bfc28e16bb8ae807f580d84c165c48445 100644 (file)
@@ -37,7 +37,8 @@ def add_service(args, userUnlocked, packageStateChanged):
             status = serviceManager.add_service_sync(SERVICE_NAME, response)
 
             if status:
             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)
                 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()
     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))
 
     else:
         logging.error("Failed to add presence handler: {}".format(status))