diff --git a/README.md b/README.md index 49dbf2fb..4c84b6f0 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The following features in the app requires it to be installed under `/system/pri One way to do this is to use [App systemizer for Magisk](https://github.com/Magisk-Modules-Repo/terminal_systemizer). * (since Android 11, since app v2.9.1) `android.permission.BLUETOOTH_PRIVILEGED`: Use the Bluetooth tethering shortcut switch in app. -* (prior to Android 11, since app v2.4.0) `android.permission.OVERRIDE_WIFI_CONFIG`: Read/write system Wi-Fi hotspot configuration. ([#117](https://github.com/Mygod/VPNHotspot/issues/117)) +* (Android 8-10, since app v2.4.0) `android.permission.OVERRIDE_WIFI_CONFIG`: Read/write system Wi-Fi hotspot configuration. ([#117](https://github.com/Mygod/VPNHotspot/issues/117)) Installing as system app also has the side benefit of launching root daemon less frequently due to having privileged permissions listed below. 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 ebf5162b..1e47c928 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -23,6 +23,7 @@ import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat import be.mygod.vpnhotspot.net.wifi.WifiApManager import be.mygod.vpnhotspot.root.WifiApCommands +import be.mygod.vpnhotspot.util.getRootCause import be.mygod.vpnhotspot.util.readableMessage import be.mygod.vpnhotspot.widget.SmartSnackbar import kotlinx.coroutines.Dispatchers @@ -95,7 +96,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), data.notifyChange() } override fun onException(e: Exception) { - if (e !is InvocationTargetException || e.targetException !is SecurityException) Timber.w(e) + if (e.getRootCause() !is SecurityException) Timber.w(e) GlobalScope.launch(Dispatchers.Main.immediate) { val context = parent.context ?: app Toast.makeText(context, e.readableMessage, Toast.LENGTH_LONG).show() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt index 95867425..77c314a7 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt @@ -196,7 +196,9 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick null } catch (eRoot: Exception) { eRoot.addSuppressed(e) - Timber.w(eRoot) + if (Build.VERSION.SDK_INT !in 26..29 || eRoot.getRootCause() !is SecurityException) { + Timber.w(eRoot) + } SmartSnackbar.make(eRoot).show() null } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt index ca4e2e62..3cdbdd18 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringTileService.kt @@ -18,6 +18,7 @@ import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.net.TetheringManager.tetheredIfaces import be.mygod.vpnhotspot.net.wifi.WifiApManager import be.mygod.vpnhotspot.util.broadcastReceiver +import be.mygod.vpnhotspot.util.getRootCause import be.mygod.vpnhotspot.util.readableMessage import be.mygod.vpnhotspot.util.stopAndUnbind import kotlinx.coroutines.Dispatchers @@ -122,7 +123,7 @@ sealed class TetheringTileService : IpNeighbourMonitoringTileService(), Tetherin updateTile() } override fun onException(e: Exception) { - if (e !is InvocationTargetException || e.targetException !is SecurityException) Timber.w(e) + if (e.getRootCause() !is SecurityException) Timber.w(e) GlobalScope.launch(Dispatchers.Main.immediate) { Toast.makeText(this@TetheringTileService, e.readableMessage, Toast.LENGTH_LONG).show() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt index 3ecb54ee..b31bc4b8 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt @@ -6,6 +6,7 @@ import android.content.* import android.net.InetAddresses import android.os.Build import android.os.Handler +import android.os.RemoteException import android.text.Spannable import android.text.SpannableString import android.text.SpannableStringBuilder @@ -32,9 +33,11 @@ import java.net.NetworkInterface import java.net.SocketException import java.util.concurrent.Executor -val Throwable.readableMessage: String get() = if (this is InvocationTargetException) { - targetException.readableMessage -} else localizedMessage ?: javaClass.name +tailrec fun Throwable.getRootCause(): Throwable { + if (this is InvocationTargetException || this is RemoteException) return (cause ?: return this).getRootCause() + return this +} +val Throwable.readableMessage: String get() = getRootCause().run { localizedMessage ?: javaClass.name } /** * This is a hack: we wrap longs around in 1 billion and such. Hopefully every language counts in base 10 and this works