From 913e9bd863595054c2ae4949503a55b5ca6e709e Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 22 Jan 2018 00:45:55 -0800 Subject: [PATCH] Add root unavailable to clean --- mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt | 2 +- .../java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt | 4 ++-- mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt | 4 ++-- mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt | 4 ++-- mobile/src/main/res/values-zh-rCN/strings.xml | 2 +- mobile/src/main/res/values/strings.xml | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index d4aedf09..704e0d09 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -199,7 +199,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnMonitor.Ca Status.STARTING -> { val matcher = patternNetworkInfo.matcher(loggerSu("dumpsys ${Context.WIFI_P2P_SERVICE}") ?: "") when { - !matcher.find() -> startFailure(getString(R.string.repeater_root_unavailable)) + !matcher.find() -> startFailure(getString(R.string.root_unavailable)) matcher.group(2) == "true" -> { unregisterReceiver() registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION, diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt index c0f37098..d93e5d4b 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt @@ -19,8 +19,8 @@ class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() { override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_settings) findPreference("service.clean").setOnPreferenceClickListener { - Routing.clean() - LocalBroadcastManager.getInstance(context!!).sendBroadcastSync(Intent(App.ACTION_CLEAN_ROUTINGS)) + if (Routing.clean() == null) Toast.makeText(context!!, R.string.root_unavailable, Toast.LENGTH_SHORT).show() + else LocalBroadcastManager.getInstance(context!!).sendBroadcastSync(Intent(App.ACTION_CLEAN_ROUTINGS)) true } findPreference("misc.logcat").setOnPreferenceClickListener { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt index 421053e5..bdc7053f 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt @@ -60,11 +60,11 @@ fun loggerSu(command: String): String? { null } } -fun noisySu(commands: Iterable): Boolean { +fun noisySu(commands: Iterable): Boolean? { var out = loggerSu("""function noisy() { "$@" || echo "$@" exited with $?; } ${commands.joinToString("\n") { if (it.startsWith("quiet ")) it.substring(6) else "noisy $it" }} echo $NOISYSU_SUFFIX""") - val result = out == NOISYSU_SUFFIX + val result = if (out == null) null else out == NOISYSU_SUFFIX out = out?.removeSuffix(NOISYSU_SUFFIX) if (!out.isNullOrBlank()) Log.i(NOISYSU_TAG, out) return result diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt index dd7a62c4..f0fb055c 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -79,11 +79,11 @@ class Routing(private val upstream: String, val downstream: String, ownerAddress fun start(): Boolean { if (started) return true started = true - return noisySu(startScript) + return noisySu(startScript) == true } fun stop(): Boolean { if (!started) return true started = false - return noisySu(stopScript) + return noisySu(stopScript) == true } } diff --git a/mobile/src/main/res/values-zh-rCN/strings.xml b/mobile/src/main/res/values-zh-rCN/strings.xml index c4316fd4..8856860e 100644 --- a/mobile/src/main/res/values-zh-rCN/strings.xml +++ b/mobile/src/main/res/values-zh-rCN/strings.xml @@ -22,7 +22,6 @@ 未打开 无法找到 VPN,请启用任意 VPN - 似乎没有 root Wi-Fi 直连不可用 创建 P2P 群组失败(原因:%s) 关闭已有 P2P 群组失败(原因:%s) @@ -62,5 +61,6 @@ 错误:未找到下游接口 + 似乎没有 root 发生异常,详情请查看日志。 diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 5996a3fe..a9091cc8 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -24,7 +24,6 @@ Service inactive VPN unavailable, please enable any VPN - Root unavailable Wi-Fi direct unavailable Failed to create P2P group (reason: %s) Failed to remove P2P group (reason: %s) @@ -66,5 +65,6 @@ Fatal: Downstream interface not found + Root unavailable Something went wrong, please check logcat.