Details refresh: in-place row updates, one system read per figure per tick (#161)#187
Merged
Merged
Conversation
…161) Problem 1: every 3-second foreground tick tore the whole details table down (removeAllViews) and rebuilt it, losing accessibility focus and churning allocations. The table now keeps its rows keyed by label and updates the value cells in place; rows are only created/removed when their key appears or vanishes (rate warm-up, time-to-full gating). The diffing (syncRows) is a static binder-driven helper with Robolectric tests. Problem 2: redundant system reads per tick. BatteryDO now carries the OS cycle count from the same intent everything else comes from; the fragment passes the snapshot capacity and cycle count into new BatteryHealthTracker overloads instead of re-reading BatteryManager and the sticky broadcast. Insights does one sticky read and one capacity estimate per refresh, feeding pure estimatedHealthForCycles/gradeForCycles cores. Problem 3: MainActivity looked up the gauge (and details fragment) on every tick/lifecycle hop; both are now fields set in onCreate. Closes #161 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem 1 — full table rebuild every 3 s
BatteryDetailsFragmentnow keeps its rows in a label-keyed registry and each refresh updates the value cells in place; rows are created/removed only when their label genuinely appears or vanishes (rate warm-up, time-to-full gating, capacity turning unknown). Accessibility focus, scroll position and the view tree survive refreshes.syncRowshelper — covered by the newBatteryDetailsRowSyncTest(steady-state reuses the same view instances; vanished keys remove only their row; appearing keys insert at the right position, including mid-table).applyValueDecorations, so a row toggling state can''t keep a stale icon/colour.Problem 2 — redundant system reads per tick
BatteryDOnow carries the OS cycle count (EXTRA_CYCLE_COUNT, normalized to -1 likegetChargeCycleCount) extracted from the same intent as everything else — pinned bySystemServiceTest.SnapshotCycleCount.BatteryHealthTrackeroverloads (isBatteryReadingUnreliable(context, mAh),getEffectiveCycleCount(context, osCycles)) — no second capacity estimate, no sticky re-read on the 3s tick.updateHealthData) now does one sticky read + one capacity estimate per refresh, feeding everything throughisCycleCountFromOs(osCycles),getMeasuredHealthPercentage(context, mAh)and the new pure coresestimatedHealthForCycles/gradeForCycles(parameterized tests pin the degradation curve and grade boundaries to each other).Problem 3 —
findViewByIdper tick in MainActivityThe gauge and the details fragment are fields set once in
onCreate, likebatteryInsightsButtonalready was;refreshBatteryUi,onPostResume,onPause,initializeFirstValuesand the slider callback all use them.Tests
testDebugUnitTest(407 tests, 24 new) +lintDebuggreen; debug build installed on the Mate 10 Pro.On-device check: with the screen open, watch the details table across a few refreshes — values tick without the table flashing/scroll jumping, rate/time-to-full rows still come and go correctly, and the capacity "Unknown ⚠" affordance still opens its dialog.
Closes #161
🤖 Generated with Claude Code