]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/interfaces/IPlatform.py
debian: Use new polkitd package
[waydroid.git] / tools / interfaces / IPlatform.py
index a5d6d08a602c7566182815eb1b417a3e8efc2dfb..307508cf33fbc1e33b476a6ddf34d9c5e0a0abea 100644 (file)
@@ -2,6 +2,8 @@ import gbinder
 import logging
 import time
 from tools import helpers
 import logging
 import time
 from tools import helpers
+from gi.repository import GLib
+import signal
 
 
 INTERFACE = "lineageos.waydroid.IPlatform"
 
 
 INTERFACE = "lineageos.waydroid.IPlatform"
@@ -69,11 +71,11 @@ class IPlatform:
         reply, status = self.client.transact_sync_reply(
             TRANSACTION_getAppsInfo, request)
 
         reply, status = self.client.transact_sync_reply(
             TRANSACTION_getAppsInfo, request)
 
+        apps_list = []
         if status:
             logging.error("Sending reply failed")
         else:
             reader = reply.init_reader()
         if status:
             logging.error("Sending reply failed")
         else:
             reader = reply.init_reader()
-            apps_list = []
             status, exception = reader.read_int32()
             if exception == 0:
                 status, apps = reader.read_int32()
             status, exception = reader.read_int32()
             if exception == 0:
                 status, apps = reader.read_int32()
@@ -299,6 +301,13 @@ def get_service(args):
         serviceManager = gbinder.ServiceManager("/dev/" + args.BINDER_DRIVER, args.SERVICE_MANAGER_PROTOCOL, args.BINDER_PROTOCOL)
     except TypeError:
         serviceManager = gbinder.ServiceManager("/dev/" + args.BINDER_DRIVER)
         serviceManager = gbinder.ServiceManager("/dev/" + args.BINDER_DRIVER, args.SERVICE_MANAGER_PROTOCOL, args.BINDER_PROTOCOL)
     except TypeError:
         serviceManager = gbinder.ServiceManager("/dev/" + args.BINDER_DRIVER)
+
+    if not serviceManager.is_present():
+        logging.info("Waiting for binder Service Manager...")
+        if not wait_for_manager(serviceManager):
+            logging.error("Service Manager never appeared")
+            return None
+
     tries = 1000
 
     remote, status = serviceManager.get_service_sync(SERVICE_NAME)
     tries = 1000
 
     remote, status = serviceManager.get_service_sync(SERVICE_NAME)
@@ -313,3 +322,15 @@ def get_service(args):
             return None
 
     return IPlatform(remote)
             return None
 
     return IPlatform(remote)
+
+# Like ServiceManager.wait() but can be interrupted
+def wait_for_manager(sm):
+    mainloop = GLib.MainLoop()
+    hndl = sm.add_presence_handler(lambda: mainloop.quit() if sm.is_present() else None)
+    GLib.timeout_add_seconds(60, lambda: mainloop.quit())
+    GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGINT, lambda _: mainloop.quit(), None)
+    mainloop.run()
+    sm.remove_handler(hndl)
+    if not sm.is_present():
+        return False
+    return True