]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/interfaces/IStatusBarService.py
logging: Use RotatingFileHandler to trim logfile at 5MB
[waydroid.git] / tools / interfaces / IStatusBarService.py
index 0fe30a76b8e30da0a6621a3613d1ac4374dce6cc..d4dad605f6924cdfd270210aa1ff111045674320 100644 (file)
@@ -2,6 +2,8 @@ import gbinder
 import logging
 import time
 from tools import helpers
+from gi.repository import GLib
+import signal
 
 
 INTERFACE = "com.android.internal.statusbar.IStatusBarService"
@@ -42,7 +44,17 @@ class IStatusBarService:
 
 def get_service(args):
     helpers.drivers.loadBinderNodes(args)
-    serviceManager = gbinder.ServiceManager("/dev/" + args.BINDER_DRIVER)
+    try:
+        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)
@@ -57,3 +69,15 @@ def get_service(args):
             return None
 
     return IStatusBarService(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