Add back root unavailable prompt

This commit is contained in:
Mygod
2018-10-08 15:23:57 +08:00
parent e4e716ab83
commit e347115908
13 changed files with 20 additions and 12 deletions

View File

@@ -98,7 +98,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() {
// assuming IllegalStateException will be thrown only if // assuming IllegalStateException will be thrown only if
// "Caller already has an active LocalOnlyHotspot request" // "Caller already has an active LocalOnlyHotspot request"
} catch (_: IllegalStateException) { } catch (e: SecurityException) { } catch (_: IllegalStateException) { } catch (e: SecurityException) {
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
Timber.w(e) Timber.w(e)
startFailure() startFailure()
} }

View File

@@ -35,7 +35,7 @@ class LocalOnlyInterfaceManager(val downstream: String) {
} // otw nothing needs to be done } // otw nothing needs to be done
} }
} catch (e: Exception) { } catch (e: Exception) {
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
Timber.w(e) Timber.w(e)
null null
} }

View File

@@ -80,7 +80,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
} }
} catch (e: ReflectiveOperationException) { } catch (e: ReflectiveOperationException) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
} }
} }
} }

View File

@@ -43,7 +43,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
true true
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
Timber.d(e) Timber.d(e)
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
false false
} }
if (cleaned) app.cleanRoutings() if (cleaned) app.cleanRoutings()

View File

@@ -75,7 +75,7 @@ class TetheringService : IpNeighbourMonitoringService() {
} }
} catch (e: Exception) { } catch (e: Exception) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
iterator.remove() iterator.remove()
} }
} }

View File

@@ -174,7 +174,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
app.handler.postDelayed(binder!!::requestGroupUpdate, 1000) app.handler.postDelayed(binder!!::requestGroupUpdate, 1000)
} catch (e: Exception) { } catch (e: Exception) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
} }
DialogInterface.BUTTON_NEUTRAL -> binder!!.resetCredentials() DialogInterface.BUTTON_NEUTRAL -> binder!!.resetCredentials()
} }

View File

@@ -169,7 +169,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
BluetoothAdapter.getDefaultAdapter()?.getProfileProxy(parent.requireContext(), this, PAN) BluetoothAdapter.getDefaultAdapter()?.getProfileProxy(parent.requireContext(), this, PAN)
} catch (e: SecurityException) { } catch (e: SecurityException) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
} }
} }

View File

@@ -80,7 +80,7 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) {
if (subrouting == null) this.subrouting = try { if (subrouting == null) this.subrouting = try {
Subrouting(this@Routing, priority, ifname) Subrouting(this@Routing, priority, ifname)
} catch (e: Exception) { } catch (e: Exception) {
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
Timber.w(e) Timber.w(e)
null null
} else check(subrouting.upstream == ifname) } else check(subrouting.upstream == ifname)
@@ -105,7 +105,7 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) {
subrouting = try { subrouting = try {
Subrouting(this@Routing, priority) Subrouting(this@Routing, priority)
} catch (e: Exception) { } catch (e: Exception) {
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
Timber.w(e) Timber.w(e)
null null
} }
@@ -150,7 +150,7 @@ class Routing(val downstream: String, ownerAddress: InterfaceAddress? = null) {
DnsRoute(dns) DnsRoute(dns)
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
null null
} }
} }

View File

@@ -80,7 +80,7 @@ class Subrouting(private val parent: Routing, priority: Int, val upstream: Strin
subroutes.computeIfAbsentCompat(neighbour.ip) { Subroute(neighbour.ip, neighbour.lladdr) } subroutes.computeIfAbsentCompat(neighbour.ip) { Subroute(neighbour.ip, neighbour.lladdr) }
} catch (e: Exception) { } catch (e: Exception) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e.localizedMessage).show() SmartSnackbar.make(e).show()
} }
} }
if (toRemove.isNotEmpty()) { if (toRemove.isNotEmpty()) {

View File

@@ -135,7 +135,7 @@ object TrafficRecorder {
doUpdate(timestamp) doUpdate(timestamp)
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e.localizedMessage) SmartSnackbar.make(e).show()
} }
lastUpdate = timestamp lastUpdate = timestamp
scheduleUpdateLocked() scheduleUpdateLocked()

View File

@@ -9,7 +9,9 @@ import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent import androidx.lifecycle.OnLifecycleEvent
import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.R
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.topjohnwu.superuser.NoShellException
sealed class SmartSnackbar { sealed class SmartSnackbar {
companion object { companion object {
@@ -22,6 +24,10 @@ sealed class SmartSnackbar {
return if (holder == null) ToastWrapper(Toast.makeText(app, text, Toast.LENGTH_LONG)) else return if (holder == null) ToastWrapper(Toast.makeText(app, text, Toast.LENGTH_LONG)) else
SnackbarWrapper(Snackbar.make(holder, text ?: null.toString(), Snackbar.LENGTH_LONG)) 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 { class Register(private val view: View) : LifecycleObserver {

View File

@@ -109,6 +109,7 @@
<item quantity="other">%d 个接口</item> <item quantity="other">%d 个接口</item>
</plurals> </plurals>
<string name="root_unavailable">似乎没有 root</string>
<string name="failure_reason_unknown">未知 #%d</string> <string name="failure_reason_unknown">未知 #%d</string>
<string name="exception_interface_not_found">错误:未找到下游接口</string> <string name="exception_interface_not_found">错误:未找到下游接口</string>
<string name="noisy_su_failure">发生异常,详情请查看调试信息。</string> <string name="noisy_su_failure">发生异常,详情请查看调试信息。</string>

View File

@@ -120,6 +120,7 @@
<item quantity="other">%d interfaces</item> <item quantity="other">%d interfaces</item>
</plurals> </plurals>
<string name="root_unavailable">Root unavailable</string>
<string name="failure_reason_unknown">unknown #%d</string> <string name="failure_reason_unknown">unknown #%d</string>
<string name="exception_interface_not_found">Fatal: Downstream interface not found</string> <string name="exception_interface_not_found">Fatal: Downstream interface not found</string>
<string name="noisy_su_failure">Something went wrong, please check the debug information.</string> <string name="noisy_su_failure">Something went wrong, please check the debug information.</string>