Skip to content

Apps: Restrict battery filter to whitelisted apps#360

Merged
d4rken merged 1 commit into
mainfrom
fix/issue-359-battery-unrestricted-predicate
May 2, 2026
Merged

Apps: Restrict battery filter to whitelisted apps#360
d4rken merged 1 commit into
mainfrom
fix/issue-359-battery-unrestricted-predicate

Conversation

@d4rken
Copy link
Copy Markdown
Member

@d4rken d4rken commented May 2, 2026

What changed

The "Battery unrestricted apps" category on the Overview screen, and the matching battery filter on the Apps list, now only show apps that are actually whitelisted from battery optimization (i.e. set to Unrestricted in Android's per-app battery settings). Apps in the default Optimized state (or Restricted, on devices that expose it) no longer appear there.

Closes #359.

Technical Context

  • The filter was wired with batteryOptimization != BatteryOptimization.MANAGED_BY_SYSTEM, which matches both IGNORED (whitelisted) and OPTIMIZED (declares the perm but is not whitelisted). The label said "unrestricted" but the predicate said "any app that can request whitelisting".
  • Same predicate was duplicated in AppsFilterOptions.BATTERY_OPTIMIZATION and OverviewViewModel#SummaryCategory.BATTERY_OPT. Both flipped to == BatteryOptimization.IGNORED.
  • Explains the reporter's observation that "even after a refresh or app restart" the app stayed in the list: the underlying scan was updating the enum from IGNORED to OPTIMIZED, but the filter still matched. No One UI / Samsung quirk involved.
  • Added a per-enum-value unit test on BATTERY_OPTIMIZATION.matches. Behavioural change is intentional — anyone who relied on the chip surfacing all apps that declare the permission has lost that view; the chip now matches the Overview label semantics.

The 'Battery unrestricted apps' Overview category and the apps-list battery filter both used the predicate batteryOptimization != MANAGED_BY_SYSTEM, which matches IGNORED *and* OPTIMIZED. After a user changed an app's battery setting from Unrestricted to Optimized, a fresh scan correctly updated the enum from IGNORED to OPTIMIZED, but the filter still matched and the app stayed in the list — which the reporter saw as the data being stuck even after manual refresh and app restart.

Flip the predicate to == IGNORED in both AppsFilterOptions.BATTERY_OPTIMIZATION and OverviewViewModel#SummaryCategory.BATTERY_OPT so it actually means 'whitelisted from doze'. Adds a unit test covering all four enum values.
@d4rken d4rken marked this pull request as ready for review May 2, 2026 08:11
@d4rken d4rken merged commit ad6b3f5 into main May 2, 2026
11 checks passed
@d4rken d4rken deleted the fix/issue-359-battery-unrestricted-predicate branch May 2, 2026 08:11
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] Apps remain listed in "Battery unrestricted apps" after changing to Optimized or Restricted

1 participant