fix: updateStatus 添加 try-catch 防止系统关机时 DeadSystemException

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dongliang
2026-04-27 15:07:22 +09:30
parent fb884ea816
commit 977c2dd0d2

View File

@@ -24,6 +24,7 @@ import com.xiaoqu.watch.util.DeviceUtil
import com.xiaoqu.watch.util.NetworkUtil import com.xiaoqu.watch.util.NetworkUtil
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import timber.log.Timber
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
@@ -104,8 +105,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
} }
} }
/** 更新状态信息显示 */ /** 更新状态信息显示try-catch 保护,防止系统关机时 DeadSystemException */
private fun updateStatus() { private fun updateStatus() {
try {
val dateInfo = DateUtil.getDateInfo() val dateInfo = DateUtil.getDateInfo()
val sb = StringBuilder() val sb = StringBuilder()
sb.appendLine("${dateInfo.date} ${dateInfo.week} ${dateInfo.time}") sb.appendLine("${dateInfo.date} ${dateInfo.week} ${dateInfo.time}")
@@ -119,6 +121,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
sb.appendLine("屏幕: ${if (screenController.isScreenOn()) "亮" else "灭"}") sb.appendLine("屏幕: ${if (screenController.isScreenOn()) "亮" else "灭"}")
sb.appendLine("NFC: ${if (nfcController.isOpen()) "开" else "关"}") sb.appendLine("NFC: ${if (nfcController.isOpen()) "开" else "关"}")
binding.tvStatus.text = sb.toString() binding.tvStatus.text = sb.toString()
} catch (e: Exception) {
Timber.w(e, "更新状态信息异常")
}
} }
/** 绑定测试按钮 */ /** 绑定测试按钮 */