Skip to content

fix: refresh widgets after idle#978

Merged
ovitrif merged 1 commit into
masterfrom
codex/github-mention-bug]-android-os-widgets-show-stale-data-af
Jun 5, 2026
Merged

fix: refresh widgets after idle#978
ovitrif merged 1 commit into
masterfrom
codex/github-mention-bug]-android-os-widgets-show-stale-data-af

Conversation

@ovitrif
Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif commented May 31, 2026

Fixes #975

Description

This PR:

  1. Refactors Android widget refresh scheduling into one AppWidgetRefreshScheduler entry point.
  2. Keeps periodic WorkManager refresh as the primary 15-minute best-effort engine, with a sparse inexact idle alarm for app-not-running catch-up and a 30-minute native widget fallback.
  3. Restores scheduling from app startup, foreground, widget enable/update/configuration, boot, package replacement, and the foreground-service stop action.
  4. Updates the worker to refresh only active widget types, track per-type attempt/success freshness, skip fresh remote-backed types, and retry stale/failed types independently.
  5. Treats Facts as local cached rotation, so a Facts update is not counted as proof that remote-backed widgets refreshed.
  6. Removes runtime-only user-present/idle-mode receiver registration and avoids tying widget refresh to LightningNodeService.onDestroy.

Preview

Before Idle After Idle
beforeIdle afterIdle

QA Notes

Manual Tests

  • 1. Android launcher → install the PR dev build → add Price, Headlines, Blocks, Facts, and Weather OS widgets → open Bitkit once → stop Bitkit from the persistent notification → keep Wi-Fi/data on → unplug USB/power → lock the phone and leave it untouched for 30+ minutes → unlock without opening Bitkit: remote-backed widgets update without launching the app.
    Result: Real idle wait from 19:15 to 20:43 on June 2, 2026: Price changed from $67.443 to $67.314, Blocks changed from 952,132 to 952,138, News changed headline, and Facts rotated locally. Weather stayed at $0.28, which is valid when the fee estimate itself has not changed.
  • 3. Logs: device logs after the real wait show Bitkit widget update notifications after unlock, successful widget update records, and a later catch-up alarm/worker pass that saw all active widget types and skipped remote-backed types as fresh.
  • 4. negative: Android quick settings → disable Wi-Fi/data → repeat the idle test: remote-backed widgets may stay stale while offline; Facts may still rotate from local cached facts only.
  • 5. negative: Android Settings → Apps → Bitkit → Force stop → return to launcher: Android 15 may disable widget updates/pending intents until the user launches or interacts with Bitkit again; this is expected platform behavior.

Automated Checks

  • Unit tests added: cover widget freshness policy, scheduler cancel/schedule behavior, boot/package/alarm receiver delegation, and worker attempt/success handling in app/src/test/java/to/bitkit/appwidget/.
  • Unit test modified: covers the foreground-service stop action scheduling widget catch-up before shutdown in app/src/test/java/to/bitkit/androidServices/LightningNodeServiceTest.kt.
  • git diff --check passed locally.
  • ./gradlew compileDevDebugKotlin passed locally.
  • ./gradlew testDevDebugUnitTest passed locally.
  • ./gradlew detekt passed locally.

@ovitrif ovitrif self-assigned this May 31, 2026
@ovitrif ovitrif force-pushed the codex/github-mention-bug]-android-os-widgets-show-stale-data-af branch from efea229 to 295079f Compare May 31, 2026 19:18
@ovitrif ovitrif removed the codex label May 31, 2026
@ovitrif ovitrif added this to the 2.3.0 milestone May 31, 2026
@ovitrif ovitrif requested a review from piotr-iohk May 31, 2026 19:50
@ovitrif ovitrif marked this pull request as ready for review May 31, 2026 19:51
@ovitrif ovitrif enabled auto-merge May 31, 2026 19:51
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@piotr-iohk

This comment was marked as resolved.

@ovitrif

This comment was marked as resolved.

@ovitrif

This comment was marked as resolved.

@jvsena42

This comment was marked as resolved.

jvsena42

