Skip to content

Commit

Permalink
Add special backup action for adaptive brightness data
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
buttercookie42 committed Jan 21, 2024
1 parent 671da90 commit d4f30fe
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/src/main/java/com/machiav3lli/backup/dbs/entity/SpecialInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ open class SpecialInfo : PackageInfo {
val systemDir = "/data/system"
val userDir = "$systemDir/users/$userId"
val systemCeDir = "/data/system_ce/$userId"
val systemDeDirGlobal = "/data/system_de"
val vendorDeDir = "/data/vendor_de/$userId"
val specPrefix = "$ "

Expand Down Expand Up @@ -142,6 +143,30 @@ open class SpecialInfo : PackageInfo {
), R.drawable.ic_accounts
)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val baseDir = if (Build.VERSION.SDK_INT <
Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
systemDeDirGlobal
} else {
systemDir
}
specialInfos
.add(
SpecialInfo(
"special.adaptive.brightness",
specPrefix + context.getString(R.string.spec_adaptiveBrightness),
Build.VERSION.RELEASE,
Build.VERSION.SDK_INT, arrayOf(
// Note: Restoring these two files very likely only works if
// the device is abruptly rebooted immediately after
// restoring them.
"$baseDir/ambient_brightness_stats.xml",
"$baseDir/brightness_events.xml"
),
R.drawable.ic_adaptive_brightness
)
)
}
specialInfos
.add(
SpecialInfo(
Expand Down
242 changes: 242 additions & 0 deletions app/src/main/res/drawable/ic_adaptive_brightness.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Neo Backup: open-source apps backup and restore app.
~ Copyright (C) 2020 Antonios Hazim
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="38dp"
android:height="38dp"
android:viewportWidth="32"
android:viewportHeight="32">

<path
android:fillColor="@color/ic_special"
android:pathData="M16,16m-16,0a16,16 0,1 1,32 0a16,16 0,1 1,-32 0" />

<group
android:scaleX="0.295"
android:scaleY="0.295">

<path
android:fillColor="#00000000"
android:pathData="M9,27L9,81"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,15L19,93"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,8L29,100"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,4L39,104"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,2L49,106"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,2L59,106"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,4L69,104"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,8L79,100"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,15L89,93"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,27L99,81"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M27,9L81,9"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M15,19L93,19"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M8,29L100,29"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M4,39L104,39"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M2,49L106,49"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M2,59L106,59"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M4,69L104,69"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M8,79L100,79"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M15,89L93,89"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M27,99L81,99"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#55FFFFFF" />
</group>

<group
android:scaleX="0.085"
android:scaleY="0.085"
android:translateX="5"
android:translateY="5">
<path
android:fillColor="#00000000"
android:pathData="M128,140m-40,0a40,40 0,1 1,80 0a40,40 0,1 1,-80 0"
android:strokeWidth="16"
android:strokeColor="?backgroundColor"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M196,116a59.8,59.8 0,0 1,48 24"
android:strokeWidth="16"
android:strokeColor="?backgroundColor"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M12,140a59.8,59.8 0,0 1,48 -24"
android:strokeWidth="16"
android:strokeColor="?backgroundColor"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M70.4,216a64.1,64.1 0,0 1,115.2 0"
android:strokeWidth="16"
android:strokeColor="?backgroundColor"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M60,116A32,32 0,1 1,91.4 78"
android:strokeWidth="16"
android:strokeColor="?backgroundColor"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M164.6,78A32,32 0,1 1,196 116"
android:strokeWidth="16"
android:strokeColor="?backgroundColor"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</group>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,5 @@
<string name="prefs_theme_dynamic_light">Hell mit dynamischen Farben</string>
<string name="prefs_theme_system_black">Systemthema (Schwarz)</string>
<string name="prefs_theme_dynamic_dark">Dunkel mit dynamischen Farben</string>
<string name="spec_adaptiveBrightness">Automatische Helligkeit</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
<string name="spec_wallpaper">Wallpaper</string>
<string name="spec_fingerprint">Fingerprints</string>
<string name="spec_wifiAccessPoints">Wireless access points</string>
<string name="spec_adaptiveBrightness">Adaptive brightness</string>
<string name="error_creating_notification_channel">Unable to create notification channel</string>
<string name="error_updating_schedule_mode">Error updating %1$s of schedule %2$d</string>
<string name="permission_not_granted">Permission to access external storage is required</string>
Expand Down

0 comments on commit d4f30fe

Please sign in to comment.