mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package io.legado.app.help
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.SystemClock
|
||||
@@ -14,11 +19,19 @@ object AppFreezeMonitor {
|
||||
Handler(HandlerThread("AppFreezeMonitor").apply { start() }.looper)
|
||||
}
|
||||
|
||||
fun init() {
|
||||
val screenStatusReceiver by lazy {
|
||||
ScreenStatusReceiver()
|
||||
}
|
||||
|
||||
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||
fun init(context: Context) {
|
||||
if (!AppConfig.recordLog) {
|
||||
context.unregisterReceiver(screenStatusReceiver)
|
||||
return
|
||||
}
|
||||
|
||||
context.registerReceiver(screenStatusReceiver, screenStatusReceiver.filter)
|
||||
|
||||
var previous = SystemClock.uptimeMillis()
|
||||
|
||||
val runnable = object : Runnable {
|
||||
@@ -27,7 +40,7 @@ object AppFreezeMonitor {
|
||||
val elapsed = current - previous
|
||||
val extra = elapsed - 3000
|
||||
|
||||
if (extra > 100) {
|
||||
if (extra > 300) {
|
||||
LogUtils.d(TAG, "检测到应用被系统冻结,时长:$extra 毫秒")
|
||||
}
|
||||
|
||||
@@ -41,4 +54,19 @@ object AppFreezeMonitor {
|
||||
handler.postDelayed(runnable, 3000)
|
||||
}
|
||||
|
||||
class ScreenStatusReceiver : BroadcastReceiver() {
|
||||
|
||||
val filter = IntentFilter().apply {
|
||||
addAction(Intent.ACTION_SCREEN_ON)
|
||||
addAction(Intent.ACTION_SCREEN_OFF)
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
when (intent?.action) {
|
||||
Intent.ACTION_SCREEN_ON -> LogUtils.d(TAG, "SCREEN_ON")
|
||||
Intent.ACTION_SCREEN_OFF -> LogUtils.d(TAG, "SCREEN_OFF")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
||||
LogUtils.upLevel()
|
||||
LogUtils.logDeviceInfo()
|
||||
LiveEventBus.config().enableLogger(AppConfig.recordLog)
|
||||
AppFreezeMonitor.init()
|
||||
AppFreezeMonitor.init(appCtx)
|
||||
}
|
||||
|
||||
PreferKey.processText -> sharedPreferences?.let {
|
||||
|
||||
Reference in New Issue
Block a user