Loading services/core/java/com/android/server/backup/SystemBackupAgent.java +4 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.app.backup.FullBackup; import android.app.backup.FullBackupDataOutput; import android.app.backup.WallpaperBackupHelper; import android.content.Context; import android.content.pm.PackageManager; import android.os.Environment; import android.os.ParcelFileDescriptor; import android.os.RemoteException; Loading Loading @@ -124,7 +125,9 @@ public class SystemBackupAgent extends BackupAgentHelper { addHelperIfEligibleForUser(USAGE_STATS_HELPER, new UsageStatsBackupHelper(mUserId)); addHelperIfEligibleForUser(SHORTCUT_MANAGER_HELPER, new ShortcutBackupHelper(mUserId)); addHelperIfEligibleForUser(ACCOUNT_MANAGER_HELPER, new AccountManagerBackupHelper(mUserId)); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_SLICES_DISABLED)) { addHelperIfEligibleForUser(SLICES_HELPER, new SliceBackupHelper(this)); } addHelperIfEligibleForUser(PEOPLE_HELPER, new PeopleBackupHelper(mUserId)); addHelperIfEligibleForUser(APP_LOCALES_HELPER, new AppSpecificLocalesBackupHelper(mUserId)); addHelperIfEligibleForUser(APP_GENDER_HELPER, Loading services/tests/mockingservicestests/src/com/android/server/backup/SystemBackupAgentTest.java +37 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import android.annotation.NonNull; import android.app.backup.BackupHelper; import android.content.Context; import android.content.pm.PackageManager; import android.os.UserHandle; import android.os.UserManager; import android.platform.test.annotations.Presubmit; Loading @@ -47,14 +48,20 @@ public class SystemBackupAgentTest { private TestableSystemBackupAgent mSystemBackupAgent; @Mock private Context mContextMock; @Mock private UserManager mUserManagerMock; @Mock private Context mContextMock; @Mock private UserManager mUserManagerMock; @Mock private PackageManager mPackageManagerMock; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mSystemBackupAgent = new TestableSystemBackupAgent(); when(mContextMock.getSystemService(UserManager.class)).thenReturn(mUserManagerMock); when(mPackageManagerMock.hasSystemFeature( PackageManager.FEATURE_SLICES_DISABLED)).thenReturn(false); } @Test Loading @@ -79,6 +86,29 @@ public class SystemBackupAgentTest { "app_gender"); } @Test public void onCreate_systemUser_slicesDisabled_addsAllNonSlicesHelpers() { UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM); when(mUserManagerMock.isProfile()).thenReturn(false); when(mPackageManagerMock.hasSystemFeature( PackageManager.FEATURE_SLICES_DISABLED)).thenReturn(true); mSystemBackupAgent.onCreate(userHandle, /* backupDestination= */ 0); assertThat(mSystemBackupAgent.mAddedHelpers) .containsExactly( "account_sync_settings", "preferred_activities", "notifications", "permissions", "usage_stats", "shortcut_manager", "account_manager", "people", "app_locales", "app_gender"); } @Test public void onCreate_profileUser_addsProfileEligibleHelpers() { UserHandle userHandle = new UserHandle(NON_SYSTEM_USER_ID); Loading Loading @@ -130,5 +160,10 @@ public class SystemBackupAgentTest { public Object getSystemService(@ServiceName @NonNull String name) { return null; } @Override public PackageManager getPackageManager() { return mPackageManagerMock; } } } Loading
services/core/java/com/android/server/backup/SystemBackupAgent.java +4 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.app.backup.FullBackup; import android.app.backup.FullBackupDataOutput; import android.app.backup.WallpaperBackupHelper; import android.content.Context; import android.content.pm.PackageManager; import android.os.Environment; import android.os.ParcelFileDescriptor; import android.os.RemoteException; Loading Loading @@ -124,7 +125,9 @@ public class SystemBackupAgent extends BackupAgentHelper { addHelperIfEligibleForUser(USAGE_STATS_HELPER, new UsageStatsBackupHelper(mUserId)); addHelperIfEligibleForUser(SHORTCUT_MANAGER_HELPER, new ShortcutBackupHelper(mUserId)); addHelperIfEligibleForUser(ACCOUNT_MANAGER_HELPER, new AccountManagerBackupHelper(mUserId)); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_SLICES_DISABLED)) { addHelperIfEligibleForUser(SLICES_HELPER, new SliceBackupHelper(this)); } addHelperIfEligibleForUser(PEOPLE_HELPER, new PeopleBackupHelper(mUserId)); addHelperIfEligibleForUser(APP_LOCALES_HELPER, new AppSpecificLocalesBackupHelper(mUserId)); addHelperIfEligibleForUser(APP_GENDER_HELPER, Loading
services/tests/mockingservicestests/src/com/android/server/backup/SystemBackupAgentTest.java +37 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import android.annotation.NonNull; import android.app.backup.BackupHelper; import android.content.Context; import android.content.pm.PackageManager; import android.os.UserHandle; import android.os.UserManager; import android.platform.test.annotations.Presubmit; Loading @@ -47,14 +48,20 @@ public class SystemBackupAgentTest { private TestableSystemBackupAgent mSystemBackupAgent; @Mock private Context mContextMock; @Mock private UserManager mUserManagerMock; @Mock private Context mContextMock; @Mock private UserManager mUserManagerMock; @Mock private PackageManager mPackageManagerMock; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mSystemBackupAgent = new TestableSystemBackupAgent(); when(mContextMock.getSystemService(UserManager.class)).thenReturn(mUserManagerMock); when(mPackageManagerMock.hasSystemFeature( PackageManager.FEATURE_SLICES_DISABLED)).thenReturn(false); } @Test Loading @@ -79,6 +86,29 @@ public class SystemBackupAgentTest { "app_gender"); } @Test public void onCreate_systemUser_slicesDisabled_addsAllNonSlicesHelpers() { UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM); when(mUserManagerMock.isProfile()).thenReturn(false); when(mPackageManagerMock.hasSystemFeature( PackageManager.FEATURE_SLICES_DISABLED)).thenReturn(true); mSystemBackupAgent.onCreate(userHandle, /* backupDestination= */ 0); assertThat(mSystemBackupAgent.mAddedHelpers) .containsExactly( "account_sync_settings", "preferred_activities", "notifications", "permissions", "usage_stats", "shortcut_manager", "account_manager", "people", "app_locales", "app_gender"); } @Test public void onCreate_profileUser_addsProfileEligibleHelpers() { UserHandle userHandle = new UserHandle(NON_SYSTEM_USER_ID); Loading Loading @@ -130,5 +160,10 @@ public class SystemBackupAgentTest { public Object getSystemService(@ServiceName @NonNull String name) { return null; } @Override public PackageManager getPackageManager() { return mPackageManagerMock; } } }