diff options
| author | 2024-07-19 23:28:36 +0000 | |
|---|---|---|
| committer | 2024-07-31 19:39:15 +0000 | |
| commit | 3fbdf467b829e767a9ed718543873efb511986ba (patch) | |
| tree | fc34791262c31bdd5a324367f17210d70dbc8c6c | |
| parent | e00c7d22ffc990ddc2420c1a02017f226a71bb85 (diff) | |
Implementing smart device config backup
This CL makes sure that we only backup the device confugration when it is different from the currently backed up value
Flag: EXEMPT bug fix
Fix: 347959516
Test: manually verified
Change-Id: Ib326c5ba901cce8e8aea76c4c544d0baf6ab15eb
| -rw-r--r-- | packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java | 116 |
1 files changed, 80 insertions, 36 deletions
diff --git a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java index cbbce1a74e94..866359399128 100644 --- a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java +++ b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java @@ -120,6 +120,14 @@ public class WallpaperBackupAgent extends BackupAgent { static final String SYSTEM_GENERATION = "system_gen"; static final String LOCK_GENERATION = "lock_gen"; + static final String DEVICE_CONFIG_WIDTH = "device_config_width"; + + static final String DEVICE_CONFIG_HEIGHT = "device_config_height"; + + static final String DEVICE_CONFIG_SECONDARY_WIDTH = "device_config_secondary_width"; + + static final String DEVICE_CONFIG_SECONDARY_HEIGHT = "device_config_secondary_height"; + static final float DEFAULT_ACCEPTABLE_PARALLAX = 0.2f; // If this file exists, it means we exceeded our quota last time @@ -175,6 +183,16 @@ public class WallpaperBackupAgent extends BackupAgent { // disk churn. final int lastSysGeneration = sharedPrefs.getInt(SYSTEM_GENERATION, /* defValue= */ -1); final int lastLockGeneration = sharedPrefs.getInt(LOCK_GENERATION, /* defValue= */ -1); + + final int deviceConfigWidth = sharedPrefs.getInt( + DEVICE_CONFIG_WIDTH, /* defValue= */ -1); + final int deviceConfigHeight = sharedPrefs.getInt( + DEVICE_CONFIG_HEIGHT, /* defValue= */ -1); + final int deviceConfigSecondaryWidth = sharedPrefs.getInt( + DEVICE_CONFIG_SECONDARY_WIDTH, /* defValue= */ -1); + final int deviceConfigSecondaryHeight = sharedPrefs.getInt( + DEVICE_CONFIG_SECONDARY_HEIGHT, /* defValue= */ -1); + final int sysGeneration = mWallpaperManager.getWallpaperId(FLAG_SYSTEM); final int lockGeneration = mWallpaperManager.getWallpaperId(FLAG_LOCK); final boolean sysChanged = (sysGeneration != lastSysGeneration); @@ -195,7 +213,11 @@ public class WallpaperBackupAgent extends BackupAgent { backupWallpaperInfoFile(/* sysOrLockChanged= */ sysChanged || lockChanged, data); backupSystemWallpaperFile(sharedPrefs, sysChanged, sysGeneration, data); backupLockWallpaperFileIfItExists(sharedPrefs, lockChanged, lockGeneration, data); - backupDeviceInfoFile(data); + + final boolean isDeviceConfigChanged = isDeviceConfigChanged(deviceConfigWidth, + deviceConfigHeight, deviceConfigSecondaryWidth, deviceConfigSecondaryHeight); + + backupDeviceInfoFile(sharedPrefs, isDeviceConfigChanged, data); } catch (Exception e) { Slog.e(TAG, "Unable to back up wallpaper", e); mEventLogger.onBackupException(e); @@ -209,50 +231,72 @@ public class WallpaperBackupAgent extends BackupAgent { } } + private boolean isDeviceConfigChanged(int width, int height, int secondaryWidth, + int secondaryHeight) { + Point currentDimensions = getScreenDimensions(); + Display smallerDisplay = getSmallerDisplayIfExists(); + Point currentSecondaryDimensions = smallerDisplay != null ? getRealSize(smallerDisplay) : + new Point(0, 0); + + return (currentDimensions.x != width + || currentDimensions.y != height + || currentSecondaryDimensions.x != secondaryWidth + || currentSecondaryDimensions.y != secondaryHeight); + } + /** * This method backs up the device dimension information. The device data will always get * overwritten when triggering a backup */ - private void backupDeviceInfoFile(FullBackupDataOutput data) + private void backupDeviceInfoFile(SharedPreferences sharedPrefs, boolean isDeviceConfigChanged, + FullBackupDataOutput data) throws IOException { final File deviceInfoStage = new File(getFilesDir(), WALLPAPER_BACKUP_DEVICE_INFO_STAGE); - // save the dimensions of the device with xml formatting - Point dimensions = getScreenDimensions(); - Display smallerDisplay = getSmallerDisplayIfExists(); - Point secondaryDimensions = smallerDisplay != null ? getRealSize(smallerDisplay) : - new Point(0, 0); - - deviceInfoStage.createNewFile(); - FileOutputStream fstream = new FileOutputStream(deviceInfoStage, false); - TypedXmlSerializer out = Xml.resolveSerializer(fstream); - out.startDocument(null, true); - out.startTag(null, "dimensions"); - - out.startTag(null, "width"); - out.text(String.valueOf(dimensions.x)); - out.endTag(null, "width"); - - out.startTag(null, "height"); - out.text(String.valueOf(dimensions.y)); - out.endTag(null, "height"); - - if (smallerDisplay != null) { - out.startTag(null, "secondarywidth"); - out.text(String.valueOf(secondaryDimensions.x)); - out.endTag(null, "secondarywidth"); + if (isDeviceConfigChanged) { + // save the dimensions of the device with xml formatting + Point dimensions = getScreenDimensions(); + Display smallerDisplay = getSmallerDisplayIfExists(); + Point secondaryDimensions = smallerDisplay != null ? getRealSize(smallerDisplay) : + new Point(0, 0); + + deviceInfoStage.createNewFile(); + FileOutputStream fstream = new FileOutputStream(deviceInfoStage, false); + TypedXmlSerializer out = Xml.resolveSerializer(fstream); + out.startDocument(null, true); + out.startTag(null, "dimensions"); + + out.startTag(null, "width"); + out.text(String.valueOf(dimensions.x)); + out.endTag(null, "width"); + + out.startTag(null, "height"); + out.text(String.valueOf(dimensions.y)); + out.endTag(null, "height"); + + if (smallerDisplay != null) { + out.startTag(null, "secondarywidth"); + out.text(String.valueOf(secondaryDimensions.x)); + out.endTag(null, "secondarywidth"); + + out.startTag(null, "secondaryheight"); + out.text(String.valueOf(secondaryDimensions.y)); + out.endTag(null, "secondaryheight"); + } - out.startTag(null, "secondaryheight"); - out.text(String.valueOf(secondaryDimensions.y)); - out.endTag(null, "secondaryheight"); + out.endTag(null, "dimensions"); + out.endDocument(); + fstream.flush(); + FileUtils.sync(fstream); + fstream.close(); + + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putInt(DEVICE_CONFIG_WIDTH, dimensions.x); + editor.putInt(DEVICE_CONFIG_HEIGHT, dimensions.y); + editor.putInt(DEVICE_CONFIG_SECONDARY_WIDTH, secondaryDimensions.x); + editor.putInt(DEVICE_CONFIG_SECONDARY_HEIGHT, secondaryDimensions.y); + editor.apply(); } - - out.endTag(null, "dimensions"); - out.endDocument(); - fstream.flush(); - FileUtils.sync(fstream); - fstream.close(); - if (DEBUG) Slog.v(TAG, "Storing device dimension data"); backupFile(deviceInfoStage, data); } |