From accbcf1436ff5a17ac49bc5c224d7f8029bf4ae2 Mon Sep 17 00:00:00 2001 From: Jan Henning Date: Sun, 21 Jan 2024 20:55:19 +0100 Subject: [PATCH] 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). --- .../backup/dbs/entity/SpecialInfo.kt | 28 ++ .../res/drawable/ic_adaptive_brightness.xml | 242 ++++++++++++++++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 272 insertions(+) create mode 100644 app/src/main/res/drawable/ic_adaptive_brightness.xml diff --git a/app/src/main/java/com/machiav3lli/backup/dbs/entity/SpecialInfo.kt b/app/src/main/java/com/machiav3lli/backup/dbs/entity/SpecialInfo.kt index 8a3f6893a9..0f939882a3 100644 --- a/app/src/main/java/com/machiav3lli/backup/dbs/entity/SpecialInfo.kt +++ b/app/src/main/java/com/machiav3lli/backup/dbs/entity/SpecialInfo.kt @@ -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 = "$ " @@ -142,6 +143,33 @@ open class SpecialInfo : PackageInfo { ), R.drawable.ic_accounts ) ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + val brightnessStatsBaseDir = 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 files very likely only works if + // the device is abruptly rebooted after restoring them. + // Also for a full backup of the adaptive brightness data, + // the Device Health Service's app data needs to be backed + // up, too. + "$brightnessStatsBaseDir/ambient_brightness_stats.xml", + "$brightnessStatsBaseDir/brightness_events.xml", + "$systemDir/display-manager-state.xml" + ), + R.drawable.ic_adaptive_brightness + ) + ) + } specialInfos .add( SpecialInfo( diff --git a/app/src/main/res/drawable/ic_adaptive_brightness.xml b/app/src/main/res/drawable/ic_adaptive_brightness.xml new file mode 100644 index 0000000000..c40d01413a --- /dev/null +++ b/app/src/main/res/drawable/ic_adaptive_brightness.xml @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index dca50fa814..1c960dff07 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -406,4 +406,5 @@ Hell mit dynamischen Farben Systemthema (Schwarz) Dunkel mit dynamischen Farben + Automatische Helligkeit \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b51858d768..16f683bd54 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -232,6 +232,7 @@ Wallpaper Fingerprints Wireless access points + Adaptive brightness Unable to create notification channel Error updating %1$s of schedule %2$d Permission to access external storage is required