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

Commit 801f2ec5 authored by Chandan Nath's avatar Chandan Nath
Browse files

[Multi-user] Make backup dirs user-specific

1. For system user, functionality remains almost (see 2) exactly the
same.
2. Change the full backup dir which is used only to write temporary
manifest and meta dirs by the system process when doing full backup.
This is so that we dont have to worry unnecessarily about yet another dir.

Bug: 120424138

Test: 1) atest RunBackupFrameworksServicesRoboTests
2) atest $(find \
frameworks/base/services/tests/servicestests/src/com/android/server/backup \
-name '*Test.java')
3) atest CtsBackupTestCases
4) atest CtsBackupHostTestCases
5) atest GtsBackupTestCases
6) atest GtsBackupHostTestCases
7) 'adb shell bmgr' enabled/backupnow flow

Change-Id: I9a33547c9595a86b62869ee731d4c75a029922e8
parent ed04879a
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -17,29 +17,35 @@
package com.android.server.backup;

import android.os.Environment;
import android.os.UserHandle;

import java.io.File;

/** Directories used for user specific backup/restore persistent state and book-keeping. */
public final class UserBackupManagerFiles {
final class UserBackupManagerFiles {
    // Name of the directories the service stores bookkeeping data under.
    private static final String BACKUP_PERSISTENT_DIR = "backup";
    private static final String BACKUP_STAGING_DIR = "backup_stage";

    private static File getBaseDir(int userId) {
        return Environment.getDataSystemCeDirectory(userId);
    }

    static File getBaseStateDir(int userId) {
        // TODO (b/120424138) this should be per user
        if (userId != UserHandle.USER_SYSTEM) {
            return new File(getBaseDir(userId), BACKUP_PERSISTENT_DIR);
        }
        // TODO (b/120424138) remove if clause above and use same logic for system user.
        // simultaneously, copy below dir to new system user dir
        return new File(Environment.getDataDirectory(), BACKUP_PERSISTENT_DIR);
    }

    static File getDataDir(int userId) {
        // TODO (b/120424138) this should be per user
        // This dir on /cache is managed directly in init.rc
        return new File(Environment.getDownloadCacheDirectory(), BACKUP_STAGING_DIR);
        if (userId != UserHandle.USER_SYSTEM) {
            return new File(getBaseDir(userId), BACKUP_STAGING_DIR);
        }

    /** Directory used by full backup engine to store state. */
    public static File getFullBackupEngineFilesDir(int userId) {
        // TODO (b/120424138) this should be per user
        return new File("/data/system");
        // TODO (b/120424138) remove if clause above and use same logic for system user. Since this
        // is a staging dir, we dont need to copy below dir to new system user dir
        return new File(Environment.getDownloadCacheDirectory(), BACKUP_STAGING_DIR);
    }
}
+1 −9
Original line number Diff line number Diff line
@@ -551,7 +551,7 @@ public class UserBackupManagerService {
        mUserBackupThread.quit();
    }

    public int getUserId() {
    public @UserIdInt int getUserId() {
        return mUserId;
    }

@@ -567,10 +567,6 @@ public class UserBackupManagerService {
        return mContext;
    }

    public void setContext(Context context) {
        mContext = context;
    }

    public PackageManager getPackageManager() {
        return mPackageManager;
    }
@@ -583,10 +579,6 @@ public class UserBackupManagerService {
        return mPackageManagerBinder;
    }

    public void setPackageManagerBinder(IPackageManager packageManagerBinder) {
        mPackageManagerBinder = packageManagerBinder;
    }

    public IActivityManager getActivityManager() {
        return mActivityManager;
    }
+15 −8
Original line number Diff line number Diff line
@@ -34,14 +34,12 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Slog;

import com.android.internal.util.Preconditions;
import com.android.server.AppWidgetBackupBridge;
import com.android.server.backup.BackupAgentTimeoutParameters;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.UserBackupManagerFiles;
import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.remote.RemoteCall;
import com.android.server.backup.utils.FullBackupUtils;
@@ -78,21 +76,21 @@ public class FullBackupEngine {
        private final File mFilesDir;

        FullBackupRunner(
                UserBackupManagerService userBackupManagerService,
                PackageInfo packageInfo,
                IBackupAgent agent,
                ParcelFileDescriptor pipe,
                int token,
                boolean includeApks)
                throws IOException {
            // TODO: http://b/22388012
            mUserId = UserHandle.USER_SYSTEM;
            mUserId = userBackupManagerService.getUserId();
            mPackageManager = backupManagerService.getPackageManager();
            mPackage = packageInfo;
            mAgent = agent;
            mPipe = ParcelFileDescriptor.dup(pipe.getFileDescriptor());
            mToken = token;
            mIncludeApks = includeApks;
            mFilesDir = UserBackupManagerFiles.getFullBackupEngineFilesDir(mUserId);
            mFilesDir = userBackupManagerService.getDataDir();
        }

        @Override
@@ -155,9 +153,12 @@ public class FullBackupEngine {
                        backupManagerService.getBackupManagerBinder(),
                        mTransportFlags);
            } catch (IOException e) {
                Slog.e(TAG, "Error running full backup for " + mPackage.packageName);
                Slog.e(TAG, "Error running full backup for " + mPackage.packageName, e);
            } catch (RemoteException e) {
                Slog.e(TAG, "Remote agent vanished during full backup of " + mPackage.packageName);
                Slog.e(
                        TAG,
                        "Remote agent vanished during full backup of " + mPackage.packageName,
                        e);
            } finally {
                try {
                    mPipe.close();
@@ -233,7 +234,13 @@ public class FullBackupEngine {
                pipes = ParcelFileDescriptor.createPipe();

                FullBackupRunner runner =
                        new FullBackupRunner(mPkg, mAgent, pipes[1], mOpToken, mIncludeApks);
                        new FullBackupRunner(
                                backupManagerService,
                                mPkg,
                                mAgent,
                                pipes[1],
                                mOpToken,
                                mIncludeApks);
                pipes[1].close(); // the runner has dup'd it
                pipes[1] = null;
                Thread t = new Thread(runner, "app-data-runner");