This comment was marked as resolved.

@ovitrif

This comment was marked as resolved.

@piotr-iohk

This comment was marked as resolved.

@ovitrif

This comment was marked as low quality.

@ovitrif

This comment was marked as resolved.

@piotr-iohk

This comment was marked as resolved.

@ovitrif ovitrif marked this pull request as draft June 2, 2026 14:50
auto-merge was automatically disabled June 2, 2026 14:50

Pull request was converted to draft

@ovitrif

This comment was marked as resolved.

@ovitrif

This comment was marked as resolved.

@ovitrif

This comment was marked as resolved.

@ovitrif ovitrif force-pushed the codex/github-mention-bug]-android-os-widgets-show-stale-data-af branch 2 times, most recently from 19f5fc1 to ddf4c64 Compare June 2, 2026 17:08
@ovitrif ovitrif marked this pull request as ready for review June 2, 2026 19:26
@ovitrif ovitrif force-pushed the codex/github-mention-bug]-android-os-widgets-show-stale-data-af branch from ddf4c64 to 89bb9cd Compare June 2, 2026 19:35
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@ovitrif

This comment was marked as resolved.

@jvsena42

This comment was marked as resolved.

@piotr-iohk

This comment was marked as resolved.

@piotr-iohk

This comment was marked as resolved.

@jvsena42

This comment was marked as resolved.

@piotr-iohk

This comment was marked as resolved.

@ovitrif

This comment was marked as resolved.

@ovitrif

This comment was marked as resolved.

@jvsena42

This comment was marked as outdated.

@ovitrif

This comment was marked as resolved.

@piotr-iohk

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Comment thread app/src/main/java/to/bitkit/appwidget/AppWidgetRefreshScheduler.kt Outdated
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Comment thread app/src/main/java/to/bitkit/appwidget/AppWidgetRefreshScheduler.kt
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Comment thread app/src/main/java/to/bitkit/appwidget/AppWidgetRefreshPolicy.kt
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@ovitrif ovitrif requested a review from jvsena42 June 5, 2026 11:52
@piotr-iohk
Copy link
Copy Markdown
Collaborator

Testing again after recent updates...

@ovitrif ovitrif force-pushed the codex/github-mention-bug]-android-os-widgets-show-stale-data-af branch from 7dc6e59 to ee47435 Compare June 5, 2026 13:40
@ovitrif
Copy link
Copy Markdown
Collaborator Author

ovitrif commented Jun 5, 2026

Testing again after recent updates...

@piotr-iohk Pls use latest commit, after squashing all prevs:
ee47435

note that your comment was right before the squashing push and I will add new dev mode setting to clear logs; so I can test this and other OS widgets PRs easier without having to clear logs.

@ovitrif
Copy link
Copy Markdown
Collaborator Author

ovitrif commented Jun 5, 2026

PS. Can still have an issue for this 🙏🏻 , I am not discouraging that.

Yeah, that's for the sake of documenting it somewhere - so it is not only in our collective knowledge 👍

Issue filed:

Copy link
Copy Markdown
Member

@jvsena42 jvsena42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on physical Mi Note 11

  1. Fresh app
  2. Set Block widgets OS and in-app
  3. Finish app by notificatoin
  4. disable wifi and block app
  5. On middle for 12 minutes
  6. unlock phone
  7. turn on wifi
  8. Both widgets updated
Screen_recording_20260605_105739.mp4

Copy link
Copy Markdown
Collaborator

@piotr-iohk piotr-iohk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested again latest head (before squash) on Samsung S22 / Android 16, power savings off, 30+ min idle after stop-from-notification. Price/Blocks/weather updated without opening app. Headlines may remain unchanged within 30 min by design (60 min interval).

@ovitrif ovitrif enabled auto-merge June 5, 2026 14:12
@ovitrif ovitrif merged commit 4da3173 into master Jun 5, 2026
17 checks passed
@ovitrif ovitrif deleted the codex/github-mention-bug]-android-os-widgets-show-stale-data-af branch June 5, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Android OS widgets show stale data after idle

4 participants