diff options
| author | 2014-11-21 02:24:30 +0000 | |
|---|---|---|
| committer | 2014-11-21 02:24:31 +0000 | |
| commit | ad064d48adcfac71bd04d9f3bb5ea9d607d132a7 (patch) | |
| tree | 2d758c20f8dea1900ab49562ba486457d2cfa541 | |
| parent | 8ae8500365e71c59cbe96f600371391ac8d245b8 (diff) | |
| parent | ac6a3a5e9d90edb533e5b377a4a14ef514be955a (diff) | |
Merge "Recents backup helper" into lmp-mr1-dev
3 files changed, 124 insertions, 0 deletions
diff --git a/core/java/android/app/backup/RecentsBackupHelper.java b/core/java/android/app/backup/RecentsBackupHelper.java new file mode 100644 index 000000000000..fd69d2043d15 --- /dev/null +++ b/core/java/android/app/backup/RecentsBackupHelper.java @@ -0,0 +1,114 @@ +package android.app.backup; + +import android.content.Context; +import android.os.Environment; +import android.os.ParcelFileDescriptor; +import android.util.Slog; + +import java.io.File; + +/** + * Helper for saving/restoring 'recent tasks' infrastructure. + * @hide + */ +public class RecentsBackupHelper implements BackupHelper { + private static final String TAG = "RecentsBackup"; + private static final boolean DEBUG = false; + + // This must match TaskPersister.TASKS_DIRNAME, but that class is not accessible from here + private static final String RECENTS_TASK_DIR = "recent_tasks"; + + // Must match TaskPersister.IMAGES_DIRNAME, as above + private static final String RECENTS_IMAGE_DIR = "recent_images"; + + // At restore time, tasks/thumbnails are placed in these directories alongside + // the "live" recents dirs named above. + private static final String RECENTS_TASK_RESTORE_DIR = "restored_" + RECENTS_TASK_DIR; + private static final String RECENTS_IMAGE_RESTORE_DIR = "restored_" + RECENTS_IMAGE_DIR; + + // Prefixes for tagging the two kinds of recents backup records that we might generate + private static final String RECENTS_TASK_KEY = "task:"; + private static final String RECENTS_IMAGE_KEY = "image:"; + + FileBackupHelperBase mTaskFileHelper; + + final File mSystemDir; + final File mTasksDir; + final File mRestoredTasksDir; + final File mRestoredImagesDir; + final String[] mRecentFiles; + final String[] mRecentKeys; + + /** + * @param context The agent context in which this helper instance will run + */ + public RecentsBackupHelper(Context context) { + mTaskFileHelper = new FileBackupHelperBase(context); + + mSystemDir = new File(Environment.getDataDirectory(), "system"); + mTasksDir = new File(mSystemDir, RECENTS_TASK_DIR); + mRestoredTasksDir = new File(mSystemDir, RECENTS_TASK_RESTORE_DIR); + mRestoredImagesDir = new File(mSystemDir, RECENTS_IMAGE_RESTORE_DIR); + + // Currently we back up only the recent-task descriptions, not the thumbnails + File[] recentFiles = mTasksDir.listFiles(); + if (recentFiles != null) { + // We explicitly proceed even if this is a zero-size array + final int N = recentFiles.length; + mRecentKeys = new String[N]; + mRecentFiles = new String[N]; + if (DEBUG) { + Slog.i(TAG, "Identifying recents for backup: " + N); + } + for (int i = 0; i < N; i++) { + mRecentKeys[i] = new String(RECENTS_TASK_KEY + recentFiles[i].getName()); + mRecentFiles[i] = recentFiles[i].getAbsolutePath(); + if (DEBUG) { + Slog.i(TAG, " " + mRecentKeys[i]); + } + } + } else { + mRecentFiles = mRecentKeys = new String[0]; + } + } + + /** + * Task-file key: RECENTS_TASK_KEY + leaf filename + * Thumbnail-file key: RECENTS_IMAGE_KEY + leaf filename + */ + @Override + public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, + ParcelFileDescriptor newState) { + FileBackupHelperBase.performBackup_checked(oldState, data, newState, + mRecentFiles, mRecentKeys); + } + + @Override + public void restoreEntity(BackupDataInputStream data) { + final String key = data.getKey(); + File output = null; + if (key.startsWith(RECENTS_TASK_KEY)) { + String name = key.substring(RECENTS_TASK_KEY.length()); + output = new File(mRestoredTasksDir, name); + mRestoredTasksDir.mkdirs(); + } else if (key.startsWith(RECENTS_IMAGE_KEY)) { + String name = key.substring(RECENTS_IMAGE_KEY.length()); + output = new File(mRestoredImagesDir, name); + mRestoredImagesDir.mkdirs(); + } + + if (output != null) { + if (DEBUG) { + Slog.i(TAG, "Restoring key='" + + key + "' to " + output.getAbsolutePath()); + } + mTaskFileHelper.writeFile(output, data); + } + } + + @Override + public void writeNewStateDescription(ParcelFileDescriptor newState) { + mTaskFileHelper.writeNewStateDescription(newState); + } + +} diff --git a/core/java/com/android/server/backup/SystemBackupAgent.java b/core/java/com/android/server/backup/SystemBackupAgent.java index 26e2e2ac356c..ed7ce63cb425 100644 --- a/core/java/com/android/server/backup/SystemBackupAgent.java +++ b/core/java/com/android/server/backup/SystemBackupAgent.java @@ -23,6 +23,7 @@ import android.app.backup.BackupDataOutput; import android.app.backup.BackupAgentHelper; import android.app.backup.FullBackup; import android.app.backup.FullBackupDataOutput; +import android.app.backup.RecentsBackupHelper; import android.app.backup.WallpaperBackupHelper; import android.content.Context; import android.os.Environment; @@ -83,6 +84,8 @@ public class SystemBackupAgent extends BackupAgentHelper { } } addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files, keys)); + addHelper("recents", new RecentsBackupHelper(SystemBackupAgent.this)); + super.onBackup(oldState, data, newState); } @@ -113,6 +116,7 @@ public class SystemBackupAgent extends BackupAgentHelper { addHelper("system_files", new WallpaperBackupHelper(SystemBackupAgent.this, new String[] { WALLPAPER_IMAGE }, new String[] { WALLPAPER_IMAGE_KEY} )); + addHelper("recents", new RecentsBackupHelper(SystemBackupAgent.this)); try { super.onRestore(data, appVersionCode, newState); diff --git a/services/core/java/com/android/server/am/TaskPersister.java b/services/core/java/com/android/server/am/TaskPersister.java index b331c845a0e3..9311f253d46a 100644 --- a/services/core/java/com/android/server/am/TaskPersister.java +++ b/services/core/java/com/android/server/am/TaskPersister.java @@ -63,6 +63,12 @@ public class TaskPersister { private static final String IMAGES_DIRNAME = "recent_images"; static final String IMAGE_EXTENSION = ".png"; + // Directory where restored historical task XML/PNG files are placed. This directory + // contains subdirs named after TASKS_DIRNAME and IMAGES_DIRNAME mirroring the + // ancestral device's dataset. This needs to match the RECENTS_TASK_RESTORE_DIR + // value in RecentsBackupHelper. + private static final String RESTORED_TASKS = "restored_" + TASKS_DIRNAME; + private static final String TAG_TASK = "task"; static File sImagesDir; |