Migrate from deprecated APIs
This commit is contained in:
@@ -13,6 +13,8 @@ import be.mygod.vpnhotspot.net.Routing.Companion.IPTABLES
|
||||
import be.mygod.vpnhotspot.net.TetheringManager
|
||||
import be.mygod.vpnhotspot.util.Services
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.onClosed
|
||||
import kotlinx.coroutines.channels.onFailure
|
||||
import kotlinx.coroutines.channels.produce
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import java.io.File
|
||||
@@ -101,7 +103,7 @@ class ProcessListener(private val terminateRegex: Regex,
|
||||
launch(parent) {
|
||||
try {
|
||||
process.inputStream.bufferedReader().forEachLine {
|
||||
check(offer(ProcessData.StdoutLine(it)))
|
||||
trySend(ProcessData.StdoutLine(it)).onClosed { return@forEachLine }.onFailure { throw it!! }
|
||||
if (terminateRegex.containsMatchIn(it)) process.destroy()
|
||||
}
|
||||
} catch (_: InterruptedIOException) { }
|
||||
@@ -111,7 +113,9 @@ class ProcessListener(private val terminateRegex: Regex,
|
||||
process.errorStream.bufferedReader().forEachLine { check(offer(ProcessData.StderrLine(it))) }
|
||||
} catch (_: InterruptedIOException) { }
|
||||
}
|
||||
launch(parent) { check(offer(ProcessData.Exit(process.waitFor()))) }
|
||||
launch(parent) {
|
||||
trySend(ProcessData.Exit(process.waitFor())).onClosed { return@launch }.onFailure { throw it!! }
|
||||
}
|
||||
parent.join()
|
||||
} finally {
|
||||
parent.cancel()
|
||||
|
||||
@@ -10,9 +10,7 @@ import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat
|
||||
import be.mygod.vpnhotspot.net.wifi.WifiApManager
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.ReceiveChannel
|
||||
import kotlinx.coroutines.channels.consumeEach
|
||||
import kotlinx.coroutines.channels.produce
|
||||
import kotlinx.coroutines.channels.*
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import timber.log.Timber
|
||||
|
||||
@@ -65,12 +63,11 @@ object WifiApCommands {
|
||||
override fun create(scope: CoroutineScope) = scope.produce<SoftApCallbackParcel>(capacity = capacity) {
|
||||
val finish = CompletableDeferred<Unit>()
|
||||
val key = WifiApManager.registerSoftApCallback(object : WifiApManager.SoftApCallbackCompat {
|
||||
private fun push(parcel: SoftApCallbackParcel) = check(try {
|
||||
offer(parcel)
|
||||
} catch (closed: Throwable) {
|
||||
finish.completeExceptionally(closed)
|
||||
true
|
||||
})
|
||||
private fun push(parcel: SoftApCallbackParcel) {
|
||||
trySend(parcel).onClosed {
|
||||
finish.completeExceptionally(it ?: ClosedSendChannelException("Channel was closed normally"))
|
||||
}.onFailure { throw it!! }
|
||||
}
|
||||
|
||||
override fun onStateChanged(state: Int, failureReason: Int) =
|
||||
push(SoftApCallbackParcel.OnStateChanged(state, failureReason))
|
||||
|
||||
Reference in New Issue
Block a user