Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 1 | package com.android.launcher3; |
| 2 | |
| 3 | import android.app.backup.BackupAgent; |
| 4 | import android.app.backup.BackupDataInput; |
| 5 | import android.app.backup.BackupDataOutput; |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 6 | import android.os.ParcelFileDescriptor; |
| 7 | |
Sunny Goyal | 49f19f0 | 2017-01-05 14:36:02 -0800 | [diff] [blame] | 8 | import com.android.launcher3.logging.FileLog; |
Sunny Goyal | e8f7d5a | 2016-05-24 11:30:14 -0700 | [diff] [blame] | 9 | import com.android.launcher3.provider.RestoreDbTask; |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 10 | |
Alex Chau | 29a96ad | 2022-02-10 13:12:20 +0000 | [diff] [blame] | 11 | import java.io.File; |
| 12 | import java.io.IOException; |
| 13 | |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 14 | public class LauncherBackupAgent extends BackupAgent { |
| 15 | |
Alex Chau | 29a96ad | 2022-02-10 13:12:20 +0000 | [diff] [blame] | 16 | private static final String TAG = "LauncherBackupAgent"; |
| 17 | |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 18 | @Override |
Sunny Goyal | 49f19f0 | 2017-01-05 14:36:02 -0800 | [diff] [blame] | 19 | public void onCreate() { |
| 20 | super.onCreate(); |
| 21 | // Set the log dir as LauncherAppState is not initialized during restore. |
| 22 | FileLog.setDir(getFilesDir()); |
| 23 | } |
| 24 | |
| 25 | @Override |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 26 | public void onRestore( |
| 27 | BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) { |
| 28 | // Doesn't do incremental backup/restore |
| 29 | } |
| 30 | |
| 31 | @Override |
Alex Chau | 29a96ad | 2022-02-10 13:12:20 +0000 | [diff] [blame] | 32 | public void onRestoreFile(ParcelFileDescriptor data, long size, File destination, int type, |
| 33 | long mode, long mtime) throws IOException { |
| 34 | // Remove old files which might contain obsolete attributes like idp_grid_name in shared |
| 35 | // preference that will obstruct backup's attribute from writing to shared preferences. |
| 36 | if (destination.delete()) { |
Charlie Anderson | c9d11e8 | 2023-08-02 11:41:55 -0400 | [diff] [blame] | 37 | FileLog.d(TAG, "onRestoreFile: Removed obsolete file " + destination); |
Alex Chau | 29a96ad | 2022-02-10 13:12:20 +0000 | [diff] [blame] | 38 | } |
| 39 | super.onRestoreFile(data, size, destination, type, mode, mtime); |
| 40 | } |
| 41 | |
| 42 | @Override |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 43 | public void onBackup( |
| 44 | ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) { |
| 45 | // Doesn't do incremental backup/restore |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void onRestoreFinished() { |
Charlie Anderson | c9d11e8 | 2023-08-02 11:41:55 -0400 | [diff] [blame] | 50 | FileLog.d(TAG, "onRestoreFinished: set pending for RestoreDbTask"); |
Sunny Goyal | 68031ca | 2021-08-02 12:23:44 -0700 | [diff] [blame] | 51 | RestoreDbTask.setPending(this); |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 52 | } |
| 53 | } |