1 package com.android.launcher3; 2 3 import android.app.backup.BackupAgent; 4 import android.app.backup.BackupDataInput; 5 import android.app.backup.BackupDataOutput; 6 import android.os.ParcelFileDescriptor; 7 8 import com.android.launcher3.logging.FileLog; 9 import com.android.launcher3.provider.RestoreDbTask; 10 11 import java.io.File; 12 import java.io.IOException; 13 14 public class LauncherBackupAgent extends BackupAgent { 15 16 private static final String TAG = "LauncherBackupAgent"; 17 18 @Override onCreate()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 onRestore( BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)26 public void onRestore( 27 BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) { 28 // Doesn't do incremental backup/restore 29 } 30 31 @Override onRestoreFile(ParcelFileDescriptor data, long size, File destination, int type, long mode, long mtime)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()) { 37 FileLog.d(TAG, "onRestoreFile: Removed obsolete file " + destination); 38 } 39 super.onRestoreFile(data, size, destination, type, mode, mtime); 40 } 41 42 @Override onBackup( ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState)43 public void onBackup( 44 ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) { 45 // Doesn't do incremental backup/restore 46 } 47 48 @Override onRestoreFinished()49 public void onRestoreFinished() { 50 FileLog.d(TAG, "onRestoreFinished: set pending for RestoreDbTask"); 51 RestoreDbTask.setPending(this); 52 } 53 } 54