Show reason for dead state on notification.

This commit is contained in:
voussoir 2023-11-30 22:41:10 -08:00
parent 4e2beedaef
commit 42311b446b

View file

@ -57,6 +57,7 @@ class TrackerService: Service()
var last_significant_motion: Long = 0 var last_significant_motion: Long = 0
var last_watchdog: Long = 0 var last_watchdog: Long = 0
var dead_at: Long = 0 var dead_at: Long = 0
var dead_reason: String = ""
var arrived_at_home: Long = 0 var arrived_at_home: Long = 0
val TIME_UNTIL_SLEEP: Long = 5 * Keys.ONE_MINUTE_IN_MILLISECONDS val TIME_UNTIL_SLEEP: Long = 5 * Keys.ONE_MINUTE_IN_MILLISECONDS
val TIME_UNTIL_DEAD: Long = 3 * Keys.ONE_MINUTE_IN_MILLISECONDS val TIME_UNTIL_DEAD: Long = 3 * Keys.ONE_MINUTE_IN_MILLISECONDS
@ -185,7 +186,7 @@ class TrackerService: Service()
Keys.STATE_FULL_RECORDING -> state_full_recording() Keys.STATE_FULL_RECORDING -> state_full_recording()
Keys.STATE_ARRIVED_AT_HOME -> state_arrived_at_home() Keys.STATE_ARRIVED_AT_HOME -> state_arrived_at_home()
Keys.STATE_SLEEP -> state_sleep() Keys.STATE_SLEEP -> state_sleep()
Keys.STATE_DEAD -> state_dead() Keys.STATE_DEAD -> state_dead(dead_reason="Loaded previous state")
} }
} }
@ -201,6 +202,7 @@ class TrackerService: Service()
recent_displacement_locations.clear() recent_displacement_locations.clear()
arrived_at_home = 0 arrived_at_home = 0
dead_at = 0 dead_at = 0
dead_reason = ""
if (foreground_started > 0) if (foreground_started > 0)
{ {
stopForeground(STOP_FOREGROUND_DETACH) stopForeground(STOP_FOREGROUND_DETACH)
@ -217,7 +219,7 @@ class TrackerService: Service()
Log.i("VOUSSOIR", "TrackerService.state_full_power") Log.i("VOUSSOIR", "TrackerService.state_full_power")
if (! trackbook.database.ready) if (! trackbook.database.ready)
{ {
state_dead() state_dead("Database not ready")
} }
trackbook.load_database() trackbook.load_database()
tracking_state = Keys.STATE_FULL_RECORDING tracking_state = Keys.STATE_FULL_RECORDING
@ -225,6 +227,7 @@ class TrackerService: Service()
reset_location_listeners(Keys.LOCATION_INTERVAL_FULL_POWER) reset_location_listeners(Keys.LOCATION_INTERVAL_FULL_POWER)
arrived_at_home = 0 arrived_at_home = 0
dead_at = 0 dead_at = 0
dead_reason = ""
if (foreground_started == 0L) if (foreground_started == 0L)
{ {
startForeground(Keys.TRACKER_SERVICE_NOTIFICATION_ID, displayNotification()) startForeground(Keys.TRACKER_SERVICE_NOTIFICATION_ID, displayNotification())
@ -236,7 +239,7 @@ class TrackerService: Service()
} }
else else
{ {
state_dead() state_dead("No listeners enabled")
} }
displayNotification() displayNotification()
} }
@ -251,6 +254,7 @@ class TrackerService: Service()
trackbook.database.commit() trackbook.database.commit()
arrived_at_home = System.currentTimeMillis() arrived_at_home = System.currentTimeMillis()
dead_at = 0 dead_at = 0
dead_reason = ""
stop_wakelock() stop_wakelock()
displayNotification() displayNotification()
} }
@ -264,10 +268,11 @@ class TrackerService: Service()
reset_location_listeners(Keys.LOCATION_INTERVAL_SLEEP) reset_location_listeners(Keys.LOCATION_INTERVAL_SLEEP)
arrived_at_home = arrived_at_home arrived_at_home = arrived_at_home
dead_at = 0 dead_at = 0
dead_reason = ""
stop_wakelock() stop_wakelock()
displayNotification() displayNotification()
} }
fun state_dead() fun state_dead(dead_reason: String)
{ {
// This state is activated when the device is struggling to receive a GPS fix due to being // This state is activated when the device is struggling to receive a GPS fix due to being
// indoors / underground. It will be woken up again by the accelerometers or by plugging / // indoors / underground. It will be woken up again by the accelerometers or by plugging /
@ -280,6 +285,7 @@ class TrackerService: Service()
recent_displacement_locations.clear() recent_displacement_locations.clear()
arrived_at_home = 0 arrived_at_home = 0
dead_at = System.currentTimeMillis() dead_at = System.currentTimeMillis()
this.dead_reason = dead_reason
stop_wakelock() stop_wakelock()
displayNotification() displayNotification()
} }
@ -293,11 +299,12 @@ class TrackerService: Service()
reset_location_listeners(Keys.LOCATION_INTERVAL_FULL_POWER) reset_location_listeners(Keys.LOCATION_INTERVAL_FULL_POWER)
arrived_at_home = 0 arrived_at_home = 0
dead_at = 0 dead_at = 0
dead_reason = ""
stop_wakelock() stop_wakelock()
displayNotification() displayNotification()
if (!gpsLocationListenerRegistered && !networkLocationListenerRegistered) if (!gpsLocationListenerRegistered && !networkLocationListenerRegistered)
{ {
state_dead() state_dead(dead_reason="No listeners enabled")
} }
} }
@ -371,7 +378,7 @@ class TrackerService: Service()
if(! trackbook.database.ready) if(! trackbook.database.ready)
{ {
Log.i("VOUSSOIR", "TrackerService.onLocationChanged: database is not ready!!.") Log.i("VOUSSOIR", "TrackerService.onLocationChanged: database is not ready!!.")
state_dead() state_dead(dead_reason="Database not ready")
return return
} }
@ -509,26 +516,31 @@ class TrackerService: Service()
if (tracking_state == Keys.STATE_FULL_RECORDING) if (tracking_state == Keys.STATE_FULL_RECORDING)
{ {
notification_builder.setContentTitle("${timestamp} (recording)") notification_builder.setContentTitle("${timestamp} (recording)")
notification_builder.setContentText(null)
notification_builder.setSmallIcon(R.drawable.ic_satellite_24dp) notification_builder.setSmallIcon(R.drawable.ic_satellite_24dp)
} }
else if (tracking_state == Keys.STATE_ARRIVED_AT_HOME) else if (tracking_state == Keys.STATE_ARRIVED_AT_HOME)
{ {
notification_builder.setContentTitle("${timestamp} (home)") notification_builder.setContentTitle("${timestamp} (home)")
notification_builder.setContentText(null)
notification_builder.setSmallIcon(R.drawable.ic_homepoint_24dp) notification_builder.setSmallIcon(R.drawable.ic_homepoint_24dp)
} }
else if (tracking_state == Keys.STATE_SLEEP) else if (tracking_state == Keys.STATE_SLEEP)
{ {
notification_builder.setContentTitle("${timestamp} (sleeping)") notification_builder.setContentTitle("${timestamp} (sleeping)")
notification_builder.setContentText(null)
notification_builder.setSmallIcon(R.drawable.ic_sleep_24dp) notification_builder.setSmallIcon(R.drawable.ic_sleep_24dp)
} }
else if (tracking_state == Keys.STATE_DEAD) else if (tracking_state == Keys.STATE_DEAD)
{ {
notification_builder.setContentTitle("${timestamp} (dead)") notification_builder.setContentTitle("${timestamp} (dead)")
notification_builder.setContentText(dead_reason)
notification_builder.setSmallIcon(R.drawable.ic_skull_24dp) notification_builder.setSmallIcon(R.drawable.ic_skull_24dp)
} }
else if (tracking_state == Keys.STATE_STOP || tracking_state == Keys.STATE_MAPVIEW) else if (tracking_state == Keys.STATE_STOP || tracking_state == Keys.STATE_MAPVIEW)
{ {
notification_builder.setContentTitle("${timestamp} (stopped)") notification_builder.setContentTitle("${timestamp} (stopped)")
notification_builder.setContentText(null)
notification_builder.setSmallIcon(R.drawable.ic_fiber_manual_stop_24dp) notification_builder.setSmallIcon(R.drawable.ic_fiber_manual_stop_24dp)
} }
@ -838,7 +850,7 @@ class TrackerService: Service()
(now - last_significant_motion) > TIME_UNTIL_DEAD (now - last_significant_motion) > TIME_UNTIL_DEAD
) )
{ {
state_dead() state_dead(dead_reason="No GPS reception")
} }
} }
} }