From 5eb95c31a8eb6c13d27dcceb5510f2d9c6a04d71 Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Fri, 10 Jun 2022 00:35:33 +0200 Subject: [PATCH] Set aidl version based on the android version --- tools/actions/container_manager.py | 33 +++++++++++++++++++++++++++ tools/helpers/drivers.py | 2 ++ tools/helpers/props.py | 11 +++++++++ tools/interfaces/IClipboard.py | 5 +++- tools/interfaces/IHardware.py | 5 +++- tools/interfaces/IPlatform.py | 5 +++- tools/interfaces/IStatusBarService.py | 5 +++- tools/interfaces/IUserMonitor.py | 5 +++- 8 files changed, 66 insertions(+), 5 deletions(-) diff --git a/tools/actions/container_manager.py b/tools/actions/container_manager.py index ee91c52..0588939 100644 --- a/tools/actions/container_manager.py +++ b/tools/actions/container_manager.py @@ -7,6 +7,7 @@ import time import glob import signal import sys +import uuid import tools.config from tools import helpers from tools import services @@ -81,11 +82,43 @@ def start(args): for path in perm_list: chmod(path, mode) + def set_aidl_version(): + cfg = tools.config.load(args) + android_api = 0 + try: + mnt = "/tmp/waydroid-" + str(uuid.uuid1()) + helpers.mount.mount(args, cfg["waydroid"]["images_path"] + "/system.img", mnt) + android_api = int(helpers.props.file_get(args, mnt + "/system/build.prop", + "ro.build.version.sdk")) + except: + logging.error("Failed to parse android version from system.img") + finally: + helpers.mount.umount_all(args, mnt); + + if android_api < 28: + binder_protocol = "aidl" + sm_protocol = "aidl" + elif android_api < 30: + binder_protocol = "aidl2" + sm_protocol = "aidl2" + elif android_api < 31: + binder_protocol = "aidl3" + sm_protocol = "aidl3" + else: + binder_protocol = "aidl3" + sm_protocol = "aidl4" + + cfg["waydroid"]["binder_protocol"] = binder_protocol + cfg["waydroid"]["service_manager_protocol"] = sm_protocol + tools.config.save(args, cfg) + def signal_handler(sig, frame): services.hardware_manager.stop(args) stop(args) sys.exit(0) + set_aidl_version() + status = helpers.lxc.status(args) if status == "STOPPED": # Load binder and ashmem drivers diff --git a/tools/helpers/drivers.py b/tools/helpers/drivers.py index cf708f0..66744b3 100644 --- a/tools/helpers/drivers.py +++ b/tools/helpers/drivers.py @@ -176,3 +176,5 @@ def loadBinderNodes(args): args.BINDER_DRIVER = cfg["waydroid"]["binder"] args.VNDBINDER_DRIVER = cfg["waydroid"]["vndbinder"] args.HWBINDER_DRIVER = cfg["waydroid"]["hwbinder"] + args.BINDER_PROTOCOL = cfg["waydroid"]["binder_protocol"] + args.SERVICE_MANAGER_PROTOCOL = cfg["waydroid"]["service_manager_protocol"] diff --git a/tools/helpers/props.py b/tools/helpers/props.py index 46ab268..de3c3a8 100644 --- a/tools/helpers/props.py +++ b/tools/helpers/props.py @@ -49,3 +49,14 @@ def set(args, prop, value): session_cfg["session"]["state"])) else: logging.error("WayDroid session is stopped") + +def file_get(args, file, prop): + with open(file) as build_prop: + for line in build_prop: + line = line.strip() + if len(line) == 0 or line[0] == "#": + continue + k,v = line.partition("=")[::2] + if k == prop: + return v; + return "" diff --git a/tools/interfaces/IClipboard.py b/tools/interfaces/IClipboard.py index a123501..5bd00b6 100644 --- a/tools/interfaces/IClipboard.py +++ b/tools/interfaces/IClipboard.py @@ -12,7 +12,10 @@ TRANSACTION_getClipboardData = 2 def add_service(args, sendClipboardData, getClipboardData): 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) def response_handler(req, code, flags): logging.debug( diff --git a/tools/interfaces/IHardware.py b/tools/interfaces/IHardware.py index f7984db..9e1f2fe 100644 --- a/tools/interfaces/IHardware.py +++ b/tools/interfaces/IHardware.py @@ -15,7 +15,10 @@ TRANSACTION_upgrade = 5 def add_service(args, enableNFC, enableBluetooth, suspend, reboot, upgrade): 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) def response_handler(req, code, flags): logging.debug( diff --git a/tools/interfaces/IPlatform.py b/tools/interfaces/IPlatform.py index 9887d13..a8a5410 100644 --- a/tools/interfaces/IPlatform.py +++ b/tools/interfaces/IPlatform.py @@ -275,7 +275,10 @@ 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) tries = 1000 remote, status = serviceManager.get_service_sync(SERVICE_NAME) diff --git a/tools/interfaces/IStatusBarService.py b/tools/interfaces/IStatusBarService.py index 0fe30a7..fa5f6f5 100644 --- a/tools/interfaces/IStatusBarService.py +++ b/tools/interfaces/IStatusBarService.py @@ -42,7 +42,10 @@ 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) tries = 1000 remote, status = serviceManager.get_service_sync(SERVICE_NAME) diff --git a/tools/interfaces/IUserMonitor.py b/tools/interfaces/IUserMonitor.py index 0a16031..664fac6 100644 --- a/tools/interfaces/IUserMonitor.py +++ b/tools/interfaces/IUserMonitor.py @@ -12,7 +12,10 @@ TRANSACTION_packageStateChanged = 2 def add_service(args, userUnlocked, packageStateChanged): 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) def response_handler(req, code, flags): logging.debug( -- 2.47.3