-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from YuS1aN/dev
Merge
- Loading branch information
Showing
8 changed files
with
98 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package me.kbai.zhenxunui.tool | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager.NameNotFoundException | ||
import android.os.Build | ||
import android.util.Log | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.runBlocking | ||
import me.kbai.zhenxunui.extends.logE | ||
|
||
object CrashHandler { | ||
|
||
fun init(context: Context) { | ||
Thread.setDefaultUncaughtExceptionHandler { _, exception -> | ||
runBlocking(Dispatchers.IO) { | ||
log(context, exception) | ||
} | ||
} | ||
} | ||
|
||
private fun log(context: Context, throwable: Throwable) = logE( | ||
"MODEL: ${Build.MODEL} " + | ||
"SDK: ${Build.VERSION.SDK_INT} " + | ||
"CPU_ABI: ${Build.SUPPORTED_ABIS.contentToString()} " + | ||
"VERSION: ${getPackageVersionName(context)} " + | ||
"\n StackTrace: \n" + | ||
Log.getStackTraceString(throwable), | ||
"CRASH" | ||
) | ||
|
||
|
||
private fun getPackageVersionName(context: Context) = try { | ||
context.packageManager.getPackageInfo(context.packageName, 0).versionName | ||
} catch (e: NameNotFoundException) { | ||
"" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters