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).
This commit is contained in:
Goffi 2020-01-25 21:08:41 +01:00
commit a485709173

View file

@ -26,6 +26,7 @@ from sat.core.constants import Const as C
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 @@ from twisted.internet import error as int_error
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 @@ class AndroidPlugin(object):
# 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 @@ class AndroidPlugin(object):
actions=["android.net.conn.CONNECTIVITY_CHANGE"])
self.br.start()
@property
def state(self):
return self._state
@ -276,6 +286,25 @@ class AndroidPlugin(object):
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):