feat(android): background-run exemption — wizard card + backup tab hint #1392

Merged
chris merged 4 commits from fix/android-battery-exemption into main 2026-10-25 20:34:23 +01:00
Owner

Problem\nAndroid (Doze + aggressive OEM battery savers) can defer or kill the periodic WorkManager backup — the app had no battery-optimization handling at all, so backups could silently stall on Samsung/Xiaomi/Huawei devices. This is the gap every background-backup app covers with an "always run in background" ask.\n\n## What it does\n- PowerExemption boundary (PowerManager-backed) + REQUEST_IGNORE_BATTERY_OPTIMIZATIONS manifest permission; request fires the real system dialog (resolve-guarded no-op).\n- Wizard: 4th card "Immer im Hintergrund ausführen" in the backup step — tap-to-ask only (never auto-fires; unlike runtime permissions this dialog is intrusive), granted state flips in place on resume. Not counted as a required/optional permission — it's a system setting.\n- Backup tab: quiet hint card (title + where-to-check hint + Allow) only while the exemption is missing; disappears entirely when granted.\n- de/en/da strings in parity; ON_RESUME-refreshing rememberExemptState() helper (JVM-tested).\n\n## Verification\n./gradlew :app:testDebugUnitTest :core:test :app:assembleDebug → BUILD SUCCESSFUL, 1009 tests / 0 failures (new: ExemptStateTest 4, PowerExemptionRobolectricTest 3; BackupPermissionsTest 108 regression green). Android CI image scoped runs apply.

## Problem\nAndroid (Doze + aggressive OEM battery savers) can defer or kill the periodic WorkManager backup — the app had no battery-optimization handling at all, so backups could silently stall on Samsung/Xiaomi/Huawei devices. This is the gap every background-backup app covers with an "always run in background" ask.\n\n## What it does\n- `PowerExemption` boundary (PowerManager-backed) + `REQUEST_IGNORE_BATTERY_OPTIMIZATIONS` manifest permission; request fires the real system dialog (resolve-guarded no-op).\n- **Wizard**: 4th card "Immer im Hintergrund ausführen" in the backup step — tap-to-ask only (never auto-fires; unlike runtime permissions this dialog is intrusive), granted state flips in place on resume. Not counted as a required/optional permission — it's a system setting.\n- **Backup tab**: quiet hint card (title + where-to-check hint + Allow) only while the exemption is missing; disappears entirely when granted.\n- de/en/da strings in parity; ON_RESUME-refreshing `rememberExemptState()` helper (JVM-tested).\n\n## Verification\n`./gradlew :app:testDebugUnitTest :core:test :app:assembleDebug` → BUILD SUCCESSFUL, 1009 tests / 0 failures (new: ExemptStateTest 4, PowerExemptionRobolectricTest 3; BackupPermissionsTest 108 regression green). Android CI image scoped runs apply.
- manifest: REQUEST_IGNORE_BATTERY_OPTIMIZATIONS so the 6h unmetered
  WorkManager backup is not deferred/killed by Doze or OEM battery
  savers (user-consented via system dialog)
- PowerExemption interface + PowerExemptionImpl (PowerManager
  isIgnoringBatteryOptimizations / ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
  with resolvability guard and ActivityNotFoundException no-op); the
  action constant is @hide in AOSP, so the literal is used
- strings background_run_* appended to de/en/da (parity, append only)
- FakePowerExemption fake + Robolectric tests for isExempt/requestExemption
  (started intent action/data/flags, unresolvable no-op)
Fix-2 UI wiring: AppContainer exposes PowerExemption; MainActivity
threads it through MemoriesApp to both surfaces. The wizard's backup
step gains a fourth card (no required/optional tag — a system setting,
not a permission; tap-to-ask only, the intrusive dialog never fires
itself), and the backup tab gains a quiet hint card at the end of the
status area — silent once exempt. A shared rememberExemptState helper
re-reads the boundary on every ON_RESUME, so returning from the system
dialog flips both cards without recreation; its state machine is JVM-
tested against FakePowerExemption. Existing background_run_* strings
reused as-is; BackupStatusViewModel untouched.
copy(android): tighten background_run body wording (avoid title echo)
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Deploy review instance (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 6s
Build and Deploy / Android unit tests and debug APK (push) Successful in 4m26s
5ab7f654e6
chris merged commit 0862541076 into main 2026-10-25 20:34:23 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1392
No description provided.