Commit eab807f
authored
General: Dedupe DataStore reads by porting SD Maid SE's DataStoreValue DSL (#26)
Amply keeps one shared Preferences DataStore, and Preferences DataStore
hands the entire snapshot to every collector on any write. None of the 14
preference flows deduplicated, so an unrelated write woke all of them.
That was user-visible: ChargeStatsRecorder stamps lastCaptureWallMillis on
every recorded sample (~20s while charging, always a new timestamp), which
re-emitted captureEnabled unchanged, restarted the flatMapLatest in
statsDashboardStates and replayed its loading marker — collapsing the
dashboard's charging card to its loading size for a frame, every 20s.
Settings are now declared with a createValue() DSL in common/datastore,
which dedupes on the raw stored value before the reader runs. The guard
lives in the primitive, so a facade cannot forget it, and it never depends
on a domain type's equals.
Settings read as a unit — a session and its provenance, the recovery
target, the interruption event, the alarm config, theme and quick-access
state — are now one @serializable record under one key (new dependency:
kotlinx-serialization-json), so a partially-written state cannot exist and
read-modify-write collapses to update {}. Independent scalars stay
separate so a hot-path write doesn't wake unrelated collectors.
Corruption semantics are chosen per record rather than globally. Records
whose decode was already all-or-nothing keep a whole-record fallback, but
ChargingPreferences parses field by field: its four facts degrade
independently, and a wholesale fallback would silently downgrade a user's
90% protective baseline to the 80% default and then persist the downgrade.
For the same reason every field except the charge policy itself is
optional — a missing pid must not take an owed restore down with it.
Also fixes a pre-existing torn read in InterruptionAssessor, which read
recovery provenance, work id and session through separate suspend calls
and could pair fields from either side of a concurrent adopt or clear.
No migration: old keys are abandoned and new ones are suffixed .v2. Test
users only. An update installed mid-session therefore loses that session's
record — wipe app data before installing.
Verified: 706 tests pass on both flavors; lintVital clean on all four
beta/release variants; R8 release builds clean with no serialization
stripping. Both blip regression tests were confirmed against a negative
control (removing the dedupe makes them fail: 6 emissions instead of 2,
providers recreated 4x instead of 1x), as were the per-field corruption,
missing-metadata and alarm-normalization guards.1 parent d00b9ef commit eab807f
35 files changed
Lines changed: 1505 additions & 417 deletions
File tree
- .claude
- rules
- app
- src
- main/java/eu/darken/amply
- alarm/core
- charging/core
- access
- common
- datastore
- serialization
- theming
- fullcharge/core
- main
- core
- ui
- dashboard
- settings
- stats
- core
- ui
- test/java/eu/darken/amply
- alarm/core
- charging/core
- common/datastore
- fullcharge/core
- main/ui/dashboard
- buildSrc/src/main/java
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
111 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
112 | 134 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
Lines changed: 42 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | 3 | | |
| 4 | + | |
| 5 | + | |
8 | 6 | | |
9 | | - | |
| 7 | + | |
10 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | | - | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | | - | |
18 | | - | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | | - | |
31 | | - | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
36 | | - | |
| 42 | + | |
| 43 | + | |
37 | 44 | | |
38 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
39 | 63 | | |
40 | | - | |
| 64 | + | |
41 | 65 | | |
42 | 66 | | |
43 | | - | |
| 67 | + | |
44 | 68 | | |
45 | 69 | | |
46 | 70 | | |
47 | | - | |
| 71 | + | |
48 | 72 | | |
49 | 73 | | |
50 | 74 | | |
51 | | - | |
| 75 | + | |
52 | 76 | | |
53 | 77 | | |
54 | | - | |
| 78 | + | |
55 | 79 | | |
56 | 80 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 81 | + | |
67 | 82 | | |
68 | 83 | | |
69 | 84 | | |
| |||
Lines changed: 99 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
13 | 63 | | |
14 | 64 | | |
15 | | - | |
| 65 | + | |
| 66 | + | |
16 | 67 | | |
17 | | - | |
18 | | - | |
19 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
20 | 79 | | |
21 | 80 | | |
22 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
23 | 84 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
29 | 88 | | |
30 | 89 | | |
31 | 90 | | |
32 | 91 | | |
33 | 92 | | |
34 | 93 | | |
35 | 94 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
39 | 98 | | |
40 | 99 | | |
41 | 100 | | |
42 | 101 | | |
43 | 102 | | |
44 | 103 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
52 | 115 | | |
53 | 116 | | |
54 | 117 | | |
55 | | - | |
| 118 | + | |
56 | 119 | | |
57 | | - | |
| 120 | + | |
58 | 121 | | |
59 | | - | |
| 122 | + | |
60 | 123 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 124 | + | |
| 125 | + | |
69 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
0 commit comments