Various bugfixes

This commit is contained in:
Mygod
2019-07-20 16:15:26 +08:00
parent 184ce94590
commit 0ab3ccf8d5
3 changed files with 23 additions and 25 deletions

View File

@@ -90,7 +90,7 @@ dependencies {
implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0' implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0'
implementation 'net.glxn.qrgen:android:2.0' implementation 'net.glxn.qrgen:android:2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" 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) { for (dep in aux) {
freedomImplementation dep freedomImplementation dep
googleImplementation dep googleImplementation dep

View File

@@ -255,28 +255,29 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
if (Build.VERSION.SDK_INT >= 26 && app.uiMode.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) { if (Build.VERSION.SDK_INT >= 26 && app.uiMode.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) {
showNotification() showNotification()
} }
unregisterReceiver() launch {
registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION, registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION,
WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION))
receiverRegistered = true receiverRegistered = true
try { try {
p2pManager.requestGroupInfo(channel) { p2pManager.requestGroupInfo(channel) {
when { when {
it == null -> doStart() it == null -> doStart()
it.isGroupOwner -> launch { if (routingManager == null) doStartLocked(it) } it.isGroupOwner -> launch { if (routingManager == null) doStartLocked(it) }
else -> { else -> {
Timber.i("Removing old group ($it)") Timber.i("Removing old group ($it)")
p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener { p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener {
override fun onSuccess() = doStart() override fun onSuccess() = doStart()
override fun onFailure(reason: Int) = override fun onFailure(reason: Int) =
startFailure(formatReason(R.string.repeater_remove_old_group_failure, reason)) 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 return START_NOT_STICKY
} }
@@ -389,14 +390,11 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
} }
}) })
} }
private fun unregisterReceiver() { private fun cleanLocked() {
if (receiverRegistered) { if (receiverRegistered) {
unregisterReceiver(receiver) unregisterReceiver(receiver)
receiverRegistered = false receiverRegistered = false
} }
}
private fun cleanLocked() {
unregisterReceiver()
if (Build.VERSION.SDK_INT >= 28) { if (Build.VERSION.SDK_INT >= 28) {
timeoutMonitor?.close() timeoutMonitor?.close()
timeoutMonitor = null timeoutMonitor = null

View File

@@ -62,7 +62,7 @@ class IpNeighbourMonitor private constructor() : IpMonitor() {
private fun postUpdateLocked() { private fun postUpdateLocked() {
if (updatePosted || instance != this) return if (updatePosted || instance != this) return
GlobalScope.launch(Dispatchers.Main) { GlobalScope.launch {
val neighbours = synchronized(neighbours) { val neighbours = synchronized(neighbours) {
updatePosted = false updatePosted = false
neighbours.values.toList() neighbours.values.toList()