修复负数计时回归:前台服务类型按版本显式选型;重要度改圆圈数字;置顶改上箭头(v0.10)

This commit is contained in:
XIGE
2026-11-29 10:05:14 +08:00
parent af10a29a95
commit 2bd9817d04
5 changed files with 39 additions and 18 deletions

View File

@@ -103,11 +103,18 @@ class TimerService : Service() {
private fun startForegroundCompat() {
val notification = Notif.buildOngoing(this)
// 必须显式传类型:specialUse 是 Android 14 才引入的,
// Android 12/13 不认识清单里的这个类型位,两参版本(读清单)会被拒绝,
// 服务起不来 → 每秒 tick 停掉 → 息屏后到点无人结算,通知滚成负数。
// <34 用 dataSync(Android 12 原生支持,行为与历史版本一致);
// >=34 用 specialUse 规避 dataSync 的 24 小时 6 小时累计上限。
val type = if (android.os.Build.VERSION.SDK_INT >= 34) {
android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
} else {
android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
}
runCatching {
// 两参版本会读清单里声明的前台服务类型(specialUse)。
// 不用三参 + SPECIAL_USE:该类型 Android 14 才引入,
// 在 P30 的 Android 12 上传进去会直接抛 IllegalArgumentException。
startForeground(Notif.ID_ONGOING, notification)
startForeground(Notif.ID_ONGOING, notification, type)
}.onFailure {
// 前台服务被系统拒绝(省电策略/权限)时退化为普通服务,
// 计时本身仍在 TimerCore 里走,只是通知可能不显示。