Repository navigation
fix(widget): fix battery widget charging status not updating (#1269) - #1671
Open
ArunaK-netizen wants to merge 1 commit into
Open
ArunaK-netizen wants to merge 1 commit into
ArunaK-netizen wants to merge 1 commit into
Conversation
…sw#1269) Resolve sameerasw#1269 where existing battery widgets fail to update charging status on charger connect/disconnect. - Overcome Android 8.0+ implicit broadcast restrictions for power connect/disconnect by registering a dynamic BroadcastReceiver in EssentialsApp for 0ms in-memory updates and adding BatteryWidgetJobService (JobScheduler requiresCharging) for background wakeup. - Fix Glance stale DataStore preference poisoning where cached false locked existing widgets by dynamically reading the sticky Intent.ACTION_BATTERY_CHANGED and BatteryManager in provideGlance. - Force Glance RemoteViews recomposition by updating a timestamp key across all GlanceIds in updateWidgets. - Fix crash on widget placement by safely guarding goAsync execution. - Update widget on user present (screen unlock) and status bar automation events.
ArunaK-netizen
force-pushed
the
fix/battery-widget-not-updating-on-charge
branch
from
November 6, 2026 14:05
731603b to
dad3e8e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve #1269 where existing battery widgets fail to update charging status on charger connect/disconnect.
Description
Closes #1269
This PR fixes an issue where existing home-screen battery widgets failed to update their charging state (lightning bolt and charging ring) when plugging in or unplugging the charger.
Technical Details:
BatteriesWidget.kt): Previously,provideGlancefell back to a cached boolean in DataStore. Once the phone was unplugged,falsewas saved; becausefalse != null, existing widgets were permanently locked intofalse, ignoring actual hardware status (while newly placed widgets withnullpreferences rendered correctly). The widget now directly inspects the stickyIntent.ACTION_BATTERY_CHANGEDintent andBatteryManager.isCharging.EssentialsApp.kt&BatteryWidgetJobService.kt): Manifest receivers for implicit broadcasts likeACTION_POWER_CONNECTEDare dropped by Android OS when the app is in the background. We resolved this across three tiers:EssentialsAppfor 0ms latency when the app is in memory.BatteryWidgetJobService(JobSchedulerwithsetRequiresCharging(true)) to wake up and refresh the widget when connected even if the app process was terminated.ACTION_USER_PRESENTinBatteriesWidgetReceiverto refresh widgets immediately when unlocking the screen.BatteriesWidgetReceiver.kt): Added a timestamp key (widget_last_update_ts) so Glance detects state changes and recomposesRemoteViews. Also guardedgoAsync()calls to preventIllegalStateExceptioncrashes during initial widget placement.Type of change
UI changes
before.mp4
after.mp4
Checklist
Before submitting, please make sure:
develop(notmain)../gradlew assembleDebug../gradlew testDebugUnitTest.SettingsRepositoryfor keys and getter/setter methods.FeatureRegistry.ktfor search indexing.ui/core/(RoundedCardContainer,IconToggleItem, etc.).res/values/strings.xmland drawables use rounded variants (R.drawable.rounded_*).