diff cagou/core/platform_/android.py @ 370:1a12bbd80943

android: autoconnect profile using the new `profileAutoconnectGet` backend method: thanks to this method, Cagou know which profile is started automatically in backend, and can start it in frontend too.
author Goffi <goffi@goffi.org>
date Mon, 27 Jan 2020 21:17:08 +0100
parents 4d3a0c4f2430
children 1481f09c9175
line wrap: on
line diff
--- a/cagou/core/platform_/android.py	Mon Jan 27 21:17:08 2020 +0100
+++ b/cagou/core/platform_/android.py	Mon Jan 27 21:17:08 2020 +0100
@@ -80,12 +80,33 @@
         # XXX: we use a separated socket instead of bridge because if we
         #      try to call a bridge method in on_pause method, the call data
         #      is not written before the actual pause
-        s = self._frontend_status_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        s = self._frontend_status_socket = socket.socket(
+            socket.AF_UNIX, socket.SOCK_STREAM)
         s.connect(os.path.join(SOCKET_DIR, SOCKET_FILE))
         s.sendall(STATE_RUNNING)
 
+    def profileAutoconnectGetCb(self, profile=None):
+        if profile is not None:
+            G.host.options.profile = profile
+        G.host.postInit()
+
+    def profileAutoconnectGetEb(self, failure_):
+        log.error(f"Error while getting profile to autoconnect: {failure_}")
+        G.host.postInit()
+
+    def do_postInit(self):
+        G.host.bridge.profileAutoconnectGet(
+            callback=self.profileAutoconnectGetCb,
+            errback=self.profileAutoconnectGetEb
+        )
+        return False
+
     def onProfilePlugged(self, profile):
         log.debug("ANDROID profilePlugged")
+        G.host.bridge.setParam(
+            "autoconnect_backend", C.BOOL_TRUE, "Connection", -1, profile,
+            callback=lambda: log.info(f"profile {profile} autonnection set"),
+            errback=lambda: log.error(f"can't set {profile} autonnection"))
         for method, *args in self.cache:
             method(*args)
         del self.cache