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

Commit d2c0cd43 authored by Christopher Tate's avatar Christopher Tate
Browse files

Don't do full backup/restore before setup

On the restore side, there's a bunch of one-time setup, device
provisioning, etc that we're very much not prepared to do in
lieu of running setup wizard, at least at this time.

On the backup side, it simply doesn't make sense to back up
stuff before the device has been set up.

Part of bug 5290261

Change-Id: If1c65e88e2da589d6204232d2b59c3e994f4ed3f
parent 98c8b52b
Loading
Loading
Loading
Loading
+28 −7
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.app.backup.IRestoreSession;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -4765,6 +4766,11 @@ class BackupManagerService extends IBackupManager.Stub {
        }
    }

    boolean deviceIsProvisioned() {
        final ContentResolver resolver = mContext.getContentResolver();
        return (Settings.Secure.getInt(resolver, Settings.Secure.DEVICE_PROVISIONED, 0) != 0);
    }

    // Run a *full* backup pass for the given package, writing the resulting data stream
    // to the supplied file descriptor.  This method is synchronous and does not return
    // to the caller until the backup has been completed.
@@ -4785,12 +4791,19 @@ class BackupManagerService extends IBackupManager.Stub {
            }
        }

        long oldId = Binder.clearCallingIdentity();
        try {
            // Doesn't make sense to do a full backup prior to setup
            if (!deviceIsProvisioned()) {
                Slog.i(TAG, "Full backup not supported before setup");
                return;
            }

            if (DEBUG) Slog.v(TAG, "Requesting full backup: apks=" + includeApks
                    + " shared=" + includeShared + " all=" + doAllApps
                    + " pkgs=" + pkgList);
            Slog.i(TAG, "Beginning full backup...");

        long oldId = Binder.clearCallingIdentity();
        try {
            FullBackupParams params = new FullBackupParams(fd, includeApks, includeShared,
                    doAllApps, pkgList);
            final int token = generateToken();
@@ -4822,17 +4835,25 @@ class BackupManagerService extends IBackupManager.Stub {
                // just eat it
            }
            Binder.restoreCallingIdentity(oldId);
            Slog.d(TAG, "Full backup processing complete.");
        }
        if (MORE_DEBUG) Slog.d(TAG, "Full backup done; returning to caller");
    }

    public void fullRestore(ParcelFileDescriptor fd) {
        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullRestore");
        Slog.i(TAG, "Beginning full restore...");

        long oldId = Binder.clearCallingIdentity();

        try {
            // Check whether the device has been provisioned -- we don't handle
            // full restores prior to completing the setup process.
            if (!deviceIsProvisioned()) {
                Slog.i(TAG, "Full restore not permitted before setup");
                return;
            }

            Slog.i(TAG, "Beginning full restore...");

            FullRestoreParams params = new FullRestoreParams(fd);
            final int token = generateToken();
            synchronized (mFullConfirmations) {
@@ -4863,7 +4884,7 @@ class BackupManagerService extends IBackupManager.Stub {
                Slog.w(TAG, "Error trying to close fd after full restore: " + e);
            }
            Binder.restoreCallingIdentity(oldId);
            Slog.i(TAG, "Full restore completed");
            Slog.i(TAG, "Full restore processing complete.");
        }
    }