From e347115908e24bc70b5d8e2b285d2279204815f9 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 8 Oct 2018 15:23:57 +0800 Subject: [PATCH] Add back root unavailable prompt --- .../java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt | 2 +- .../java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt | 2 +- mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt | 2 +- .../java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt | 2 +- .../src/main/java/be/mygod/vpnhotspot/TetheringService.kt | 2 +- .../main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt | 2 +- .../main/java/be/mygod/vpnhotspot/manage/TetherManager.kt | 2 +- mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt | 6 +++--- mobile/src/main/java/be/mygod/vpnhotspot/net/Subrouting.kt | 2 +- .../java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt | 2 +- .../main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt | 6 ++++++ mobile/src/main/res/values-zh-rCN/strings.xml | 1 + mobile/src/main/res/values/strings.xml | 1 + 13 files changed, 20 insertions(+), 12 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index f2bcf090..166cc96c 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -98,7 +98,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { // assuming IllegalStateException will be thrown only if // "Caller already has an active LocalOnlyHotspot request" } catch (_: IllegalStateException) { } catch (e: SecurityException) { - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() Timber.w(e) startFailure() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt index 61f6dba5..976bafaf 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt @@ -35,7 +35,7 @@ class LocalOnlyInterfaceManager(val downstream: String) { } // otw nothing needs to be done } } catch (e: Exception) { - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() Timber.w(e) null } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index 3e16102d..5da49383 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -80,7 +80,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere } } catch (e: ReflectiveOperationException) { Timber.w(e) - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() } } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt index ed6b02a3..2e0fac47 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt @@ -43,7 +43,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() { true } catch (e: RuntimeException) { Timber.d(e) - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() false } if (cleaned) app.cleanRoutings() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt index 31b3c580..e91e7c0e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt @@ -75,7 +75,7 @@ class TetheringService : IpNeighbourMonitoringService() { } } catch (e: Exception) { Timber.w(e) - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() iterator.remove() } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt index 73653b90..aad8cfa0 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt @@ -174,7 +174,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic app.handler.postDelayed(binder!!::requestGroupUpdate, 1000) } catch (e: Exception) { Timber.w(e) - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() } DialogInterface.BUTTON_NEUTRAL -> binder!!.resetCredentials() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt index 1750900a..7145e708 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -169,7 +169,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), BluetoothAdapter.getDefaultAdapter()?.getProfileProxy(parent.requireContext(), this, PAN) } catch (e: SecurityException) { Timber.w(e) - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() } } 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 ee0033ea..75aa6d88 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -80,7 +80,7 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) { if (subrouting == null) this.subrouting = try { Subrouting(this@Routing, priority, ifname) } catch (e: Exception) { - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() Timber.w(e) null } else check(subrouting.upstream == ifname) @@ -105,7 +105,7 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) { subrouting = try { Subrouting(this@Routing, priority) } catch (e: Exception) { - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() Timber.w(e) null } @@ -150,7 +150,7 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) { DnsRoute(dns) } catch (e: RuntimeException) { Timber.w(e) - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() null } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Subrouting.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Subrouting.kt index 9c47212a..9d8174eb 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Subrouting.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Subrouting.kt @@ -80,7 +80,7 @@ class Subrouting(private val parent: Routing, priority: Int, val upstream: Strin subroutes.computeIfAbsentCompat(neighbour.ip) { Subroute(neighbour.ip, neighbour.lladdr) } } catch (e: Exception) { Timber.w(e) - SmartSnackbar.make(e.localizedMessage).show() + SmartSnackbar.make(e).show() } } if (toRemove.isNotEmpty()) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt index 5e1233f8..a647c498 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt @@ -135,7 +135,7 @@ object TrafficRecorder { doUpdate(timestamp) } catch (e: RuntimeException) { Timber.w(e) - SmartSnackbar.make(e.localizedMessage) + SmartSnackbar.make(e).show() } lastUpdate = timestamp scheduleUpdateLocked() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt b/mobile/src/main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt index 7b62ee56..8aa7f33a 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt @@ -9,7 +9,9 @@ import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.OnLifecycleEvent import be.mygod.vpnhotspot.App.Companion.app +import be.mygod.vpnhotspot.R import com.google.android.material.snackbar.Snackbar +import com.topjohnwu.superuser.NoShellException sealed class SmartSnackbar { companion object { @@ -22,6 +24,10 @@ sealed class SmartSnackbar { return if (holder == null) ToastWrapper(Toast.makeText(app, text, Toast.LENGTH_LONG)) else SnackbarWrapper(Snackbar.make(holder, text ?: null.toString(), Snackbar.LENGTH_LONG)) } + fun make(e: Throwable) = make(when (e) { + is NoShellException -> app.getText(R.string.root_unavailable) + else -> e.localizedMessage + }) } class Register(private val view: View) : LifecycleObserver { diff --git a/mobile/src/main/res/values-zh-rCN/strings.xml b/mobile/src/main/res/values-zh-rCN/strings.xml index d91af1b5..9510ac3e 100644 --- a/mobile/src/main/res/values-zh-rCN/strings.xml +++ b/mobile/src/main/res/values-zh-rCN/strings.xml @@ -109,6 +109,7 @@ %d 个接口 + 似乎没有 root 未知 #%d 错误:未找到下游接口 发生异常,详情请查看调试信息。 diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index ece98cbf..661c1189 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -120,6 +120,7 @@ %d interfaces + Root unavailable unknown #%d Fatal: Downstream interface not found Something went wrong, please check the debug information.