Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2968ad5 authored by Stefan Kuhne's avatar Stefan Kuhne Committed by Android (Google) Code Review
Browse files

Merge "Revert "Backup/restore recents task list"" into mnc-dev

parents 6f145cf0 e88d1e59
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -2466,13 +2466,6 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case SYSTEM_BACKUP_RESTORED: {
            data.enforceInterface(IActivityManager.descriptor);
            systemBackupRestored();
            reply.writeNoException();
            return true;
        }

        case NOTIFY_CLEARTEXT_NETWORK_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            final int uid = data.readInt();
@@ -5758,17 +5751,6 @@ class ActivityManagerProxy implements IActivityManager
        reply.recycle();
    }

    @Override
    public void systemBackupRestored() throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        mRemote.transact(SYSTEM_BACKUP_RESTORED, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }

    @Override
    public void notifyCleartextNetwork(int uid, byte[] firstPacket) throws RemoteException {
        Parcel data = Parcel.obtain();
+0 −2
Original line number Diff line number Diff line
@@ -488,7 +488,6 @@ public interface IActivityManager extends IInterface {
    public void notifyLaunchTaskBehindComplete(IBinder token) throws RemoteException;
    public void notifyEnterAnimationComplete(IBinder token) throws RemoteException;

    public void systemBackupRestored() throws RemoteException;
    public void notifyCleartextNetwork(int uid, byte[] firstPacket) throws RemoteException;

    public void setDumpHeapDebugLimit(String processName, int uid, long maxMemSize,
@@ -825,7 +824,6 @@ public interface IActivityManager extends IInterface {
    int START_IN_PLACE_ANIMATION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+240;
    int CHECK_PERMISSION_WITH_TOKEN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+241;
    int REGISTER_TASK_STACK_LISTENER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+242;
    int SYSTEM_BACKUP_RESTORED = IBinder.FIRST_CALL_TRANSACTION+243;

    // Start of M transactions
    int NOTIFY_CLEARTEXT_NETWORK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+280;
+0 −130
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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);
    }

}
+0 −14
Original line number Diff line number Diff line
@@ -16,14 +16,12 @@

package com.android.server.backup;

import android.app.ActivityManagerNative;
import android.app.IWallpaperManager;
import android.app.backup.BackupDataInput;
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;
@@ -45,7 +43,6 @@ public class SystemBackupAgent extends BackupAgentHelper {
    // Names of the helper tags within the dataset.  Changing one of these names will
    // break the ability to restore from datasets that predate the change.
    private static final String WALLPAPER_HELPER = "wallpaper";
    private static final String RECENTS_HELPER = "recents";
    private static final String SYNC_SETTINGS_HELPER = "account_sync_settings";
    private static final String PREFERRED_HELPER = "preferred_activities";
    private static final String NOTIFICATION_HELPER = "notifications";
@@ -92,7 +89,6 @@ public class SystemBackupAgent extends BackupAgentHelper {
            }
        }
        addHelper(WALLPAPER_HELPER, new WallpaperBackupHelper(this, files, keys));
        addHelper(RECENTS_HELPER, new RecentsBackupHelper(this));
        addHelper(SYNC_SETTINGS_HELPER, new AccountSyncSettingsBackupHelper(this));
        addHelper(PREFERRED_HELPER, new PreferredActivityBackupHelper());
        addHelper(NOTIFICATION_HELPER, new NotificationBackupHelper(this));
@@ -127,7 +123,6 @@ public class SystemBackupAgent extends BackupAgentHelper {
        addHelper("system_files", new WallpaperBackupHelper(this,
                new String[] { WALLPAPER_IMAGE },
                new String[] { WALLPAPER_IMAGE_KEY} ));
        addHelper(RECENTS_HELPER, new RecentsBackupHelper(this));
        addHelper(SYNC_SETTINGS_HELPER, new AccountSyncSettingsBackupHelper(this));
        addHelper(PREFERRED_HELPER, new PreferredActivityBackupHelper());
        addHelper(NOTIFICATION_HELPER, new NotificationBackupHelper(this));
@@ -200,13 +195,4 @@ public class SystemBackupAgent extends BackupAgentHelper {
            }
        }
    }

    @Override
    public void onRestoreFinished() {
        try {
            ActivityManagerNative.getDefault().systemBackupRestored();
        } catch (RemoteException e) {
            // Not possible since this code is running in the system process.
        }
    }
}
+2 −20
Original line number Diff line number Diff line
@@ -6164,17 +6164,6 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    @Override
    public void systemBackupRestored() {
        synchronized (this) {
            if (mSystemReady) {
                mTaskPersister.restoreTasksFromOtherDeviceLocked();
            } else {
                Slog.w(TAG, "System backup restored before system is ready");
            }
        }
    }
    final void ensureBootCompleted() {
        boolean booting;
        boolean enableScreen;
@@ -11327,7 +11316,6 @@ public final class ActivityManagerService extends ActivityManagerNative
            mRecentTasks.clear();
            mRecentTasks.addAll(mTaskPersister.restoreTasksLocked());
            mTaskPersister.restoreTasksFromOtherDeviceLocked();
            mRecentTasks.cleanupLocked(UserHandle.USER_ALL);
            mTaskPersister.startPersisting();
@@ -16191,18 +16179,12 @@ public final class ActivityManagerService extends ActivityManagerNative
                                        removeUriPermissionsForPackageLocked(ssp, userId, true);
                                        removeTasksByPackageNameLocked(ssp, userId);
                                        if (userId == UserHandle.USER_OWNER) {
                                            mTaskPersister.removeFromPackageCache(ssp);
                                        }
                                        mBatteryStatsService.notePackageUninstalled(ssp);
                                    }
                                } else {
                                    cleanupDisabledPackageComponentsLocked(ssp, userId,
                                            intent.getStringArrayExtra(
                                                    Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST));
                                    if (userId == UserHandle.USER_OWNER) {
                                        mTaskPersister.addOtherDeviceTasksToRecentsLocked(ssp);
                                    }
                                }
                            }
                            break;
@@ -16217,8 +16199,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                                intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
                        mCompatModePackages.handlePackageAddedLocked(ssp, replacing);
                        if (userId == UserHandle.USER_OWNER) {
                            mTaskPersister.addOtherDeviceTasksToRecentsLocked(ssp);
                        if (replacing) {
                            removeTasksByRemovedPackageComponentsLocked(ssp, userId);
                        }
                        try {
                            ApplicationInfo ai = AppGlobals.getPackageManager().
Loading