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
// "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()
}

View File

@@ -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
}

View File

@@ -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()
}
}
}

View File

@@ -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()

View File

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

View File

@@ -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()
}

View File

@@ -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()
}
}

View File

@@ -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
}
}

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) }
} catch (e: Exception) {
Timber.w(e)
SmartSnackbar.make(e.localizedMessage).show()
SmartSnackbar.make(e).show()
}
}
if (toRemove.isNotEmpty()) {

View File

@@ -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()

View File

@@ -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 {

View File

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

View File

@@ -120,6 +120,7 @@
<item quantity="other">%d interfaces</item>
</plurals>
<string name="root_unavailable">Root unavailable</string>
<string name="failure_reason_unknown">unknown #%d</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>