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

Commit 80fc4df0 authored by Chris Tate's avatar Chris Tate Committed by Android (Google) Code Review
Browse files

Merge "Backup OS service now processes unlock off the main thread"

parents 1b0b699d 73093a47
Loading
Loading
Loading
Loading
+38 −30
Original line number Diff line number Diff line
@@ -401,26 +401,35 @@ public class BackupManagerService implements BackupManagerServiceInterface {
        @Override
        public void onUnlockUser(int userId) {
            if (userId == UserHandle.USER_SYSTEM) {
                sInstance.unlockSystemUser();
            }
        }
    }
    // Called through the trampoline from onUnlockUser(), then we buck the work
    // off to the background thread to keep the unlock time down.
    public void unlockSystemUser() {
        mBackupHandler.post(() -> {
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup init");
                sInstance.initialize(userId);
            sInstance.initialize(UserHandle.USER_SYSTEM);
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
            // Migrate legacy setting
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup migrate");
                if (!backupSettingMigrated(userId)) {
            if (!backupSettingMigrated(UserHandle.USER_SYSTEM)) {
                if (DEBUG) {
                    Slog.i(TAG, "Backup enable apparently not migrated");
                }
                final ContentResolver r = sInstance.mContext.getContentResolver();
                final int enableState = Settings.Secure.getIntForUser(r,
                            Settings.Secure.BACKUP_ENABLED, -1, userId);
                        Settings.Secure.BACKUP_ENABLED, -1, UserHandle.USER_SYSTEM);
                if (enableState >= 0) {
                    if (DEBUG) {
                        Slog.i(TAG, "Migrating enable state " + (enableState != 0));
                    }
                        writeBackupEnableState(enableState != 0, userId);
                    writeBackupEnableState(enableState != 0, UserHandle.USER_SYSTEM);
                    Settings.Secure.putStringForUser(r,
                                Settings.Secure.BACKUP_ENABLED, null, userId);
                            Settings.Secure.BACKUP_ENABLED, null, UserHandle.USER_SYSTEM);
                } else {
                    if (DEBUG) {
                        Slog.i(TAG, "Backup not yet configured; retaining null enable state");
@@ -431,13 +440,12 @@ public class BackupManagerService implements BackupManagerServiceInterface {
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup enable");
            try {
                    sInstance.setBackupEnabled(readBackupEnableState(userId));
                sInstance.setBackupEnabled(readBackupEnableState(UserHandle.USER_SYSTEM));
            } catch (RemoteException e) {
                // can't happen; it's a local object
            }
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
            }
        }
        });
    }
    class ProvisionedObserver extends ContentObserver {
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import java.io.PrintWriter;
 */
public interface BackupManagerServiceInterface {

  void unlockSystemUser();

  // Utility: build a new random integer token
  int generateRandomIntegerToken();

+38 −30
Original line number Diff line number Diff line
@@ -548,26 +548,35 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
        @Override
        public void onUnlockUser(int userId) {
            if (userId == UserHandle.USER_SYSTEM) {
                sInstance.unlockSystemUser();
            }
        }
    }

    // Called through the trampoline from onUnlockUser(), then we buck the work
    // off to the background thread to keep the unlock time down.
    public void unlockSystemUser() {
        mBackupHandler.post(() -> {
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup init");
                sInstance.initialize(userId);
            sInstance.initialize(UserHandle.USER_SYSTEM);
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);

            // Migrate legacy setting
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup migrate");
                if (!backupSettingMigrated(userId)) {
            if (!backupSettingMigrated(UserHandle.USER_SYSTEM)) {
                if (DEBUG) {
                    Slog.i(TAG, "Backup enable apparently not migrated");
                }
                final ContentResolver r = sInstance.mContext.getContentResolver();
                final int enableState = Settings.Secure.getIntForUser(r,
                            Settings.Secure.BACKUP_ENABLED, -1, userId);
                        Settings.Secure.BACKUP_ENABLED, -1, UserHandle.USER_SYSTEM);
                if (enableState >= 0) {
                    if (DEBUG) {
                        Slog.i(TAG, "Migrating enable state " + (enableState != 0));
                    }
                        writeBackupEnableState(enableState != 0, userId);
                    writeBackupEnableState(enableState != 0, UserHandle.USER_SYSTEM);
                    Settings.Secure.putStringForUser(r,
                                Settings.Secure.BACKUP_ENABLED, null, userId);
                            Settings.Secure.BACKUP_ENABLED, null, UserHandle.USER_SYSTEM);
                } else {
                    if (DEBUG) {
                        Slog.i(TAG, "Backup not yet configured; retaining null enable state");
@@ -578,13 +587,12 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter

            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup enable");
            try {
                    sInstance.setBackupEnabled(readBackupEnableState(userId));
                sInstance.setBackupEnabled(readBackupEnableState(UserHandle.USER_SYSTEM));
            } catch (RemoteException e) {
                // can't happen; it's a local object
            }
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
            }
        }
        });
    }

    // Bookkeeping of in-flight operations for timeout etc. purposes.  The operation
+7 −0
Original line number Diff line number Diff line
@@ -139,6 +139,13 @@ public class Trampoline extends IBackupManager.Stub {
        }
    }

    void unlockSystemUser() {
        BackupManagerServiceInterface svc = mService;
        if (svc != null) {
            svc.unlockSystemUser();
        }
    }

    public void setBackupServiceActive(final int userHandle, boolean makeActive) {
        // Only the DPM should be changing the active state of backup
        final int caller = binderGetCallingUid();