Better log alarms

This commit is contained in:
Milos Kozak 2022-06-08 13:39:08 +02:00
parent 0273ba7bf0
commit 024a902316
5 changed files with 18 additions and 18 deletions

View file

@ -249,7 +249,7 @@ class MainApp : DaggerApplication() {
override fun onTerminate() { override fun onTerminate() {
aapsLogger.debug(LTag.CORE, "onTerminate") aapsLogger.debug(LTag.CORE, "onTerminate")
unregisterActivityLifecycleCallbacks(activityMonitor) unregisterActivityLifecycleCallbacks(activityMonitor)
alarmSoundServiceHelper.stopService(this) alarmSoundServiceHelper.stopService(this, "onTerminate")
super.onTerminate() super.onTerminate()
} }
} }

View file

@ -17,12 +17,12 @@ import info.nightscout.androidaps.databinding.OverviewNotificationItemBinding
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.IconsProvider import info.nightscout.androidaps.interfaces.IconsProvider
import info.nightscout.androidaps.interfaces.NotificationHolder import info.nightscout.androidaps.interfaces.NotificationHolder
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewNotification import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewNotification
import info.nightscout.androidaps.services.AlarmSoundServiceHelper import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -68,7 +68,7 @@ class NotificationStore @Inject constructor(
store.add(n) store.add(n)
if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true) && n !is NotificationWithAction) if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true) && n !is NotificationWithAction)
raiseSystemNotification(n) raiseSystemNotification(n)
if (n.soundId != null && n.soundId != 0) alarmSoundServiceHelper.startAlarm(context, n.soundId!!) if (n.soundId != null && n.soundId != 0) alarmSoundServiceHelper.startAlarm(context, n.soundId!!, n.text)
Collections.sort(store, NotificationComparator()) Collections.sort(store, NotificationComparator())
return true return true
} }
@ -77,7 +77,7 @@ class NotificationStore @Inject constructor(
fun remove(id: Int): Boolean { fun remove(id: Int): Boolean {
for (i in store.indices) { for (i in store.indices) {
if (store[i].id == id) { if (store[i].id == id) {
if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context) if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context, "Removed " + store[i].text)
aapsLogger.debug(LTag.NOTIFICATION, "Notification removed: " + store[i].text) aapsLogger.debug(LTag.NOTIFICATION, "Notification removed: " + store[i].text)
store.removeAt(i) store.removeAt(i)
return true return true
@ -92,7 +92,7 @@ class NotificationStore @Inject constructor(
while (i < store.size) { while (i < store.size) {
val n = store[i] val n = store[i]
if (n.validTo != 0L && n.validTo < System.currentTimeMillis()) { if (n.validTo != 0L && n.validTo < System.currentTimeMillis()) {
if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context) if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context, "Expired " + store[i].text)
aapsLogger.debug(LTag.NOTIFICATION, "Notification expired: " + store[i].text) aapsLogger.debug(LTag.NOTIFICATION, "Notification expired: " + store[i].text)
store.removeAt(i) store.removeAt(i)
i-- i--

View file

@ -74,11 +74,11 @@ class ErrorDialog : DaggerDialogFragment() {
} }
binding.mute.setOnClickListener { binding.mute.setOnClickListener {
uel.log(Action.ERROR_DIALOG_MUTE, Sources.Unknown) uel.log(Action.ERROR_DIALOG_MUTE, Sources.Unknown)
stopAlarm() stopAlarm("Mute")
} }
binding.mute5min.setOnClickListener { binding.mute5min.setOnClickListener {
uel.log(Action.ERROR_DIALOG_MUTE_5MIN, Sources.Unknown) uel.log(Action.ERROR_DIALOG_MUTE_5MIN, Sources.Unknown)
stopAlarm() stopAlarm("Mute 5 min")
handler.postDelayed(this::startAlarm, T.mins(5).msecs()) handler.postDelayed(this::startAlarm, T.mins(5).msecs())
} }
startAlarm() startAlarm()
@ -110,14 +110,14 @@ class ErrorDialog : DaggerDialogFragment() {
super.dismissAllowingStateLoss() super.dismissAllowingStateLoss()
helperActivity?.finish() helperActivity?.finish()
handler.removeCallbacksAndMessages(null) handler.removeCallbacksAndMessages(null)
stopAlarm() stopAlarm("Dismiss")
} }
private fun startAlarm() { private fun startAlarm() {
if (sound != 0) if (sound != 0)
alarmSoundServiceHelper.startAlarm(ctx, sound) alarmSoundServiceHelper.startAlarm(ctx, sound, "$title:$status")
} }
private fun stopAlarm() = private fun stopAlarm(reason: String) =
alarmSoundServiceHelper.stopService(ctx) alarmSoundServiceHelper.stopService(ctx, reason)
} }

View file

@ -8,7 +8,7 @@ open class Notification {
var id = 0 var id = 0
var date: Long = 0 var date: Long = 0
var text: String? = null var text: String = ""
var level = 0 var level = 0
var validTo: Long = 0 var validTo: Long = 0
@RawRes var soundId: Int? = null @RawRes var soundId: Int? = null

View file

@ -28,8 +28,8 @@ class AlarmSoundServiceHelper @Inject constructor(
private val notificationHolder: NotificationHolder private val notificationHolder: NotificationHolder
) { ) {
fun startAlarm(context: Context, sound: Int) { fun startAlarm(context: Context, sound: Int, reason: String) {
aapsLogger.debug(LTag.CORE, "Starting alarm") aapsLogger.debug(LTag.CORE, "Starting alarm from $reason")
val connection = object : ServiceConnection { val connection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) { override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
// The binder of the service that returns the instance that is created. // The binder of the service that returns the instance that is created.
@ -62,8 +62,8 @@ class AlarmSoundServiceHelper @Inject constructor(
} }
} }
fun stopService(context: Context) { fun stopService(context: Context, reason: String) {
aapsLogger.debug(LTag.CORE, "Stopping alarm") aapsLogger.debug(LTag.CORE, "Stopping alarm from $reason")
val alarm = Intent(context, AlarmSoundService::class.java) val alarm = Intent(context, AlarmSoundService::class.java)
context.stopService(alarm) context.stopService(alarm)
} }