|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2019-2022 Mamoe Technologies and contributors.
|
|
|
+ * Copyright 2019-2023 Mamoe Technologies and contributors.
|
|
|
*
|
|
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
|
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
|
@@ -8,11 +8,12 @@
|
|
|
*/
|
|
|
|
|
|
@file:JvmMultifileClass
|
|
|
-@file:Suppress("NOTHING_TO_INLINE")
|
|
|
|
|
|
package net.mamoe.mirai.utils
|
|
|
|
|
|
+import android.os.Build
|
|
|
import android.util.Base64
|
|
|
+import androidx.annotation.RequiresApi
|
|
|
|
|
|
|
|
|
public actual fun ByteArray.encodeBase64(): String {
|
|
@@ -23,6 +24,7 @@ public actual fun String.decodeBase64(): ByteArray {
|
|
|
return Base64.decode(this, Base64.DEFAULT)
|
|
|
}
|
|
|
|
|
|
+@RequiresApi(Build.VERSION_CODES.N)
|
|
|
@PublishedApi
|
|
|
internal class StacktraceException(override val message: String?, private val stacktrace: Array<StackTraceElement>) :
|
|
|
Exception(message, null, true, false) {
|
|
@@ -30,10 +32,23 @@ internal class StacktraceException(override val message: String?, private val st
|
|
|
override fun getStackTrace(): Array<StackTraceElement> = stacktrace
|
|
|
}
|
|
|
|
|
|
+@PublishedApi
|
|
|
+internal class StacktraceExceptionBeforeN(
|
|
|
+ override val message: String?,
|
|
|
+ private val stacktrace: Array<StackTraceElement>
|
|
|
+) : Exception(message, null) {
|
|
|
+ override fun fillInStackTrace(): Throwable = this
|
|
|
+ override fun getStackTrace(): Array<StackTraceElement> = stacktrace
|
|
|
+}
|
|
|
+
|
|
|
public actual inline fun <reified E> Throwable.unwrap(addSuppressed: Boolean): Throwable {
|
|
|
if (this !is E) return this
|
|
|
return if (addSuppressed) {
|
|
|
- val e = StacktraceException("Unwrapped exception: $this", this.stackTrace)
|
|
|
+ val e = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
+ StacktraceException("Unwrapped exception: $this", this.stackTrace)
|
|
|
+ } else {
|
|
|
+ StacktraceExceptionBeforeN("Unwrapped exception: $this", this.stackTrace)
|
|
|
+ }
|
|
|
for (throwable in this.suppressed) {
|
|
|
e.addSuppressed(throwable)
|
|
|
}
|