@@ -1,6 +1,5 @@
|
||||
package be.mygod.vpnhotspot
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
@@ -9,7 +8,6 @@ import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreference
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.net.Routing.Companion.IPTABLES
|
||||
import be.mygod.vpnhotspot.net.TetherOffloadManager
|
||||
import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor
|
||||
import be.mygod.vpnhotspot.net.monitor.IpMonitor
|
||||
@@ -18,7 +16,9 @@ import be.mygod.vpnhotspot.net.wifi.WifiDoubleLock
|
||||
import be.mygod.vpnhotspot.preference.AlwaysAutoCompleteEditTextPreferenceDialogFragment
|
||||
import be.mygod.vpnhotspot.preference.SharedPreferenceDataStore
|
||||
import be.mygod.vpnhotspot.preference.SummaryFallbackProvider
|
||||
import be.mygod.vpnhotspot.util.RootSession
|
||||
import be.mygod.vpnhotspot.root.Dump
|
||||
import be.mygod.vpnhotspot.root.RootManager
|
||||
import be.mygod.vpnhotspot.util.Services
|
||||
import be.mygod.vpnhotspot.util.launchUrl
|
||||
import be.mygod.vpnhotspot.util.showAllowingStateLoss
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
@@ -27,9 +27,9 @@ import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.PrintWriter
|
||||
import kotlin.system.exitProcess
|
||||
@@ -48,34 +48,30 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
||||
if (Build.VERSION.SDK_INT >= 27) {
|
||||
isChecked = TetherOffloadManager.enabled
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
if (TetherOffloadManager.enabled != newValue) {
|
||||
if (TetherOffloadManager.enabled != newValue) GlobalScope.launch(Dispatchers.Main.immediate) {
|
||||
isEnabled = false
|
||||
GlobalScope.launch {
|
||||
try {
|
||||
TetherOffloadManager.enabled = newValue as Boolean
|
||||
} catch (e: Exception) {
|
||||
Timber.d(e)
|
||||
SmartSnackbar.make(e).show()
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
isChecked = TetherOffloadManager.enabled
|
||||
isEnabled = true
|
||||
}
|
||||
try {
|
||||
TetherOffloadManager.setEnabled(newValue as Boolean)
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
SmartSnackbar.make(e).show()
|
||||
}
|
||||
isChecked = TetherOffloadManager.enabled
|
||||
isEnabled = true
|
||||
}
|
||||
false
|
||||
}
|
||||
} else parent!!.removePreference(this)
|
||||
}
|
||||
val boot = findPreference<SwitchPreference>("service.repeater.startOnBoot")!!
|
||||
if (RepeaterService.supported) {
|
||||
if (Services.p2p != null) {
|
||||
boot.setOnPreferenceChangeListener { _, value ->
|
||||
BootReceiver.enabled = value as Boolean
|
||||
true
|
||||
}
|
||||
boot.isChecked = BootReceiver.enabled
|
||||
} else boot.parent!!.removePreference(boot)
|
||||
if (!RepeaterService.supported || !RepeaterService.safeModeConfigurable) {
|
||||
if (Services.p2p == null || !RepeaterService.safeModeConfigurable) {
|
||||
val safeMode = findPreference<Preference>(RepeaterService.KEY_SAFE_MODE)!!
|
||||
safeMode.parent!!.removePreference(safeMode)
|
||||
}
|
||||
@@ -88,7 +84,6 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
||||
setAction(R.string.settings_exit_app) {
|
||||
GlobalScope.launch {
|
||||
RoutingManager.clean(false)
|
||||
RootSession.trimMemory()
|
||||
exitProcess(0)
|
||||
}
|
||||
}
|
||||
@@ -109,57 +104,19 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
||||
Runtime.getRuntime().exec(arrayOf("logcat", "-d")).inputStream.use { it.copyTo(out) }
|
||||
} catch (e: IOException) {
|
||||
Timber.w(e)
|
||||
e.printStackTrace(writer)
|
||||
}
|
||||
writer.println()
|
||||
val commands = StringBuilder()
|
||||
// https://android.googlesource.com/platform/external/iptables/+/android-7.0.0_r1/iptables/Android.mk#34
|
||||
val iptablesSave = if (Build.VERSION.SDK_INT >= 24) "iptables-save" else
|
||||
File(app.deviceStorage.cacheDir, "iptables-save").absolutePath.also {
|
||||
commands.appendln("ln -sf /system/bin/iptables $it")
|
||||
}
|
||||
val ip6tablesSave = if (Build.VERSION.SDK_INT >= 24) "ip6tables-save" else
|
||||
File(app.deviceStorage.cacheDir, "ip6tables-save").absolutePath.also {
|
||||
commands.appendln("ln -sf /system/bin/ip6tables $it")
|
||||
}
|
||||
commands.append("""
|
||||
|echo dumpsys ${Context.WIFI_P2P_SERVICE}
|
||||
|dumpsys ${Context.WIFI_P2P_SERVICE}
|
||||
|echo
|
||||
|echo dumpsys ${Context.CONNECTIVITY_SERVICE} tethering
|
||||
|dumpsys ${Context.CONNECTIVITY_SERVICE} tethering
|
||||
|echo
|
||||
|echo iptables -t filter
|
||||
|$iptablesSave -t filter
|
||||
|echo
|
||||
|echo iptables -t nat
|
||||
|$iptablesSave -t nat
|
||||
|echo
|
||||
|echo ip6tables-save
|
||||
|$ip6tablesSave
|
||||
|echo
|
||||
|echo ip rule
|
||||
|ip rule
|
||||
|echo
|
||||
|echo ip neigh
|
||||
|ip neigh
|
||||
|echo
|
||||
|echo iptables -nvx -L vpnhotspot_fwd
|
||||
|$IPTABLES -nvx -L vpnhotspot_fwd
|
||||
|echo
|
||||
|echo iptables -nvx -L vpnhotspot_acl
|
||||
|$IPTABLES -nvx -L vpnhotspot_acl
|
||||
|echo
|
||||
|echo logcat-su
|
||||
|logcat -d
|
||||
""".trimMargin())
|
||||
try {
|
||||
RootSession.use { it.execQuiet(commands.toString(), true).out.forEach(writer::println) }
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace(writer)
|
||||
Timber.i(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
RootManager.use {
|
||||
it.execute(Dump(logFile.absolutePath))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
PrintWriter(FileOutputStream(logFile, true)).use { e.printStackTrace(it) }
|
||||
}
|
||||
context.startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND)
|
||||
.setType("text/x-log")
|
||||
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
@@ -187,8 +144,8 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
||||
when (preference.key) {
|
||||
UpstreamMonitor.KEY, FallbackUpstreamMonitor.KEY ->
|
||||
AlwaysAutoCompleteEditTextPreferenceDialogFragment().apply {
|
||||
setArguments(preference.key, app.connectivity.allNetworks.mapNotNull {
|
||||
app.connectivity.getLinkProperties(it)?.interfaceName
|
||||
setArguments(preference.key, Services.connectivity.allNetworks.mapNotNull {
|
||||
Services.connectivity.getLinkProperties(it)?.interfaceName
|
||||
}.toTypedArray())
|
||||
setTargetFragment(this@SettingsPreferenceFragment, 0)
|
||||
}.showAllowingStateLoss(parentFragmentManager, preference.key)
|
||||
|
||||
Reference in New Issue
Block a user