diff --git a/mobile/build.gradle b/mobile/build.gradle index 58f63f88..c1e67692 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -90,7 +90,7 @@ dependencies { implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0' implementation 'net.glxn.qrgen:android:2.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0-M2' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0-RC' for (dep in aux) { freedomImplementation dep googleImplementation dep diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index ce242552..fdba849a 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -255,28 +255,29 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene if (Build.VERSION.SDK_INT >= 26 && app.uiMode.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) { showNotification() } - unregisterReceiver() - registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION, - WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) - receiverRegistered = true - try { - p2pManager.requestGroupInfo(channel) { - when { - it == null -> doStart() - it.isGroupOwner -> launch { if (routingManager == null) doStartLocked(it) } - else -> { - Timber.i("Removing old group ($it)") - p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener { - override fun onSuccess() = doStart() - override fun onFailure(reason: Int) = - startFailure(formatReason(R.string.repeater_remove_old_group_failure, reason)) - }) + launch { + registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION, + WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) + receiverRegistered = true + try { + p2pManager.requestGroupInfo(channel) { + when { + it == null -> doStart() + it.isGroupOwner -> launch { if (routingManager == null) doStartLocked(it) } + else -> { + Timber.i("Removing old group ($it)") + p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener { + override fun onSuccess() = doStart() + override fun onFailure(reason: Int) = + startFailure(formatReason(R.string.repeater_remove_old_group_failure, reason)) + }) + } } } + } catch (e: SecurityException) { + Timber.w(e) + startFailure(e.readableMessage) } - } catch (e: SecurityException) { - Timber.w(e) - startFailure(e.readableMessage) } return START_NOT_STICKY } @@ -389,14 +390,11 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene } }) } - private fun unregisterReceiver() { + private fun cleanLocked() { if (receiverRegistered) { unregisterReceiver(receiver) receiverRegistered = false } - } - private fun cleanLocked() { - unregisterReceiver() if (Build.VERSION.SDK_INT >= 28) { timeoutMonitor?.close() timeoutMonitor = null diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt index 5d359cb4..4a799816 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt @@ -62,7 +62,7 @@ class IpNeighbourMonitor private constructor() : IpMonitor() { private fun postUpdateLocked() { if (updatePosted || instance != this) return - GlobalScope.launch(Dispatchers.Main) { + GlobalScope.launch { val neighbours = synchronized(neighbours) { updatePosted = false neighbours.values.toList()