Skip to content

Charging: Add HyperOS 3 Battery Protection support for qualified Xiaomi devices - #64

Merged
d4rken merged 4 commits into
mainfrom
feat/xiaomi-hyperos3
Aug 14, 2026
Merged

Charging: Add HyperOS 3 Battery Protection support for qualified Xiaomi devices#64
d4rken merged 4 commits into
mainfrom
feat/xiaomi-hyperos3

Conversation

@d4rken

@d4rken d4rken commented Aug 14, 2026

Copy link
Copy Markdown
Member

What changed

Adds charge control for HyperOS 3's Battery Protection mode on qualified Xiaomi devices, starting with the Redmi Note 14 (tanzanite). On these devices Amply can now read and set all three native modes: Battery protection (fixed 80% cap), Intelligent charging, and Charge fully. The temporary full-charge session uses Charge fully as the override and restores the prior mode as on other supported devices. Unqualified HyperOS 3 devices keep the diagnostics-only experience with the contribution wizard.

Technical Context

  • The gate is HyperOS 3 plus a qualified-codename allowlist, not version-only: mode 2 is model-/build-dependent within HyperOS 3 (a Poco F5 on HyperOS 3.0.2 has only the two old modes), ro.mi.os.version.code has no minor version, and mode-2 presence can't be probed at runtime (the key is absent in factory state; a read only returns the current value).
  • Hardware evidence (issue [Device support] Xiaomi 24117RN76G — settings discovery #48, tanzanite): external shell-UID writes — the same path the Shizuku service uses — move charging in both directions (write 2 below the cap holds at 80% for ~20 min; write 0 mid-hold resumes past 80), Settings UI follows each write, applied synchronously. No hardware hold signal exists in dumpsys battery, so verification is settings read-back only. The Verified-devices ledger row lands in this PR alongside the gate.
  • This is a GrapheneOS-precedent remote landing: app-level items (factory/absent-key semantics, sessions, access tiers, R8) are recorded as failing-closed known gaps in the ledger, to be verified by the contributor on the next beta via issue [Device support] Xiaomi 24117RN76G — settings discovery #48. The absent-key decode (absent = Intelligent) mirrors HyperOS 2 and is flagged in code comments.
  • The one reviewed safety-boundary change: SettingWritePolicy widens the key's write domain to {"0","1","2"}. The domain is global, so 2 becomes boundary-writable on HyperOS 2 too — accepted because no Amply code path emits it there and the HyperOS 2 decode refuses it. AdapterMutationDomainTest pins the adapter/boundary pairing.
  • Closest review focus: the new adapter's apply must value-match FixedLimit(80) exactly (the OEM cap is hard-wired), and the registry insertion must not disturb the HyperOS 2 or lab fallthrough paths — both are pinned by new tests.

Closes #48. Supersedes #63 (its ledger commit is folded into this branch).

d4rken added 2 commits August 14, 2026 09:24
… ledger

The tanzanite contributor (issue #48) ran the requested protocol via
on-device adb shell (shell UID, same path as the Shizuku service):
external write of mode 2 below the cap activated Battery Protection
with the Settings UI following, the device held 80% for ~20 minutes
under active use, and writing 0 mid-hold resumed charging past 80.
This answers the daemon-enforcement-of-external-writes question for
tanzanite mode 2. No current reading (sysfs denied) and no hardware
hold signal in dumpsys, so a future adapter is readback-only.
Support still needs gate design (mode 2 is not HyperOS-3-wide),
the reviewed write-domain widening, absent-key semantics, and a
test-build qualification run.
…mi devices

New XiaomiHyperOs3ChargingAdapter (xiaomi-hyperos3-v1) over the same
secure key as HyperOS 2, adding mode 2 = Battery protection as
FixedLimit(80). Gate: manufacturer + ro.mi.os.version.code == 3 + a
qualified-codename allowlist (ships with tanzanite) + system user.
Version-only gating is impossible: mode 2 is model-/build-dependent
within HyperOS 3 (marblein on 3.0.2 lacks it) and cannot be probed at
runtime (key absent in factory state). SYNC_READBACK only; dumpsys
battery exposes no hardware hold signal on HyperOS 3.

Both-direction hardware enforcement of external shell-UID writes was
demonstrated on tanzanite (issue #48): write 2 below the cap holds at
80%, write 0 mid-hold resumes past 80, Settings UI follows, applied
synchronously.

Boundary: SettingWritePolicy widens the key's write domain to
{0,1,2} globally; accepted on HyperOS 2 because no code path emits 2
there and its decode refuses it (AdapterMutationDomainTest pins the
pairing). ContributionAllowlist discloses 2 as a named OEM mode.

Absent-key decode (absent = Intelligent) mirrors HyperOS 2 but is
unverified on HyperOS 3 — flagged in comments, pending the remote
qualification run before this leaves draft.
@d4rken d4rken added device support Request to add charge-control support for a device/OEM ROM: HyperOS Xiaomi / Redmi / POCO api: 36 A16 (Baklava) Shizuku Shizuku / ADB privileged access related labels Aug 14, 2026
@github-actions github-actions Bot added the enhancement New feature or request label Aug 14, 2026
d4rken added 2 commits August 14, 2026 10:18
Records the issue-#48 remote qualification (both-direction external
shell-UID write enforcement) as a Verified-devices row and documents
the GrapheneOS-precedent landing: app-level items (absent-key
semantics, sessions, access tiers, R8) stay open as failing-closed
known gaps, to be verified by the contributor on the next beta.
@d4rken
d4rken marked this pull request as ready for review August 14, 2026 08:23
@d4rken
d4rken merged commit 3c8bb2d into main Aug 14, 2026
13 checks passed
@d4rken
d4rken deleted the feat/xiaomi-hyperos3 branch August 14, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: 36 A16 (Baklava) device support Request to add charge-control support for a device/OEM enhancement New feature or request ROM: HyperOS Xiaomi / Redmi / POCO Shizuku Shizuku / ADB privileged access related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Device support] Xiaomi 24117RN76G — settings discovery

1 participant