]> glassweightruler.freedombox.rocks Git - waydroid.git/commitdiff
Support upgrading major android versions
authorAlessandro Astone <ales.astone@gmail.com>
Mon, 18 Jul 2022 21:46:14 +0000 (23:46 +0200)
committerAlessandro Astone <ales.astone@gmail.com>
Sat, 23 Jul 2022 07:53:07 +0000 (09:53 +0200)
When restarting the lxc container our binder services will receive a
binder_presence event and will try to re-register on the service manager.
If the service manager was created with aidl2 and the new android version
uses aidl3 this will fail with:
  Failed to add service waydroidusermonitor: -2147483647

When that happens, try to restart the service by getting a new service
manager that can handle the new aidl protocol version.

tools/actions/container_manager.py
tools/actions/upgrader.py
tools/helpers/__init__.py
tools/helpers/protocol.py [new file with mode: 0644]
tools/services/clipboard_manager.py
tools/services/hardware_manager.py
tools/services/user_manager.py

index f242b862bbd63de07ef1a6d8074cecdca2ecc2d0..9539394d90f519e06dd85ac82ff3c63c400e85fb 100644 (file)
@@ -82,33 +82,6 @@ def start(args):
         for path in perm_list:
             chmod(path, mode)
 
         for path in perm_list:
             chmod(path, mode)
 
-    def set_aidl_version():
-        cfg = tools.config.load(args)
-        android_api = 0
-        try:
-            android_api = int(helpers.props.file_get(args,
-                    tools.config.defaults["rootfs"] + "/system/build.prop",
-                    "ro.build.version.sdk"))
-        except:
-            logging.error("Failed to parse android version from system.img")
-
-        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)
     def signal_handler(sig, frame):
         services.hardware_manager.stop(args)
         stop(args)
@@ -159,7 +132,7 @@ def start(args):
         # Mount rootfs
         helpers.images.mount_rootfs(args, cfg["waydroid"]["images_path"])
 
         # Mount rootfs
         helpers.images.mount_rootfs(args, cfg["waydroid"]["images_path"])
 
