Misc fixes

This commit is contained in:
Mygod
2020-07-18 03:20:22 +08:00
parent c344dbfa4a
commit 0f16210c80
6 changed files with 9 additions and 10 deletions

View File

@@ -95,7 +95,7 @@ dependencies {
implementation("com.takisoft.preferencex:preferencex-simplemenu:1.1.0") implementation("com.takisoft.preferencex:preferencex-simplemenu:1.1.0")
implementation("eu.chainfire:librootjava:1.3.0") implementation("eu.chainfire:librootjava:1.3.0")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.2") implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8")
testImplementation("junit:junit:4.13") testImplementation("junit:junit:4.13")
androidTestImplementation("androidx.room:room-testing:$roomVersion") androidTestImplementation("androidx.room:room-testing:$roomVersion")
androidTestImplementation("androidx.test:runner:1.2.0") androidTestImplementation("androidx.test:runner:1.2.0")

View File

@@ -151,7 +151,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
override fun onStateChanged(state: Int, failureReason: Int) { override fun onStateChanged(state: Int, failureReason: Int) {
if (state < 10 || state > 14) { if (state < 10 || state > 14) {
Timber.w(Exception("Unknown state $state")) Timber.w(Exception("Unknown state $state, $failureReason"))
return return
} }
this.failureReason = if (state == 14) failureReason else null // WIFI_AP_STATE_FAILED this.failureReason = if (state == 14) failureReason else null // WIFI_AP_STATE_FAILED

View File

@@ -6,6 +6,7 @@ import be.mygod.vpnhotspot.net.Routing.Companion.IP
import be.mygod.vpnhotspot.root.RoutingCommands import be.mygod.vpnhotspot.root.RoutingCommands
import be.mygod.vpnhotspot.util.RootSession import be.mygod.vpnhotspot.util.RootSession
import be.mygod.vpnhotspot.widget.SmartSnackbar import be.mygod.vpnhotspot.widget.SmartSnackbar
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
@@ -40,6 +41,7 @@ object DhcpWorkaround : SharedPreferences.OnSharedPreferenceChangeListener {
SmartSnackbar.make(e).show() SmartSnackbar.make(e).show()
} }
} }
} catch (_: CancellationException) {
} catch (e: Exception) { } catch (e: Exception) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e).show() SmartSnackbar.make(e).show()

View File

@@ -17,6 +17,7 @@ import be.mygod.vpnhotspot.util.RootSession
import be.mygod.vpnhotspot.util.if_nametoindex import be.mygod.vpnhotspot.util.if_nametoindex
import be.mygod.vpnhotspot.util.parseNumericAddress import be.mygod.vpnhotspot.util.parseNumericAddress
import be.mygod.vpnhotspot.widget.SmartSnackbar import be.mygod.vpnhotspot.widget.SmartSnackbar
import kotlinx.coroutines.CancellationException
import timber.log.Timber import timber.log.Timber
import java.io.BufferedWriter import java.io.BufferedWriter
import java.io.IOException import java.io.IOException
@@ -340,7 +341,9 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh
currentDns?.transaction?.revert() currentDns?.transaction?.revert()
currentDns = if (ifindex == 0 || dns == null) null else try { currentDns = if (ifindex == 0 || dns == null) null else try {
DnsRoute(ifindex, dns) DnsRoute(ifindex, dns)
} catch (e: RuntimeException) { } catch (_: CancellationException) {
null
} catch (e: Exception) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e).show() SmartSnackbar.make(e).show()
null null

View File

@@ -16,7 +16,6 @@ import be.mygod.vpnhotspot.net.monitor.UpstreamMonitor
import be.mygod.vpnhotspot.util.SpanFormatter import be.mygod.vpnhotspot.util.SpanFormatter
import be.mygod.vpnhotspot.util.parseNumericAddress import be.mygod.vpnhotspot.util.parseNumericAddress
import timber.log.Timber import timber.log.Timber
import java.lang.RuntimeException
class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs),
DefaultLifecycleObserver { DefaultLifecycleObserver {

View File

@@ -18,7 +18,7 @@ class RootSession : AutoCloseable {
monitor.lock() monitor.lock()
val instance = try { val instance = try {
RootSession() RootSession()
} catch (e: RuntimeException) { } catch (e: Exception) {
monitor.unlock() monitor.unlock()
throw e throw e
} }
@@ -41,11 +41,6 @@ class RootSession : AutoCloseable {
server!!.execute(RoutingCommands.Process(listOf("sh", "-c", command), redirect)) server!!.execute(RoutingCommands.Process(listOf("sh", "-c", command), redirect))
} }
fun exec(command: String) = execQuiet(command).check(listOf(command)) fun exec(command: String) = execQuiet(command).check(listOf(command))
fun execOut(command: String): String {
val result = execQuiet(command)
result.check(listOf(command), false)
return result.out
}
/** /**
* This transaction is different from what you may have in mind since you can revert it after committing it. * This transaction is different from what you may have in mind since you can revert it after committing it.