# HG changeset patch # User Goffi # Date 1579982921 -3600 # Node ID b8606090127886f3d3fe486a0e99543ad8093d74 # Parent 130f9cb6e0ab4aa9af1c1806477f9cbc9ee3a17b plugin android: added a `profileAutoconnectGet` method: this method will be called by frontend to know which profile to connect automatically (when the frontend has been closed and is reopened, this will avoid to have to go through the profileManager again). diff -r 130f9cb6e0ab -r b86060901278 sat/plugins/plugin_misc_android.py --- a/sat/plugins/plugin_misc_android.py Sat Jan 25 21:08:40 2020 +0100 +++ b/sat/plugins/plugin_misc_android.py Sat Jan 25 21:08:41 2020 +0100 @@ -26,6 +26,7 @@ from sat.core.log import getLogger from sat.core import exceptions from sat.memory import params +from twisted.internet import defer from twisted.internet import reactor from twisted.internet import protocol from twisted.internet import error as int_error @@ -33,7 +34,7 @@ log = getLogger(__name__) PLUGIN_INFO = { - C.PI_NAME: "Android ", + C.PI_NAME: "Android", C.PI_IMPORT_NAME: "android", C.PI_TYPE: C.PLUG_TYPE_MISC, C.PI_RECOMMENDATIONS: ["XEP-0352"], @@ -169,6 +170,16 @@ # plugins have done their job host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=-1000) + # profiles autoconnection + host.bridge.addMethod( + "profileAutoconnectGet", + ".plugin", + in_sign="", + out_sign="s", + method=self._profileAutoconnectGet, + async_=True, + ) + # audio manager, to get ring status self.am = activity.getSystemService(Context.AUDIO_SERVICE) @@ -194,7 +205,6 @@ actions=["android.net.conn.CONNECTIVITY_CHANGE"]) self.br.start() - @property def state(self): return self._state @@ -276,6 +286,25 @@ return True + # Profile autoconnection + + def _profileAutoconnectGet(self): + return defer.ensureDeferred(self.profileAutoconnectGet()) + + async def profileAutoconnectGet(self): + """Return profile to connect automatically by frontend, if any""" + autoconnect_dict = await self.host.memory.storage.getIndParamValues( + category='Connection', name='autoconnect_backend', + ) + profiles_autoconnect = [p for p, v in autoconnect_dict.items() if C.bool(v)] + if not profiles_autoconnect: + return None + if len(profiles_autoconnect) > 1: + log.warning( + f"More that one profiles with backend autoconnection set found, picking " + f"up first one (full list: {profiles_autoconnect!r})") + return profiles_autoconnect[0] + # CSI def _setInactive(self):