Dashboard: Show charging speed and wattage in more places - #55
Merged
Conversation
The sticky battery broadcast carries EXTRA_MAX_CHARGING_CURRENT and EXTRA_MAX_CHARGING_VOLTAGE: what the connected supply claims it can deliver. Both land on BatteryReadout as nullable fields (absent or non-positive normalizes to null: a device with nothing connected reports 0, which is "no charger", not "a 0 W charger"). StatsPowerCalculator gains advertisedMaxMilliwatts for that pair, with AOSP BatteryStatus' 5 V fallback when only the current is reported, plus readout-taking overloads so callers don't re-derive the charge-power gate. The existing implausibility cap applies to the advertised figure too. Also adds the strings the upcoming wattage surfaces need.
The card headline said only "Charging" whatever the charger delivered. It now classifies the measured draw into slowly / (plain) / fast / very fast. The slow and fast bars are AOSP SettingsLib's own bucket values (5 W / 7.5 W), applied to the measured draw rather than the charger-advertised maximum AOSP classifies: the measurement is what the battery actually receives and is the number printed one line below the headline. The very-fast bar at 15 W is ours, twice the AOSP fast bar, so modern 20 W+ chargers aren't all lumped in as merely "fast". A draw that can't be measured keeps the plain title rather than guessing a speed. BatteryEffect moves from main/ui/dashboard to battery/ui: its tri-state "is the battery positively not charging" semantics are needed by the battery hub and the session detail screen, which must not import a dashboard presentation file. It gains chargePowerFallbackRes, the shared rule for what to print in place of a withheld wattage.
The wattage was only ever visible in the dashboard card's reading line and as a recorded peak/average. The battery hub's electrical section now carries "Charge power" (the gated live figure, so a discharge draw can never read as charge power) and "Charger max" (the supply's advertised capability, read through only while something is connected). The charge session detail gains a live "Power now" row, but only while the viewed session is the open one the caller vouched for: the detail query is by id and unrestricted, so it can resolve a dangling open row from an earlier boot that the boot-scoped live query rejects. The activity therefore attributes the readout only when the viewed id equals the live session's id. Both surfaces distinguish a withheld figure from a missing one: "Not charging" where the battery positively reported it isn't taking charge, "Not reported" everywhere else.
BatteryManager.EXTRA_MAX_CHARGING_CURRENT/VOLTAGE are @hide constants: BatteryService puts both into ACTION_BATTERY_CHANGED, but the symbols are absent from the public SDK's android.jar, so referencing them fails to compile. The extras themselves are readable (only the constants are missing), so the reader uses the stable AOSP string keys instead. No reflection is involved.
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.
What changed
Technical Context
BatteryManager.EXTRA_MAX_CHARGING_CURRENT/VOLTAGEare@hide, soBatteryReaderreads the extras by their literal stable AOSP keys. Values at or below zero normalize to null ("no charger" rather than "a 0 W charger"), and a missing advertised voltage falls back to AOSP's assumed 5 V.BatteryEffectmoved (git mv) from the dashboard package tobattery/ui: the hub and stats screens reuse its "Not charging" vs "Not reported" semantics, andstats/uimust not depend on dashboard presentation files. The power arithmetic lives as readout overloads onStatsPowerCalculator, which already owned the calculation.