-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b2679a
commit 31ec3c2
Showing
6 changed files
with
96 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
## 更新日誌 | ||
|
||
### v1.3.7.6 | ||
|
||
* 增加錯誤上報 | ||
|
||
### v1.3.7 | ||
|
||
* 時間顯示秒 | ||
|
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
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/lizongying/mytv0/MyTVExceptionHandler.kt
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,75 @@ | ||
package com.lizongying.mytv0 | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import android.util.Log | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import kotlin.system.exitProcess | ||
|
||
class MyTVExceptionHandler(val context: Context) : Thread.UncaughtExceptionHandler { | ||
override fun uncaughtException(t: Thread, e: Throwable) { | ||
val crashInfo = | ||
"APP: ${context.appVersionName}, PRODUCT: ${Build.PRODUCT}, DEVICE: ${Build.DEVICE}, SUPPORTED_ABIS: ${Build.SUPPORTED_ABIS.joinToString()}, BOARD: ${Build.BOARD}, MANUFACTURER: ${Build.MANUFACTURER}, MODEL: ${Build.MODEL}, VERSION: ${Build.VERSION.SDK_INT}\nThread: ${t.name}\nException: ${e.message}\nStackTrace: ${ | ||
Log.getStackTraceString( | ||
e | ||
) | ||
}\n" | ||
|
||
CoroutineScope(Dispatchers.IO).launch { | ||
saveCrashInfoToFile(crashInfo) | ||
|
||
withContext(Dispatchers.Main) { | ||
android.os.Process.killProcess(android.os.Process.myPid()) | ||
exitProcess(1) | ||
} | ||
} | ||
} | ||
|
||
private suspend fun saveCrashInfoToFile(crashInfo: String) { | ||
if (isLimit()) { | ||
Log.e(TAG, crashInfo) | ||
} else { | ||
try { | ||
saveLog(crashInfo) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
|
||
private fun isLimit(): Boolean { | ||
if (context.appVersionName != SP.version) { | ||
SP.version = context.appVersionName | ||
SP.logTimes = SP.DEFAULT_LOG_TIMES | ||
return false | ||
} else { | ||
SP.logTimes-- | ||
return SP.logTimes < 0 | ||
} | ||
} | ||
|
||
private suspend fun saveLog(crashInfo: String) { | ||
withContext(Dispatchers.IO) { | ||
val client = okhttp3.OkHttpClient.Builder().build() | ||
val request = okhttp3.Request.Builder() | ||
.url("https://lyrics.run/my-tv-0/v1/log") | ||
.method("POST", crashInfo.toRequestBody("text/plain".toMediaType())) | ||
.build() | ||
try { | ||
client.newCall(request).execute() | ||
Log.i(TAG, "log success") | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private const val TAG = "MyTVException" | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"version_code": 16975621, "version_name": "v1.3.7.5"} | ||
{"version_code": 16975622, "version_name": "v1.3.7.6"} |