Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_android.py @ 3106:7f7cdc6ecfd8
plugin android: sound notification + change settings:
- new notification sound
- vibration and notification sound are now activated depending on ringer mode (normal,
vibrate or silent)
- notification sound/vibration can be configured in settings.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 03 Jan 2020 13:21:27 +0100 |
parents | fb49587f55c2 |
children | b86060901278 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
2100 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # SAT plugin for file tansfer | |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
2100 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
20 import sys |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
21 import os |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
22 import os.path |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
23 from pathlib import Path |
2100 | 24 from sat.core.i18n import _, D_ |
25 from sat.core.constants import Const as C | |
26 from sat.core.log import getLogger | |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
27 from sat.core import exceptions |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
28 from sat.memory import params |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
29 from twisted.internet import reactor |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
30 from twisted.internet import protocol |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
31 from twisted.internet import error as int_error |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 |
2100 | 33 log = getLogger(__name__) |
34 | |
35 PLUGIN_INFO = { | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2100
diff
changeset
|
36 C.PI_NAME: "Android ", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2100
diff
changeset
|
37 C.PI_IMPORT_NAME: "android", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2100
diff
changeset
|
38 C.PI_TYPE: C.PLUG_TYPE_MISC, |
3028 | 39 C.PI_RECOMMENDATIONS: ["XEP-0352"], |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2100
diff
changeset
|
40 C.PI_MAIN: "AndroidPlugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2100
diff
changeset
|
41 C.PI_HANDLER: "no", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 C.PI_DESCRIPTION: D_( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 """Manage Android platform specificities, like pause or notifications""" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 ), |
2100 | 45 } |
46 | |
47 if sys.platform != "android": | |
3028 | 48 raise exceptions.CancelError("this module is not needed on this platform") |
2100 | 49 |
2872
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
50 |
2100 | 51 from plyer import notification, vibrator |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
52 from plyer.platforms.android import activity |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
53 from jnius import autoclass |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
54 from android.broadcast import BroadcastReceiver |
2100 | 55 |
2872
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
56 #: delay between a pause event and sending the inactive indication to server, in seconds |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
57 #: we don't send the indication immediately because user can be just checking something |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
58 #: quickly on an other app. |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
59 CSI_DELAY = 30 |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
60 |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
61 PARAM_RING_CATEGORY = "Notifications" |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
62 PARAM_RING_NAME = "sound" |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
63 PARAM_RING_LABEL = D_("sound on notifications") |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
64 RING_OPTS = { |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
65 "normal": D_("Normal"), |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
66 "never": D_("Never"), |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
67 } |
2100 | 68 PARAM_VIBRATE_CATEGORY = "Notifications" |
69 PARAM_VIBRATE_NAME = "vibrate" | |
3028 | 70 PARAM_VIBRATE_LABEL = D_("Vibrate on notifications") |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
71 VIBRATION_OPTS = { |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
72 "always": D_("Always"), |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
73 "vibrate": D_("In vibrate mode"), |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
74 "never": D_("Never"), |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
75 } |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
76 SOCKET_DIR = "/data/data/org.salutatoi.cagou/" |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
77 SOCKET_FILE = ".socket" |
3057
f91d0e6d9b13
plugin android: fixed encoding in states after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
78 STATE_RUNNING = b"running" |
f91d0e6d9b13
plugin android: fixed encoding in states after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
79 STATE_PAUSED = b"paused" |
f91d0e6d9b13
plugin android: fixed encoding in states after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
80 STATE_STOPPED = b"stopped" |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
81 STATES = (STATE_RUNNING, STATE_PAUSED, STATE_STOPPED) |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
82 NET_TYPE_NONE = "no network" |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
83 NET_TYPE_WIFI = "wifi" |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
84 NET_TYPE_MOBILE = "mobile" |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
85 NET_TYPE_OTHER = "other" |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
86 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
87 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
88 Context = autoclass('android.content.Context') |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
89 ConnectivityManager = autoclass('android.net.ConnectivityManager') |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
90 MediaPlayer = autoclass('android.media.MediaPlayer') |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
91 AudioManager = autoclass('android.media.AudioManager') |
2868
5546613f5007
plugin android: workaround to seek() bug, fixing file upload:
Goffi <goffi@goffi.org>
parents:
2856
diff
changeset
|
92 |
5546613f5007
plugin android: workaround to seek() bug, fixing file upload:
Goffi <goffi@goffi.org>
parents:
2856
diff
changeset
|
93 |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
94 class FrontendStateProtocol(protocol.Protocol): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
95 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
96 def __init__(self, android_plugin): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
97 self.android_plugin = android_plugin |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
98 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
99 def dataReceived(self, data): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
100 if data in STATES: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
101 self.android_plugin.state = data |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
102 else: |
3028 | 103 log.warning("Unexpected data: {data}".format(data=data)) |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
104 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
105 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
106 class FrontendStateFactory(protocol.Factory): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
107 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
108 def __init__(self, android_plugin): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
109 self.android_plugin = android_plugin |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
110 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
111 def buildProtocol(self, addr): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
112 return FrontendStateProtocol(self.android_plugin) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
113 |
2100 | 114 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 |
2100 | 116 class AndroidPlugin(object): |
117 | |
118 params = """ | |
119 <params> | |
120 <individual> | |
121 <category name="{category_name}" label="{category_label}"> | |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
122 <param name="{ring_param_name}" label="{ring_param_label}" type="list" security="0"> |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
123 {ring_options} |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
124 </param> |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
125 <param name="{vibrate_param_name}" label="{vibrate_param_label}" type="list" security="0"> |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
126 {vibrate_options} |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
127 </param> |
2100 | 128 </category> |
129 </individual> | |
130 </params> | |
131 """.format( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 category_name=PARAM_VIBRATE_CATEGORY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 category_label=D_(PARAM_VIBRATE_CATEGORY), |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
134 vibrate_param_name=PARAM_VIBRATE_NAME, |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
135 vibrate_param_label=PARAM_VIBRATE_LABEL, |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
136 vibrate_options=params.makeOptions(VIBRATION_OPTS, "always"), |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
137 ring_param_name=PARAM_RING_NAME, |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
138 ring_param_label=PARAM_RING_LABEL, |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
139 ring_options=params.makeOptions(RING_OPTS, "normal"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
140 ) |
2100 | 141 |
142 def __init__(self, host): | |
3028 | 143 log.info(_("plugin Android initialization")) |
2100 | 144 self.host = host |
3028 | 145 self._csi = host.plugins.get('XEP-0352') |
2872
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
146 self._csi_timer = None |
2100 | 147 host.memory.updateParams(self.params) |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
148 try: |
3028 | 149 os.mkdir(SOCKET_DIR, 0o700) |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
150 except OSError as e: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
151 if e.errno == 17: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
152 # dir already exists |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
153 pass |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
154 else: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
155 raise e |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
156 self._state = None |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
157 factory = FrontendStateFactory(self) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
158 socket_path = os.path.join(SOCKET_DIR, SOCKET_FILE) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
159 try: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
160 reactor.listenUNIX(socket_path, factory) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
161 except int_error.CannotListenError as e: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
162 if e.socketError.errno == 98: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
163 # the address is already in use, we need to remove it |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
164 os.unlink(socket_path) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
165 reactor.listenUNIX(socket_path, factory) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
166 else: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
167 raise e |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
168 # we set a low priority because we want the notification to be sent after all |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
169 # plugins have done their job |
2100 | 170 host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=-1000) |
171 | |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
172 # audio manager, to get ring status |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
173 self.am = activity.getSystemService(Context.AUDIO_SERVICE) |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
174 |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
175 # sound notification |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
176 media_dir = Path(host.memory.getConfig("", "media_dir")) |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
177 assert media_dir is not None |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
178 notif_path = media_dir / "sounds" / "notifications" / "music-box.mp3" |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
179 self.notif_player = MediaPlayer() |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
180 self.notif_player.setDataSource(str(notif_path)) |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
181 self.notif_player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION) |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
182 self.notif_player.prepare() |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
183 |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
184 # Connectivity handling |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
185 self.cm = activity.getSystemService(Context.CONNECTIVITY_SERVICE) |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
186 self._net_type = None |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
187 self._checkConnectivity() |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
188 # XXX: we need to keep a reference to BroadcastReceiver to avoid |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
189 # "XXX has no attribute 'invoke'" error (looks like the same issue as |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
190 # https://github.com/kivy/pyjnius/issues/59) |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
191 self.br = BroadcastReceiver( |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
192 callback=lambda *args, **kwargs: reactor.callLater(0, |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
193 self.onConnectivityChange), |
3028 | 194 actions=["android.net.conn.CONNECTIVITY_CHANGE"]) |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
195 self.br.start() |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
196 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
197 |
2100 | 198 @property |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
199 def state(self): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
200 return self._state |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
201 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
202 @state.setter |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
203 def state(self, new_state): |
3057
f91d0e6d9b13
plugin android: fixed encoding in states after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
204 log.debug(f"frontend state has changed: {new_state.decode()}") |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
205 previous_state = self._state |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
206 self._state = new_state |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
207 if new_state == STATE_RUNNING: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
208 self._onRunning(previous_state) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
209 elif new_state == STATE_PAUSED: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
210 self._onPaused(previous_state) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
211 elif new_state == STATE_STOPPED: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
212 self._onStopped(previous_state) |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
213 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
214 @property |
2100 | 215 def cagou_active(self): |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
216 return self._state == STATE_RUNNING |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
217 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
218 def _onRunning(self, previous_state): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
219 if previous_state is not None: |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
220 self.host.bridge.bridgeReactivateSignals() |
2872
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
221 self.setActive() |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
222 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
223 def _onPaused(self, previous_state): |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
224 self.host.bridge.bridgeDeactivateSignals() |
2872
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
225 self.setInactive() |
2841
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
226 |
90115cf4e731
plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
227 def _onStopped(self, previous_state): |
2872
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
228 self.setInactive() |
2100 | 229 |
230 def _notifyMessage(self, mess_data, client): | |
2856
26d6ac4e4a66
plugin android: don't send notification if message comes from ourself (from an other device)
Goffi <goffi@goffi.org>
parents:
2841
diff
changeset
|
231 """Send notification when suitable |
26d6ac4e4a66
plugin android: don't send notification if message comes from ourself (from an other device)
Goffi <goffi@goffi.org>
parents:
2841
diff
changeset
|
232 |
26d6ac4e4a66
plugin android: don't send notification if message comes from ourself (from an other device)
Goffi <goffi@goffi.org>
parents:
2841
diff
changeset
|
233 notification is sent if: |
26d6ac4e4a66
plugin android: don't send notification if message comes from ourself (from an other device)
Goffi <goffi@goffi.org>
parents:
2841
diff
changeset
|
234 - there is a message and it is not a groupchat |
26d6ac4e4a66
plugin android: don't send notification if message comes from ourself (from an other device)
Goffi <goffi@goffi.org>
parents:
2841
diff
changeset
|
235 - message is not coming from ourself |
26d6ac4e4a66
plugin android: don't send notification if message comes from ourself (from an other device)
Goffi <goffi@goffi.org>
parents:
2841
diff
changeset
|
236 """ |
26d6ac4e4a66
plugin android: don't send notification if message comes from ourself (from an other device)
Goffi <goffi@goffi.org>
parents:
2841
diff
changeset
|
237 if (mess_data["message"] and mess_data["type"] != C.MESS_TYPE_GROUPCHAT |
26d6ac4e4a66
plugin android: don't send notification if message comes from ourself (from an other device)
Goffi <goffi@goffi.org>
parents:
2841
diff
changeset
|
238 and not mess_data["from"].userhostJID() == client.jid.userhostJID()): |
3028 | 239 message = next(iter(mess_data["message"].values())) |
2100 | 240 try: |
3028 | 241 subject = next(iter(mess_data["subject"].values())) |
2100 | 242 except StopIteration: |
3028 | 243 subject = "Cagou new message" |
2100 | 244 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
245 notification.notify(title=subject, message=message) |
3106
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
246 |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
247 ringer_mode = self.am.getRingerMode() |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
248 vibrate_mode = ringer_mode == AudioManager.RINGER_MODE_VIBRATE |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
249 |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
250 ring_setting = self.host.memory.getParamA( |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
251 PARAM_RING_NAME, |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
252 PARAM_RING_CATEGORY, |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
253 profile_key=client.profile |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
254 ) |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
255 |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
256 if ring_setting != 'never' and ringer_mode == AudioManager.RINGER_MODE_NORMAL: |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
257 self.notif_player.start() |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
258 |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
259 vibration_setting = self.host.memory.getParamA( |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
260 PARAM_VIBRATE_NAME, |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
261 PARAM_VIBRATE_CATEGORY, |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
262 profile_key=client.profile |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
263 ) |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
264 if (vibration_setting == 'always' |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
265 or vibration_setting == 'vibrate' and vibrate_mode): |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
266 try: |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
267 vibrator.vibrate() |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
268 except Exception as e: |
7f7cdc6ecfd8
plugin android: sound notification + change settings:
Goffi <goffi@goffi.org>
parents:
3095
diff
changeset
|
269 log.warning("Can't use vibrator: {e}".format(e=e)) |
2100 | 270 return mess_data |
271 | |
272 def messageReceivedTrigger(self, client, message_elt, post_treat): | |
273 if not self.cagou_active: | |
274 # we only send notification is the frontend is not displayed | |
275 post_treat.addCallback(self._notifyMessage, client) | |
276 | |
277 return True | |
2872
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
278 |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
279 # CSI |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
280 |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
281 def _setInactive(self): |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
282 self._csi_timer = None |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
283 for client in self.host.getClients(C.PROF_KEY_ALL): |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
284 self._csi.setInactive(client) |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
285 |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
286 def setInactive(self): |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
287 if self._csi is None or self._csi_timer is not None: |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
288 return |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
289 self._csi_timer = reactor.callLater(CSI_DELAY, self._setInactive) |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
290 |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
291 def setActive(self): |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
292 if self._csi is None: |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
293 return |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
294 if self._csi_timer is not None: |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
295 self._csi_timer.cancel() |
2882
0c54970d8e6e
plugin android: fixed csi_timer reset in setActive + crash on call of isActive before session initialisation
Goffi <goffi@goffi.org>
parents:
2872
diff
changeset
|
296 self._csi_timer = None |
2872
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
297 for client in self.host.getClients(C.PROF_KEY_ALL): |
6b00f88316bf
plugin android: use XEP-0352 to indicate (in)active state:
Goffi <goffi@goffi.org>
parents:
2868
diff
changeset
|
298 self._csi.setActive(client) |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
299 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
300 # Connectivity |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
301 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
302 def _handleNetworkChange(self, previous, new): |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
303 """Notify the clients about network changes. |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
304 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
305 This way the client can disconnect/reconnect transport, or change delays |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
306 """ |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
307 if new == NET_TYPE_NONE: |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
308 for client in self.host.getClients(C.PROF_KEY_ALL): |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
309 client.networkDisabled() |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
310 elif previous == NET_TYPE_NONE: |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
311 for client in self.host.getClients(C.PROF_KEY_ALL): |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
312 client.networkEnabled() |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
313 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
314 def _checkConnectivity(self): |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
315 active_network = self.cm.getActiveNetworkInfo() |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
316 if active_network is None: |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
317 net_type = NET_TYPE_NONE |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
318 else: |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
319 net_type_android = active_network.getType() |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
320 if net_type_android == ConnectivityManager.TYPE_WIFI: |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
321 net_type = NET_TYPE_WIFI |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
322 elif net_type_android == ConnectivityManager.TYPE_MOBILE: |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
323 net_type = NET_TYPE_MOBILE |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
324 else: |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
325 net_type = NET_TYPE_OTHER |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
326 if net_type != self._net_type: |
3028 | 327 log.info("connectivity has changed") |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
328 previous = self._net_type |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
329 self._net_type = net_type |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
330 if net_type == NET_TYPE_NONE: |
3028 | 331 log.info("no network active") |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
332 elif net_type == NET_TYPE_WIFI: |
3028 | 333 log.info("WIFI activated") |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
334 elif net_type == NET_TYPE_MOBILE: |
3028 | 335 log.info("mobile data activated") |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
336 else: |
3028 | 337 log.info("network activated (type={net_type_android})" |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
338 .format(net_type_android=net_type_android)) |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
339 self._handleNetworkChange(previous, net_type) |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
340 else: |
3028 | 341 log.debug("_checkConnectivity called without network change ({net_type})" |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
342 .format(net_type = net_type)) |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
343 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
344 |
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
345 def onConnectivityChange(self): |
3028 | 346 log.debug("onConnectivityChange called") |
2887
9aadf11b315b
plugin android: check connectivity
Goffi <goffi@goffi.org>
parents:
2882
diff
changeset
|
347 self._checkConnectivity() |