Skip to content

fix: OS widget cleanup crash and ordering#935

Merged
ovitrif merged 4 commits intomasterfrom
fix/os-widgets-fixes
May 7, 2026
Merged

fix: OS widget cleanup crash and ordering#935
ovitrif merged 4 commits intomasterfrom
fix/os-widgets-fixes

Conversation

@jvsena42
Copy link
Copy Markdown
Member

@jvsena42 jvsena42 commented May 7, 2026

This PR:

  1. Fixes an intermittent NPE crash when an OS widget is removed or its configuration is cancelled.
  2. Reorders the widget config activity's provider lookup so it matches the in-app AddWidgetsScreen ordering.

Description

1. Receiver crash on widget removal

All five Glance receivers (Price, Headlines, Blocks, Facts, Weather) overrode onDeleted to unregister the widget entry from the preferences store. The override called super.onDeleted() first and then goAsync() itself. Glance's GlanceAppWidgetReceiver.onDeleted already consumes the broadcast PendingResult via its internal goAsync extension, so the second call returned null and pendingResult.finish() in our finally block threw a NullPointerException. Per Glance's own KDoc:

if you override any of the methods of this class, you must call the super implementation, and you must not call AppWidgetProvider.goAsync, as it will be called by the super implementation.

The unregister logic now lives on each GlanceAppWidget.onDelete(context, glanceId) override, which Glance invokes inside its own broadcast-scoped coroutine. The onDeleted overrides on every receiver are removed, so there is no longer a duplicate goAsync call to NPE on.

2. Provider lookup ordering

AppWidgetConfigActivity.resolveWidgetType was listing the providers in Headlines, Price, Blocks, Weather order. Reordered to Price, Headlines, Blocks, Weather so it matches the AppWidgetType enum, the manifest receivers, the refresh worker, and the in-app AddWidgetsScreen listing. Pure code-style change with no behavior difference.

A note on the system widget picker order

The Android system widget picker (long-press home → Widgets) is rendered by the launcher, not by us. The Pixel launcher groups widgets within an app by their targetCellWidth × targetCellHeight area, in descending order, then by manifest declaration order within each size bucket. Because appwidget_info_facts.xml declares targetCellHeight="1" while every other widget declares targetCellHeight="2", Facts ends up alone in the smaller bucket and appears last in the picker. That positioning is launcher-controlled and intentional given the widget's existing 1-cell-tall design — this PR does not change widget sizes.

Preview

Screen_recording_20260507_120327.webm

QA Notes

Manual Tests

  • 1. Add a Bitcoin Headlines OS widget with Bitkit running in the background → tap the back arrow on the configure screen → no crash, widget is removed, app stays alive. Repeat several times to cover the intermittent timing.
  • 2. Repeat step 1 for Price, Blocks, Facts, and Weather OS widgets.

@jvsena42 jvsena42 self-assigned this May 7, 2026
@claude

This comment has been minimized.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 7, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@ovitrif ovitrif added this to the 2.3.0 milestone May 7, 2026
@ovitrif ovitrif requested review from ovitrif and piotr-iohk May 7, 2026 20:42
@ovitrif
Copy link
Copy Markdown
Collaborator

ovitrif commented May 7, 2026

Facts ends up alone in the smaller bucket and appears last in the picker.

Not really but irrelevant that it's not accurate, what matters is the conclusion that we can't alter the ordering in the OS picker programmatically:

Base automatically changed from feat/weather-v61 to master May 7, 2026 21:01
Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

Tested fixes with success 😎

@ovitrif ovitrif merged commit 87c788e into master May 7, 2026
18 checks passed
@ovitrif ovitrif deleted the fix/os-widgets-fixes branch May 7, 2026 21:02
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.

2 participants