-        set_aidl_version()
+        helpers.protocol.set_aidl_version(args)
 
         # Mount data
         helpers.mount.bind(args, session_cfg["session"]["waydroid_data"],
 
         # Mount data
         helpers.mount.bind(args, session_cfg["session"]["waydroid_data"],
index 2400023af905fc4d6bc51d440a7c285149f5e8a4..2acf464fa918c6a754c688234be50cec71873574 100644 (file)
@@ -36,4 +36,5 @@ def upgrade(args):
     if status != "STOPPED":
         logging.info("Starting container")
         helpers.images.mount_rootfs(args, args.images_path)
     if status != "STOPPED":
         logging.info("Starting container")
         helpers.images.mount_rootfs(args, args.images_path)
+        helpers.protocol.set_aidl_version(args)
         helpers.lxc.start(args)
         helpers.lxc.start(args)
index c3711007f72920bc4a5d74f123ac41e2a95fbb67..e906e9c85ac1a219d448cf76c9586f9d9fc0613d 100644 (file)
@@ -10,3 +10,4 @@ import tools.helpers.mount
 import tools.helpers.http
 import tools.helpers.ipc
 import tools.helpers.gpu
 import tools.helpers.http
 import tools.helpers.ipc
 import tools.helpers.gpu
+import tools.helpers.protocol
diff --git a/tools/helpers/protocol.py b/tools/helpers/protocol.py
new file mode 100644 (file)
index 0000000..80a1834
--- /dev/null
@@ -0,0 +1,31 @@
+from tools import helpers
+import tools.config
+import logging
+
+# Call me with rootfs mounted!
+def set_aidl_version(args):
+    cfg = tools.config.load(args)
+    android_api = 0
+    try:
+        android_api = int(helpers.props.file_get(args,
+                tools.config.defaults["rootfs"] + "/system/build.prop",
+                "ro.build.version.sdk"))
+    except:
+        logging.error("Failed to parse android version from system.img")
+
+    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)
index 72fe62afc68795036fd1168e2801eff083dcd168..2027959d10591a682d15f4cbd7589d37ce1a7838 100644 (file)
@@ -11,6 +11,8 @@ except Exception as e:
     logging.debug(str(e))
     canClip = False
 
     logging.debug(str(e))
     canClip = False
 
+stopping = False
+
 def start(args):
     def sendClipboardData(value):
         try:
 def start(args):
     def sendClipboardData(value):
         try:
@@ -25,15 +27,20 @@ def start(args):
             logging.debug(str(e))
 
     def service_thread():
             logging.debug(str(e))
 
     def service_thread():
-        IClipboard.add_service(args, sendClipboardData, getClipboardData)
+        while not stopping:
+            IClipboard.add_service(args, sendClipboardData, getClipboardData)
 
     if canClip:
 
     if canClip:
+        global stopping
+        stopping = False
         args.clipboard_manager = threading.Thread(target=service_thread)
         args.clipboard_manager.start()
     else:
         logging.warning("Failed to start Clipboard manager service, check logs")
 
 def stop(args):
         args.clipboard_manager = threading.Thread(target=service_thread)
         args.clipboard_manager.start()
     else:
         logging.warning("Failed to start Clipboard manager service, check logs")
 
 def stop(args):
+    global stopping
+    stopping = True
     try:
         if args.clipboardLoop:
             args.clipboardLoop.quit()
     try:
         if args.clipboardLoop:
             args.clipboardLoop.quit()
index 529348dc102f5e521444842d1d08af6f47f36b7b..45c51109a68e8fd17ba109098e716abfee7c7b4f 100644 (file)
@@ -6,6 +6,7 @@ import tools.actions.container_manager
 from tools import helpers
 from tools.interfaces import IHardware
 
 from tools import helpers
 from tools.interfaces import IHardware
 
+stopping = False
 
 def start(args):
     def enableNFC(enable):
 
 def start(args):
     def enableNFC(enable):
@@ -27,16 +28,22 @@ def start(args):
         helpers.images.replace(args, system_zip, system_time,
                                vendor_zip, vendor_time)
         helpers.images.mount_rootfs(args, args.images_path)
         helpers.images.replace(args, system_zip, system_time,
                                vendor_zip, vendor_time)
         helpers.images.mount_rootfs(args, args.images_path)
+        helpers.protocol.set_aidl_version(args)
         helpers.lxc.start(args)
 
     def service_thread():
         helpers.lxc.start(args)
 
     def service_thread():
-        IHardware.add_service(
-            args, enableNFC, enableBluetooth, suspend, reboot, upgrade)
+        while not stopping:
+            IHardware.add_service(
+                args, enableNFC, enableBluetooth, suspend, reboot, upgrade)
 
 
+    global stopping
+    stopping = False
     args.hardware_manager = threading.Thread(target=service_thread)
     args.hardware_manager.start()
 
 def stop(args):
     args.hardware_manager = threading.Thread(target=service_thread)
     args.hardware_manager.start()
 
 def stop(args):
+    global stopping
+    stopping = True
     try:
         if args.hardwareLoop:
             args.hardwareLoop.quit()
     try:
         if args.hardwareLoop:
             args.hardwareLoop.quit()
index 137c5de7287e1fd39f1f9f2a7e95dccf3f71033d..1171e85981b3e3eb54b0d4cbe2db0320d5ecee22 100644 (file)
@@ -7,6 +7,7 @@ import tools.config
 from tools.interfaces import IUserMonitor
 from tools.interfaces import IPlatform
 
 from tools.interfaces import IUserMonitor
 from tools.interfaces import IPlatform
 
+stopping = False
 
 def start(args, unlocked_cb=None):
 
 
 def start(args, unlocked_cb=None):
 
@@ -89,12 +90,17 @@ def start(args, unlocked_cb=None):
                         os.remove(desktop_file_path)
 
     def service_thread():
                         os.remove(desktop_file_path)
 
     def service_thread():
-        IUserMonitor.add_service(args, userUnlocked, packageStateChanged)
+        while not stopping:
+            IUserMonitor.add_service(args, userUnlocked, packageStateChanged)
 
 
+    global stopping
+    stopping = False
     args.user_manager = threading.Thread(target=service_thread)
     args.user_manager.start()
 
 def stop(args):
     args.user_manager = threading.Thread(target=service_thread)
     args.user_manager.start()
 
 def stop(args):
+    global stopping
+    stopping = True
     try:
         if args.userMonitorLoop:
             args.userMonitorLoop.quit()
     try:
         if args.userMonitorLoop:
             args.userMonitorLoop.quit()