add crash reporter

This commit is contained in:
Kr328 committed 2020-02-25 20:38:55 +08:00
1 parent 93dff86383
commit 053300919c
6 files changed
+77 -27

No files matched your search

@@ -7,7 +7,12 @@ import com.github.kr328.clash.remote.Broadcasts
import com.github.kr328.clash.remote.Remote
import com.microsoft.appcenter.AppCenter
import com.microsoft.appcenter.analytics.Analytics
import com.microsoft.appcenter.crashes.AbstractCrashesListener
import com.microsoft.appcenter.crashes.Crashes
import com.microsoft.appcenter.crashes.CrashesListener
import com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog
import com.microsoft.appcenter.crashes.model.ErrorReport
import java.lang.Exception
@Suppress("unused")
class MainApplication : Application() {
@@ -1,7 +1,5 @@
package com.github.kr328.clash.dump
import com.github.kr328.clash.core.utils.Log
object LogcatDumper {
fun dump(): List<String> {
return try {
@@ -32,4 +30,4 @@ object LogcatDumper {
emptyList()
}
}
}
}
@@ -12,39 +12,50 @@ import kotlinx.coroutines.withContext
class ClashClient(val service: IClashManager) {
suspend fun setSelectProxy(name: String, proxy: String): Boolean = withContext(Dispatchers.IO) {
return@withContext service.setSelectProxy(name, proxy)
Utils.callRemote {
service.setSelectProxy(name, proxy)
}
}
suspend fun startHealthCheck(group: String) = withContext(Dispatchers.IO) {
CompletableDeferred<Unit>().apply {
service.startHealthCheck(group, object : IStreamCallback.Stub() {
override fun complete() {
this@apply.complete(Unit)
}
Utils.callRemote {
CompletableDeferred<Unit>().apply {
service.startHealthCheck(group, object : IStreamCallback.Stub() {
override fun complete() {
this@apply.complete(Unit)
}
override fun completeExceptionally(reason: String?) {
this@apply.completeExceptionally(RemoteException(reason))
}
override fun completeExceptionally(reason: String?) {
this@apply.completeExceptionally(RemoteException(reason))
}
override fun send(data: ParcelableContainer?) {}
})
override fun send(data: ParcelableContainer?) {}
})
}
}
}.await()
suspend fun queryAllProxyGroups(): List<ProxyGroup> = withContext(Dispatchers.IO) {
service.queryAllProxies().list
Utils.callRemote {
service.queryAllProxies().list
}
}
suspend fun queryGeneral(): General = withContext(Dispatchers.IO) {
service.queryGeneral()
Utils.callRemote {
service.queryGeneral()
}
}
suspend fun queryBandwidth(): Long =
withContext(Dispatchers.IO) {
service.queryBandwidth()
suspend fun queryBandwidth(): Long = withContext(Dispatchers.IO) {
Utils.callRemote {
service.queryBandwidth()
}
}
suspend fun setProxyMode(mode: General.Mode) = withContext(Dispatchers.IO) {
service.setProxyMode(mode.toString())
Utils.callRemote {
service.setProxyMode(mode.toString())
}
}
}
@@ -8,26 +8,38 @@ import kotlinx.coroutines.withContext
class ProfileClient(private val service: IProfileService) {
suspend fun queryProfiles(): Array<ClashProfileEntity> = withContext(Dispatchers.IO) {
service.queryProfiles()
Utils.callRemote {
service.queryProfiles()
}
}
suspend fun queryActiveProfile(): ClashProfileEntity? = withContext(Dispatchers.IO) {
service.queryActiveProfile()
Utils.callRemote {
service.queryActiveProfile()
}
}
suspend fun enqueueRequest(request: ProfileRequest) = withContext(Dispatchers.IO) {
service.enqueueRequest(request)
Utils.callRemote {
service.enqueueRequest(request)
}
}
suspend fun setActiveProfile(id: Long) = withContext(Dispatchers.IO) {
service.setActiveProfile(id)
Utils.callRemote {
service.setActiveProfile(id)
}
}
suspend fun requestProfileEditUri(id: Long): String? = withContext(Dispatchers.IO) {
service.requestProfileEditUri(id)
Utils.callRemote {
service.requestProfileEditUri(id)
}
}
suspend fun commitProfileEditUri(uri: String) = withContext(Dispatchers.IO) {
service.commitProfileEditUri(uri)
Utils.callRemote {
service.commitProfileEditUri(uri)
}
}
}
@@ -0,0 +1,24 @@
package com.github.kr328.clash.remote
import android.os.DeadObjectException
import com.github.kr328.clash.dump.LogcatDumper
import com.microsoft.appcenter.crashes.Crashes
import com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog
internal object Utils {
fun <T>callRemote(block: () -> T): T {
return try {
block()
}
catch (e: DeadObjectException) {
val log = LogcatDumper.dump().joinToString(separator = "\n")
val attachmentLog = ErrorAttachmentLog
.attachmentWithText(log, "logcat.txt")
Crashes.trackError(e, null, listOf(attachmentLog))
throw e
}
}
}