Files
lawnchair/src/com/android/launcher3/LauncherBackupAgent.java
Alex Chau 29a96adaab Fix restore not migrating to new grid
- In reinitializeAfterRestore, use db path instead of grid name to check if migration is necessary, so migration will still happen if grid names are renamed. Also, only remove the target db path instead of all non source db paths, which are not necessary to be removed.
- In LauncherBackupAgent, remove old files before restoring to avoid old files from overriding restored files e.g. grid name in shared preferences
- Make sure InvariantDeviceProfile is intialize before we set pending to false, so unsupported grids can still be initialized and then be migratead
- Renamed 6x5 grid so it no longer collides with 4x4

Fix: 218500583
Test: Restore backup from supported and unsupported grids
Change-Id: Ic78e0bc7dc44ad86bd217c736b88708ad488ac0b
2022-02-11 18:15:06 +00:00

53 lines
1.7 KiB
Java

package com.android.launcher3;
import android.app.backup.BackupAgent;
import android.app.backup.BackupDataInput;
import android.app.backup.BackupDataOutput;
import android.os.ParcelFileDescriptor;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.provider.RestoreDbTask;
import java.io.File;
import java.io.IOException;
public class LauncherBackupAgent extends BackupAgent {
private static final String TAG = "LauncherBackupAgent";
@Override
public void onCreate() {
super.onCreate();
// Set the log dir as LauncherAppState is not initialized during restore.
FileLog.setDir(getFilesDir());
}
@Override
public void onRestore(
BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) {
// Doesn't do incremental backup/restore
}
@Override
public void onRestoreFile(ParcelFileDescriptor data, long size, File destination, int type,
long mode, long mtime) throws IOException {
// Remove old files which might contain obsolete attributes like idp_grid_name in shared
// preference that will obstruct backup's attribute from writing to shared preferences.
if (destination.delete()) {
FileLog.d("LauncherBackupAgent", "Removed obsolete file: " + destination);
}
super.onRestoreFile(data, size, destination, type, mode, mtime);
}
@Override
public void onBackup(
ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) {
// Doesn't do incremental backup/restore
}
@Override
public void onRestoreFinished() {
RestoreDbTask.setPending(this);
}
}