Merge branch 'master' into v2.4

This commit is contained in:
Mygod
2019-04-05 12:02:10 +08:00
2 changed files with 5 additions and 6 deletions

View File

@@ -14,7 +14,6 @@ import android.os.Handler
import android.os.Looper
import androidx.annotation.StringRes
import androidx.core.content.getSystemService
import androidx.core.os.BuildCompat
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.deletePersistentGroup
@@ -140,7 +139,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
WifiP2pManager.NO_SERVICE_REQUESTS -> getString(R.string.repeater_failure_reason_no_service_requests)
WifiP2pManagerHelper.UNSUPPORTED -> getString(R.string.repeater_failure_reason_unsupported_operation)
else -> getString(R.string.failure_reason_unknown, reason)
}).also { if (BuildCompat.isAtLeastQ()) Timber.w(RuntimeException(it)) }
})
override fun onCreate() {
super.onCreate()

View File

@@ -19,7 +19,7 @@ abstract class IpMonitor : Runnable {
companion object {
const val KEY = "service.ipMonitor"
// https://android.googlesource.com/platform/external/iproute2/+/7f7a711/lib/libnetlink.c#493
private const val MAGIC_SUFFIX = "Dump was interrupted and may be inconsistent."
private val errorMatcher = "Dump (was interrupted and may be inconsistent.|terminated)$".toRegex()
private val currentMode get() = Mode.valueOf(app.pref.getString(KEY, Mode.Poll.toString()) ?: "")
}
@@ -54,7 +54,7 @@ abstract class IpMonitor : Runnable {
}
try {
process.inputStream.bufferedReader().forEachLine {
if (it.endsWith(MAGIC_SUFFIX)) {
if (errorMatcher.matches(it)) {
Timber.w(it)
process.destroy() // move on to next mode
} else processLine(it)
@@ -103,7 +103,7 @@ abstract class IpMonitor : Runnable {
}
process.inputStream.bufferedReader().useLines {
processLines(it.map { line ->
if (line.endsWith(MAGIC_SUFFIX)) throw IOException(line)
if (errorMatcher.matches(line)) throw IOException(line)
line
})
}
@@ -121,7 +121,7 @@ abstract class IpMonitor : Runnable {
RootSession.use {
val result = it.execQuiet(command)
RootSession.checkOutput(command, result, false)
if (result.out.any { it.endsWith(MAGIC_SUFFIX) }) throw IOException(result.out.joinToString("\n"))
if (result.out.any { errorMatcher.matches(it) }) throw IOException(result.out.joinToString("\n"))
processLines(result.out.asSequence())
}
} catch (e: RuntimeException) {