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

Commit 6e95fc95 authored by Annie Meng's avatar Annie Meng
Browse files

[Multi-user] Clean up backup enabled initialization

Remove indirection in setting backup enabled state to call directly into
the UserBMS instance.

Bug: 121305979
Test: 1) atest RunBackupFrameworksServicesRoboTests
2) During SUW -> backup initializes off;
Turn backup on in SUW -> backup enabled;
Subsequent boots -> backup initializes on
Change-Id: Ief688c4e1c14b443db87eda43ec0ee398282662f
parent ed04879a
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.os.Binder;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.Trace;
import android.os.UserHandle;
import android.util.Slog;
@@ -139,13 +138,7 @@ public class BackupManagerService {
        mServiceUsers.put(userId, userBackupManagerService);

        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup enable");
        try {
            // TODO(b/121198604): Make enable file per-user and clean up indirection.
            mTrampoline.setBackupEnabledForUser(
                    userId, UserBackupManagerFilePersistedSettings.readBackupEnableState(userId));
        } catch (RemoteException e) {
            // Can't happen, it's a local object.
        }
        userBackupManagerService.initializeBackupEnableState();
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    }

+5 −0
Original line number Diff line number Diff line
@@ -546,6 +546,11 @@ public class UserBackupManagerService {
        mWakelock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*backup*");
    }

    void initializeBackupEnableState() {
        boolean isEnabled = UserBackupManagerFilePersistedSettings.readBackupEnableState(mUserId);
        setBackupEnabled(isEnabled);
    }

    /** Cleans up state when the user of this service is stopped. */
    void tearDownService() {
        mUserBackupThread.quit();
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 * Copyright (C) 2019 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.
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.backup;

import static android.Manifest.permission.BACKUP;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;

import static com.android.server.backup.testing.BackupManagerServiceTestUtils.startBackupThread;
@@ -27,7 +28,6 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.robolectric.Shadows.shadowOf;
import static org.testng.Assert.expectThrows;

@@ -201,7 +201,7 @@ public class BackupManagerServiceTest {
        backupManagerService.stopServiceForUser(mUserOneId);

        verify(mUserOneService).tearDownService();
        verifyNoMoreInteractions(mUserTwoService);
        verify(mUserTwoService, never()).tearDownService();
    }

    /** Test that the service unregisters users when stopped. */
@@ -1542,6 +1542,7 @@ public class BackupManagerServiceTest {
    }

    private BackupManagerService createService() {
        mShadowContext.grantPermissions(BACKUP);
        return new BackupManagerService(
                mContext, new Trampoline(mContext), startBackupThread(null));
    }
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 * Copyright (C) 2019 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.