[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
This commit is contained in:
Annie Meng
2019-01-03 14:42:11 +00:00
parent ed04879a5d
commit 6e95fc95ce
5 changed files with 11 additions and 12 deletions

View File

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

View File

@@ -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();

View File

@@ -1,5 +1,5 @@
/*
* 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.

View File

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

View File

@@ -1,5 +1,5 @@
/*
* 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.