Commit 162eb99
committed
frontend/android: refactor network related code
Our MainActivity code is quite complicated and mixes a lot of different
things. This change moves the code related to network management (e.g. to
display alerts when the network is not available) to a dedicated
helper class and declutters the main activity a bit.
It also fixes a bug that caused the app to misdetect mobile connection
or missing connectivity when switching between WIFI and cellular
connection. The bug was caused by the fact that the "onLost" call is not
guaranteed to be executed after the network is actually lost. This can
bring both to false positive and false negatives results, depending on
race conditions. This caused to occasionally not display the "connection
lost" banner when needed, or to e.g. display both the "connection lost" and
the "mobile connection" banner at the same time.
Adding a 250ms delay in the execution of the "onLost" handler is not
nice, but seems to reliably fix the issue on all the tested Android
versions.
This also drops the `netWorkStateReceiver`, as it was registered as a
broadcast receiver for the `CONNECTIVITY_ACTION`, which is now
deprecated.
See https://developer.android.com/reference/android/net/ConnectivityManager#CONNECTIVITY_ACTION
The `usingMobileDataChanged` call, which is used to force the mobile
server to fetch again the network source (wifi/mobile) and optionally
display the "mobile connection" banner, is moved inside the
`checkNetworkConnectivity` call, so that it's executed every time we are
reassessing the connectivity status.1 parent 494f03c commit 162eb99
File tree
4 files changed
+133
-96
lines changed- frontends/android/BitBoxApp/app/src/main/java/ch/shiftcrypto/bitboxapp
4 files changed
+133
-96
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
Lines changed: 8 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
170 | 169 | | |
171 | 170 | | |
172 | 171 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 172 | + | |
181 | 173 | | |
182 | 174 | | |
183 | 175 | | |
| |||
207 | 199 | | |
208 | 200 | | |
209 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
210 | 207 | | |
211 | 208 | | |
212 | 209 | | |
213 | 210 | | |
214 | 211 | | |
| 212 | + | |
| 213 | + | |
215 | 214 | | |
216 | 215 | | |
217 | 216 | | |
| |||
Lines changed: 7 additions & 87 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
| |||
62 | 58 | | |
63 | 59 | | |
64 | 60 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | 61 | | |
107 | 62 | | |
108 | 63 | | |
| |||
129 | 84 | | |
130 | 85 | | |
131 | 86 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | 87 | | |
141 | 88 | | |
142 | 89 | | |
| |||
248 | 195 | | |
249 | 196 | | |
250 | 197 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | 198 | | |
267 | 199 | | |
268 | 200 | | |
| |||
336 | 268 | | |
337 | 269 | | |
338 | 270 | | |
339 | | - | |
340 | | - | |
| 271 | + | |
| 272 | + | |
341 | 273 | | |
342 | 274 | | |
343 | 275 | | |
| |||
355 | 287 | | |
356 | 288 | | |
357 | 289 | | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 290 | + | |
367 | 291 | | |
368 | 292 | | |
369 | 293 | | |
| |||
389 | 313 | | |
390 | 314 | | |
391 | 315 | | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | 316 | | |
396 | | - | |
| 317 | + | |
| 318 | + | |
397 | 319 | | |
398 | 320 | | |
399 | 321 | | |
| |||
404 | 326 | | |
405 | 327 | | |
406 | 328 | | |
407 | | - | |
408 | 329 | | |
409 | 330 | | |
410 | 331 | | |
| |||
472 | 393 | | |
473 | 394 | | |
474 | 395 | | |
475 | | - | |
476 | | - | |
477 | | - | |
| 396 | + | |
| 397 | + | |
478 | 398 | | |
479 | 399 | | |
480 | 400 | | |
| |||
Lines changed: 116 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
0 commit comments