Suppress SecurityException on Android 8-10

This commit is contained in:
Mygod
2020-07-07 04:20:24 +08:00
parent 293140f64e
commit 82dc01ab37
5 changed files with 14 additions and 7 deletions

View File

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