FileDocCategorySizeDatePackage
RecentsBackupHelper.javaAPI DocAndroid 5.1 API4259Thu Mar 12 22:22:10 GMT 2015android.app.backup

RecentsBackupHelper

public class RecentsBackupHelper extends Object implements BackupHelper
Helper for saving/restoring 'recent tasks' infrastructure.
hide

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final String
RECENTS_TASK_DIR
private static final String
RECENTS_IMAGE_DIR
private static final String
RECENTS_TASK_RESTORE_DIR
private static final String
RECENTS_IMAGE_RESTORE_DIR
private static final String
RECENTS_TASK_KEY
private static final String
RECENTS_IMAGE_KEY
FileBackupHelperBase
mTaskFileHelper
final File
mSystemDir
final File
mTasksDir
final File
mRestoredTasksDir
final File
mRestoredImagesDir
final String[]
mRecentFiles
final String[]
mRecentKeys
Constructors Summary
public RecentsBackupHelper(android.content.Context context)

param
context The agent context in which this helper instance will run


                     
       
        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];
        }
    
Methods Summary
public voidperformBackup(android.os.ParcelFileDescriptor oldState, BackupDataOutput data, android.os.ParcelFileDescriptor newState)
Task-file key: RECENTS_TASK_KEY + leaf filename Thumbnail-file key: RECENTS_IMAGE_KEY + leaf filename

        FileBackupHelperBase.performBackup_checked(oldState, data, newState,
                mRecentFiles, mRecentKeys);
    
public voidrestoreEntity(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);
        }
    
public voidwriteNewStateDescription(android.os.ParcelFileDescriptor newState)

        mTaskFileHelper.writeNewStateDescription(newState);