diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt
index b1c5ac78..e8fcfe74 100644
--- a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt
+++ b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt
@@ -14,6 +14,7 @@ import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.net.Routing
import be.mygod.vpnhotspot.net.Routing.Companion.IPTABLES
import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor
+import be.mygod.vpnhotspot.net.monitor.IpMonitor
import be.mygod.vpnhotspot.net.monitor.UpstreamMonitor
import be.mygod.vpnhotspot.preference.AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat
import be.mygod.vpnhotspot.preference.SharedPreferenceDataStore
@@ -52,6 +53,10 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
if (cleaned) app.onRoutingsCleaned()
true
}
+ findPreference(IpMonitor.KEY).setOnPreferenceChangeListener { _, _ ->
+ SmartSnackbar.make(R.string.settings_restart_required).show()
+ true
+ }
findPreference("misc.logcat").setOnPreferenceClickListener {
val context = requireContext()
val logDir = File(context.cacheDir, "log")
diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt
index ddf14739..5a5e9377 100644
--- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt
+++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt
@@ -1,5 +1,6 @@
package be.mygod.vpnhotspot.net.monitor
+import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.R
import be.mygod.vpnhotspot.debugLog
import be.mygod.vpnhotspot.util.thread
@@ -12,6 +13,14 @@ import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
abstract class IpMonitor : Runnable {
+ companion object {
+ const val KEY = "service.ipMonitor"
+ }
+
+ enum class Mode {
+ Monitor, MonitorRoot, Poll
+ }
+
private class MonitorFailure : RuntimeException()
private class FlushFailure : RuntimeException()
protected abstract val monitoredObject: String
@@ -50,13 +59,18 @@ abstract class IpMonitor : Runnable {
init {
thread("${javaClass.simpleName}-input") {
- // monitor may get rejected by SELinux
- handleProcess(ProcessBuilder("ip", "monitor", monitoredObject))
- if (destroyed) return@thread
- handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject"))
- if (destroyed) return@thread
- Timber.w("Failed to set up monitor, switching to polling")
- Timber.i(MonitorFailure())
+ val mode = Mode.valueOf(app.pref.getString(KEY, Mode.Monitor.toString()) ?: "")
+ if (mode != Mode.Poll) {
+ if (mode != Mode.MonitorRoot) {
+ // monitor may get rejected by SELinux enforcing
+ handleProcess(ProcessBuilder("ip", "monitor", monitoredObject))
+ if (destroyed) return@thread
+ }
+ handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject"))
+ if (destroyed) return@thread
+ Timber.w("Failed to set up monitor, switching to polling")
+ Timber.i(MonitorFailure())
+ }
val pool = Executors.newScheduledThreadPool(1)
pool.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS)
this.pool = pool
diff --git a/mobile/src/main/res/drawable/ic_hardware_device_hub.xml b/mobile/src/main/res/drawable/ic_hardware_device_hub.xml
new file mode 100644
index 00000000..6af6c649
--- /dev/null
+++ b/mobile/src/main/res/drawable/ic_hardware_device_hub.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/mobile/src/main/res/values-zh-rCN/strings.xml b/mobile/src/main/res/values-zh-rCN/strings.xml
index b7909143..356ee9c0 100644
--- a/mobile/src/main/res/values-zh-rCN/strings.xml
+++ b/mobile/src/main/res/values-zh-rCN/strings.xml
@@ -88,6 +88,10 @@
系统默认
开(防止服务自动关闭)
高性能模式(更快消耗电池)
+ 网络状态监听模式
+ Netlink 监听
+ Netlink 监听 (root)
+ 轮询
备用 DNS 服务器[:端口]
上游网络接口
自动检测系统 VPN
@@ -105,6 +109,7 @@
捐款
请给我钱
PayPal, Flattr 等其他方式…
+ 重启应用以应用新的设置。
VPN 共享已启用
VPN 共享服务
diff --git a/mobile/src/main/res/values/arrays.xml b/mobile/src/main/res/values/arrays.xml
index 65dbb003..b532e81c 100644
--- a/mobile/src/main/res/values/arrays.xml
+++ b/mobile/src/main/res/values/arrays.xml
@@ -10,4 +10,14 @@
- Full
- HighPerf
+
+ - @string/settings_service_ip_monitor_monitor
+ - @string/settings_service_ip_monitor_monitor_root
+ - @string/settings_service_ip_monitor_poll
+
+
+ - Monitor
+ - MonitorRoot
+ - Poll
+
diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml
index f95e5b59..589f8a95 100644
--- a/mobile/src/main/res/values/strings.xml
+++ b/mobile/src/main/res/values/strings.xml
@@ -96,6 +96,10 @@
System default
On (prevents service auto-shutdowns)
High Performance Mode (consumes more power)
+ Network status monitor mode
+ Netlink monitor
+ Netlink monitor with root
+ Poll
Fallback DNS server[:port]
Upstream network interface
Auto detect system VPN
@@ -114,6 +118,7 @@
Donate
I love money
PayPal, Flattr, more…
+ Restart this app to apply this setting.
VPN tethering active
VPN Tethering Service
diff --git a/mobile/src/main/res/xml/pref_settings.xml b/mobile/src/main/res/xml/pref_settings.xml
index 690ef567..005400b7 100644
--- a/mobile/src/main/res/xml/pref_settings.xml
+++ b/mobile/src/main/res/xml/pref_settings.xml
@@ -61,6 +61,14 @@
android:key="service.repeater.startOnBoot"
android:icon="@drawable/ic_action_autorenew"
android:title="@string/settings_service_repeater_start_on_boot"/>
+