forrestguice / NaturalHour

A roman timekeeping add-on for Suntimes.
GNU General Public License v3.0
30 stars 2 forks source link

Wigdet hangs #3

Closed XanderLeaDaren closed 3 years ago

XanderLeaDaren commented 3 years ago

I’ve been faced with a recurring bug for three days now, with the widget not updating itself in the morning at the exact moment I put the phone out of Airplane mode (which I set at night for sleeping).

I’m confused as to why it’s not hanging also when I switch Airplane mode off then on during the day. Maybe due to another app conflicting? (or Suntimes Clock Alarm?)

How could I provide some debug info?

forrestguice commented 3 years ago

Does the widget ever recover? Like suppose you wait a minute or two, does it eventually update? If not, does resizing the widget (smaller or larger and back again) cause the widget to recover?

The update mechanism is similar (but not exactly the same) as that used by Suntimes. It may be worth observing the world map or clock widget to see if it behaves the same. It's unlikely there's a conflict, but it is fragile. I broke it a few commits ago while adding additional widget sizes (5x3) and only discovered it just now.

If you have access to the device's logcat there are debug lines (or lack thereof) that might give some clues. Every time the widget updates it should look something like.

onReceive: suntimes.naturalhour.WIDGET_UPDATE(42)
D/NaturalHourWidget_5x3: updateViews: 42
D/NaturalHourWidget: saveNextSuggestedUpdate: 9:25 AM
D/NaturalHourWidget_5x3: getUpdateTimeMillis: next update is at: 1602433501041
D/NaturalHourWidget_5x3: setUpdateAlarm: 9:25 AM --> suntimes.naturalhour.WIDGET_UPDATE(42) :: 0

It should happen once a minute, but if something should prevent it, the next update doesn't get scheduled. Android should eventually go to refresh the widgets on its own though, which should schedule another update (and cause it to recover). Android likes to batch updates together (delay them up to 15min) and other annoying behaviors to save battery. Its worth trying to add the app to the battery optimization exception list. The way it should work is if a scheduled update is missed (because the device is sleeping), it should be triggered immediately upon waking up. It doesn't sound like that's happening.

XanderLeaDaren commented 3 years ago

Well, it’s been three days the issue hasn’t appeared any more, so I would close this for now and I shall let you know if anything goes wrong again. 🤨