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

Commit 4704f8d3 authored by Bagus Maulana's avatar Bagus Maulana Committed by Android (Google) Code Review
Browse files

Merge "Disable SliceBackupHelper on devices with FEATURE_SLICES_DISABLED"

parents 556cf9a5 cc709e3c
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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,
+37 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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
@@ -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);
@@ -130,5 +160,10 @@ public class SystemBackupAgentTest {
        public Object getSystemService(@ServiceName @NonNull String name) {
            return null;
        }

        @Override
        public PackageManager getPackageManager() {
            return mPackageManagerMock;
        }
    }
}