X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/1f0393876d891d0e32a995d0bf7259cc6505afdc..11dabde2b39a6578b8d1a91d4651cfee4b5eaec8:/tools/interfaces/IPlatform.py diff --git a/tools/interfaces/IPlatform.py b/tools/interfaces/IPlatform.py index 9887d13..307508c 100644 --- a/tools/interfaces/IPlatform.py +++ b/tools/interfaces/IPlatform.py @@ -2,6 +2,8 @@ import gbinder import logging import time from tools import helpers +from gi.repository import GLib +import signal INTERFACE = "lineageos.waydroid.IPlatform" @@ -18,7 +20,8 @@ TRANSACTION_getAppName = 8 TRANSACTION_settingsPutString = 9 TRANSACTION_settingsGetString = 10 TRANSACTION_settingsPutInt = 11 -TRANSACTION_getAppName = 12 +TRANSACTION_settingsGetInt = 12 +TRANSACTION_launchIntent = 13 class IPlatform: def __init__(self, remote): @@ -68,11 +71,11 @@ class IPlatform: reply, status = self.client.transact_sync_reply( TRANSACTION_getAppsInfo, request) + apps_list = [] 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() @@ -182,6 +185,25 @@ class IPlatform: if exception != 0: logging.error("Failed with code: {}".format(exception)) + def launchIntent(self, arg1, arg2): + request = self.client.new_request() + request.append_string16(arg1) + request.append_string16(arg2) + reply, status = self.client.transact_sync_reply( + TRANSACTION_launchIntent, request) + + if status: + logging.error("Sending reply failed") + else: + reader = reply.init_reader() + status, exception = reader.read_int32() + if exception == 0: + rep1 = reader.read_string16() + return rep1 + else: + logging.error("Failed with code: {}".format(exception)) + return None + def getAppName(self, arg1): request = self.client.new_request() request.append_string16(arg1) @@ -275,7 +297,17 @@ class IPlatform: 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) @@ -290,3 +322,15 @@ def get_service(args): 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