Skip to content

Commit accbcf1

Browse files
Add special backup action for adaptive brightness data
Searching through the code in frameworks/base/services/core/java/com/android/server/display/, these two files are the relevant ones. Adaptive brightness in its current form was introduced for Android 9, and as per https://cs.android.com/android/_/android/platform/frameworks/base/+/3d9c19f2fd34cccac6fe09877ae9a6b4563a063e the storage directory moved from /data/system_de to /data/system for Android 14. Restoring this data will likely be a bit tricky, because it seems the files are only read on startup, and afterwards the BrightnessTracker will always write back its in-memory values, overwriting any other data that might be present on disk. Since the BrightnessTracker also writes its state during a regular reboot, it seems the only thing that could possibly work (other than an offline-restore through recovery or whatever) would be an immediate abrupt reboot through the `reboot` command. I haven't tested this, though, because I didn't want to mess with my phone's adaptive brightness data (which currently works very nicely).
1 parent 671da90 commit accbcf1

File tree

4 files changed

+272
-0
lines changed

4 files changed

+272
-0
lines changed

app/src/main/java/com/machiav3lli/backup/dbs/entity/SpecialInfo.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ open class SpecialInfo : PackageInfo {
104104
val systemDir = "/data/system"
105105
val userDir = "$systemDir/users/$userId"
106106
val systemCeDir = "/data/system_ce/$userId"
107+
val systemDeDirGlobal = "/data/system_de"
107108
val vendorDeDir = "/data/vendor_de/$userId"
108109
val specPrefix = "$ "
109110

@@ -142,6 +143,33 @@ open class SpecialInfo : PackageInfo {
142143
), R.drawable.ic_accounts
143144
)
144145
)
146+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
147+
val brightnessStatsBaseDir = if (Build.VERSION.SDK_INT <
148+
Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
149+
systemDeDirGlobal
150+
} else {
151+
systemDir
152+
}
153+
specialInfos
154+
.add(
155+
SpecialInfo(
156+
"special.adaptive.brightness",
157+
specPrefix + context.getString(R.string.spec_adaptiveBrightness),
158+
Build.VERSION.RELEASE,
159+
Build.VERSION.SDK_INT, arrayOf(
160+
// Note: Restoring these files very likely only works if
161+
// the device is abruptly rebooted after restoring them.
162+
// Also for a full backup of the adaptive brightness data,
163+
// the Device Health Service's app data needs to be backed
164+
// up, too.
165+
"$brightnessStatsBaseDir/ambient_brightness_stats.xml",
166+
"$brightnessStatsBaseDir/brightness_events.xml",
167+
"$systemDir/display-manager-state.xml"
168+
),
169+
R.drawable.ic_adaptive_brightness
170+
)
171+
)
172+
}
145173
specialInfos
146174
.add(
147175
SpecialInfo(
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Neo Backup: open-source apps backup and restore app.
3+
~ Copyright (C) 2020 Antonios Hazim
4+
~
5+
~ This program is free software: you can redistribute it and/or modify
6+
~ it under the terms of the GNU Affero General Public License as
7+
~ published by the Free Software Foundation, either version 3 of the
8+
~ License, or (at your option) any later version.
9+
~
10+
~ This program is distributed in the hope that it will be useful,
11+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
~ GNU Affero General Public License for more details.
14+
~
15+
~ You should have received a copy of the GNU Affero General Public License
16+
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
-->
18+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:width="38dp"
20+
android:height="38dp"
21+
android:viewportWidth="32"
22+
android:viewportHeight="32">
23+
24+
<path
25+
android:fillColor="@color/ic_special"
26+
android:pathData="M16,16m-16,0a16,16 0,1 1,32 0a16,16 0,1 1,-32 0" />
27+
28+
<group
29+
android:scaleX="0.295"
30+
android:scaleY="0.295">
31+
32+
<path
33+
android:fillColor="#00000000"
34+
android:pathData="M9,27L9,81"
35+
android:strokeWidth="0.8"
36+
android:strokeColor="#55FFFFFF" />
37+
<path
38+
android:fillColor="#00000000"
39+
android:pathData="M19,15L19,93"
40+
android:strokeWidth="0.8"
41+
android:strokeColor="#55FFFFFF" />
42+
<path
43+
android:fillColor="#00000000"
44+
android:pathData="M29,8L29,100"
45+
android:strokeWidth="0.8"
46+
android:strokeColor="#55FFFFFF" />
47+
<path
48+
android:fillColor="#00000000"
49+
android:pathData="M39,4L39,104"
50+
android:strokeWidth="0.8"
51+
android:strokeColor="#55FFFFFF" />
52+
<path
53+
android:fillColor="#00000000"
54+
android:pathData="M49,2L49,106"
55+
android:strokeWidth="0.8"
56+
android:strokeColor="#55FFFFFF" />
57+
<path
58+
android:fillColor="#00000000"
59+
android:pathData="M59,2L59,106"
60+
android:strokeWidth="0.8"
61+
android:strokeColor="#55FFFFFF" />
62+
<path
63+
android:fillColor="#00000000"
64+
android:pathData="M69,4L69,104"
65+
android:strokeWidth="0.8"
66+
android:strokeColor="#55FFFFFF" />
67+
<path
68+
android:fillColor="#00000000"
69+
android:pathData="M79,8L79,100"
70+
android:strokeWidth="0.8"
71+
android:strokeColor="#55FFFFFF" />
72+
<path
73+
android:fillColor="#00000000"
74+
android:pathData="M89,15L89,93"
75+
android:strokeWidth="0.8"
76+
android:strokeColor="#55FFFFFF" />
77+
<path
78+
android:fillColor="#00000000"
79+
android:pathData="M99,27L99,81"
80+
android:strokeWidth="0.8"
81+
android:strokeColor="#55FFFFFF" />
82+
<path
83+
android:fillColor="#00000000"
84+
android:pathData="M27,9L81,9"
85+
android:strokeWidth="0.8"
86+
android:strokeColor="#55FFFFFF" />
87+
<path
88+
android:fillColor="#00000000"
89+
android:pathData="M15,19L93,19"
90+
android:strokeWidth="0.8"
91+
android:strokeColor="#55FFFFFF" />
92+
<path
93+
android:fillColor="#00000000"
94+
android:pathData="M8,29L100,29"
95+
android:strokeWidth="0.8"
96+
android:strokeColor="#55FFFFFF" />
97+
<path
98+
android:fillColor="#00000000"
99+
android:pathData="M4,39L104,39"
100+
android:strokeWidth="0.8"
101+
android:strokeColor="#55FFFFFF" />
102+
<path
103+
android:fillColor="#00000000"
104+
android:pathData="M2,49L106,49"
105+
android:strokeWidth="0.8"
106+
android:strokeColor="#55FFFFFF" />
107+
<path
108+
android:fillColor="#00000000"
109+
android:pathData="M2,59L106,59"
110+
android:strokeWidth="0.8"
111+
android:strokeColor="#55FFFFFF" />
112+
<path
113+
android:fillColor="#00000000"
114+
android:pathData="M4,69L104,69"
115+
android:strokeWidth="0.8"
116+
android:strokeColor="#55FFFFFF" />
117+
<path
118+
android:fillColor="#00000000"
119+
android:pathData="M8,79L100,79"
120+
android:strokeWidth="0.8"
121+
android:strokeColor="#55FFFFFF" />
122+
<path
123+
android:fillColor="#00000000"
124+
android:pathData="M15,89L93,89"
125+
android:strokeWidth="0.8"
126+
android:strokeColor="#55FFFFFF" />
127+
<path
128+
android:fillColor="#00000000"
129+
android:pathData="M27,99L81,99"
130+
android:strokeWidth="0.8"
131+
android:strokeColor="#55FFFFFF" />
132+
<path
133+
android:fillColor="#00000000"
134+
android:pathData="M19,29L89,29"
135+
android:strokeWidth="0.8"
136+
android:strokeColor="#55FFFFFF" />
137+
<path
138+
android:fillColor="#00000000"
139+
android:pathData="M19,39L89,39"
140+
android:strokeWidth="0.8"
141+
android:strokeColor="#55FFFFFF" />
142+
<path
143+
android:fillColor="#00000000"
144+
android:pathData="M19,49L89,49"
145+
android:strokeWidth="0.8"
146+
android:strokeColor="#55FFFFFF" />
147+
<path
148+
android:fillColor="#00000000"
149+
android:pathData="M19,59L89,59"
150+
android:strokeWidth="0.8"
151+
android:strokeColor="#55FFFFFF" />
152+
<path
153+
android:fillColor="#00000000"
154+
android:pathData="M19,69L89,69"
155+
android:strokeWidth="0.8"
156+
android:strokeColor="#55FFFFFF" />
157+
<path
158+
android:fillColor="#00000000"
159+
android:pathData="M19,79L89,79"
160+
android:strokeWidth="0.8"
161+
android:strokeColor="#55FFFFFF" />
162+
<path
163+
android:fillColor="#00000000"
164+
android:pathData="M29,19L29,89"
165+
android:strokeWidth="0.8"
166+
android:strokeColor="#55FFFFFF" />
167+
<path
168+
android:fillColor="#00000000"
169+
android:pathData="M39,19L39,89"
170+
android:strokeWidth="0.8"
171+
android:strokeColor="#55FFFFFF" />
172+
<path
173+
android:fillColor="#00000000"
174+
android:pathData="M49,19L49,89"
175+
android:strokeWidth="0.8"
176+
android:strokeColor="#55FFFFFF" />
177+
<path
178+
android:fillColor="#00000000"
179+
android:pathData="M59,19L59,89"
180+
android:strokeWidth="0.8"
181+
android:strokeColor="#55FFFFFF" />
182+
<path
183+
android:fillColor="#00000000"
184+
android:pathData="M69,19L69,89"
185+
android:strokeWidth="0.8"
186+
android:strokeColor="#55FFFFFF" />
187+
<path
188+
android:fillColor="#00000000"
189+
android:pathData="M79,19L79,89"
190+
android:strokeWidth="0.8"
191+
android:strokeColor="#55FFFFFF" />
192+
</group>
193+
194+
<group
195+
android:scaleX="0.085"
196+
android:scaleY="0.085"
197+
android:translateX="5"
198+
android:translateY="5">
199+
<path
200+
android:fillColor="#00000000"
201+
android:pathData="M128,140m-40,0a40,40 0,1 1,80 0a40,40 0,1 1,-80 0"
202+
android:strokeWidth="16"
203+
android:strokeColor="?backgroundColor"
204+
android:strokeLineCap="round"
205+
android:strokeLineJoin="round" />
206+
<path
207+
android:fillColor="#00000000"
208+
android:pathData="M196,116a59.8,59.8 0,0 1,48 24"
209+
android:strokeWidth="16"
210+
android:strokeColor="?backgroundColor"
211+
android:strokeLineCap="round"
212+
android:strokeLineJoin="round" />
213+
<path
214+
android:fillColor="#00000000"
215+
android:pathData="M12,140a59.8,59.8 0,0 1,48 -24"
216+
android:strokeWidth="16"
217+
android:strokeColor="?backgroundColor"
218+
android:strokeLineCap="round"
219+
android:strokeLineJoin="round" />
220+
<path
221+
android:fillColor="#00000000"
222+
android:pathData="M70.4,216a64.1,64.1 0,0 1,115.2 0"
223+
android:strokeWidth="16"
224+
android:strokeColor="?backgroundColor"
225+
android:strokeLineCap="round"
226+
android:strokeLineJoin="round" />
227+
<path
228+
android:fillColor="#00000000"
229+
android:pathData="M60,116A32,32 0,1 1,91.4 78"
230+
android:strokeWidth="16"
231+
android:strokeColor="?backgroundColor"
232+
android:strokeLineCap="round"
233+
android:strokeLineJoin="round" />
234+
<path
235+
android:fillColor="#00000000"
236+
android:pathData="M164.6,78A32,32 0,1 1,196 116"
237+
android:strokeWidth="16"
238+
android:strokeColor="?backgroundColor"
239+
android:strokeLineCap="round"
240+
android:strokeLineJoin="round" />
241+
</group>
242+
</vector>

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,5 @@
406406
<string name="prefs_theme_dynamic_light">Hell mit dynamischen Farben</string>
407407
<string name="prefs_theme_system_black">Systemthema (Schwarz)</string>
408408
<string name="prefs_theme_dynamic_dark">Dunkel mit dynamischen Farben</string>
409+
<string name="spec_adaptiveBrightness">Automatische Helligkeit</string>
409410
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
<string name="spec_wallpaper">Wallpaper</string>
233233
<string name="spec_fingerprint">Fingerprints</string>
234234
<string name="spec_wifiAccessPoints">Wireless access points</string>
235+
<string name="spec_adaptiveBrightness">Adaptive brightness</string>
235236
<string name="error_creating_notification_channel">Unable to create notification channel</string>
236237
<string name="error_updating_schedule_mode">Error updating %1$s of schedule %2$d</string>
237238
<string name="permission_not_granted">Permission to access external storage is required</string>

0 commit comments

Comments
 (0)