Skip to content

Show a notice when battery "Restricted" freezes the widget - #88

Merged
timbortnik merged 1 commit into
mainfrom
feat/background-restriction-hint
Nov 9, 2026
Merged

timbortnik merged 1 commit into
mainfrom
feat/background-restriction-hint

Conversation

@timbortnik

Copy link
Copy Markdown
Owner

With battery usage set to Restricted (background usage off), Android gives the app no alarms, jobs or BOOT_COMPLETED in the background, so the widget silently stops refreshing until the app is opened. Apps can't lift the restriction, and Play only allows the battery-optimization exemption for core functions a weather widget doesn't qualify for, so the standard fix is to detect it and point the user at settings.

  • WidgetUtils.isWidgetBackgroundRestricted: ActivityManager .isBackgroundRestricted() and at least one widget placed (no notice for people who don't use the widget), exposed as method isWidgetBackgroundRestricted.
  • Home screen: one-line notice above the weather card with a Settings button opening the app's App info page; re-checked on every resume, so it goes away once background usage is allowed.
  • New string widgetBackgroundRestricted in all 36 locales (drafted, needs native-speaker review), new a11y id mirrored in e2e/a11y_ids.js, and docs/ai/widget.md notes plus an adb diagnosis row.

The new Robolectric tests pin sdk = R: without @config this suite runs at API 23, where isBackgroundRestricted() doesn't exist.

Verified on the API 30 emulator: restricted without a widget shows no notice; with a widget shows it; Settings opens App info; allowing background usage and returning removes it.

With battery usage set to Restricted (background usage off), Android gives
the app no alarms, jobs or BOOT_COMPLETED in the background, so the widget
silently stops refreshing until the app is opened. Apps can't lift the
restriction, and Play only allows the battery-optimization exemption for
core functions a weather widget doesn't qualify for, so the standard fix is
to detect it and point the user at settings.

- WidgetUtils.isWidgetBackgroundRestricted: ActivityManager
  .isBackgroundRestricted() and at least one widget placed (no notice for
  people who don't use the widget), exposed as method
  isWidgetBackgroundRestricted.
- Home screen: one-line notice above the weather card with a Settings
  button opening the app's App info page; re-checked on every resume, so it
  goes away once background usage is allowed.
- New string widgetBackgroundRestricted in all 36 locales (drafted, needs
  native-speaker review), new a11y id mirrored in e2e/a11y_ids.js, and
  docs/ai/widget.md notes plus an adb diagnosis row.

The new Robolectric tests pin sdk = R: without @config this suite runs at
API 23, where isBackgroundRestricted() doesn't exist.

Verified on the API 30 emulator: restricted without a widget shows no
notice; with a widget shows it; Settings opens App info; allowing
background usage and returning removes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 6 complexity · 2 duplication

Metric Results
Complexity 6
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@timbortnik
timbortnik merged commit d9265f2 into main Nov 9, 2026
6 checks passed
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.

1 participant