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

Commit 241000de authored by Andrea Zilio's avatar Andrea Zilio Committed by Android (Google) Code Review
Browse files

Merge "Add unit tests for feature to enable/disable backup scheduling."

parents acbf0458 66f4e6a0
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import android.os.UserHandle;
import android.util.Log;
import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;

import java.util.List;

/**
@@ -199,8 +201,15 @@ public class BackupManager {
    public static final int ERROR_TRANSPORT_INVALID = -2;

    private Context mContext;

    /**
     * @hide Making this package private is not sufficient for the test to access it, that's because
     * the test is in the same package but is loaded with a different class loader. Package
     * private members are not accessible across class loaders. So we make it public and @hide it.
     */
    @UnsupportedAppUsage
    private static IBackupManager sService;
    @VisibleForTesting
    public static IBackupManager sService;

    @UnsupportedAppUsage
    private static void checkServiceBinder() {
+17 −1
Original line number Diff line number Diff line
@@ -19,11 +19,14 @@ package android.app.backup;
import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.backup.BackupAnnotations.BackupDestination;
import android.app.backup.BackupAnnotations.OperationType;
import android.content.Context;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.UserHandle;
import android.platform.test.annotations.Presubmit;

@@ -31,7 +34,6 @@ import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -43,14 +45,28 @@ import java.io.IOException;
public class BackupManagerTest {
    private BackupManager mBackupManager;

    private static final int USER_ID = 12;

    @Mock
    Context mContext;
    @Mock
    IBackupManager mIBackupManager;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        mBackupManager = new BackupManager(mContext);
        BackupManager.sService = mIBackupManager;
    }

    @Test
    public void testSetFrameworkSchedulingEnabled_delegatesToService() throws RemoteException {
        when(mContext.getUserId()).thenReturn(USER_ID);
        mBackupManager.setFrameworkSchedulingEnabled(true);

        verify(mIBackupManager).setFrameworkSchedulingEnabledForUser(
                USER_ID, /* isEnabled= */true);
    }

    @Test
+2 −1
Original line number Diff line number Diff line
@@ -117,7 +117,8 @@ public class FullBackupJob extends JobService {
        return false;
    }

    private static int getJobIdForUserId(int userId) {
    @VisibleForTesting
    static int getJobIdForUserId(int userId) {
        return JobIdManager.getJobIdForUserId(MIN_JOB_ID, MAX_JOB_ID, userId);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -169,7 +169,8 @@ public class KeyValueBackupJob extends JobService {
        sNextScheduledForUserId.delete(userId);
    }

    private static int getJobIdForUserId(int userId) {
    @VisibleForTesting
    static int getJobIdForUserId(int userId) {
        return JobIdManager.getJobIdForUserId(MIN_JOB_ID, MAX_JOB_ID, userId);
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -508,7 +508,8 @@ public class UserBackupManagerService {

    @VisibleForTesting
    UserBackupManagerService(Context context, PackageManager packageManager,
            LifecycleOperationStorage operationStorage, TransportManager transportManager) {
            LifecycleOperationStorage operationStorage, TransportManager transportManager,
            BackupHandler backupHandler, BackupManagerConstants backupManagerConstants) {
        mContext = context;

        mUserId = 0;
@@ -516,6 +517,9 @@ public class UserBackupManagerService {
        mPackageManager = packageManager;
        mOperationStorage = operationStorage;
        mTransportManager = transportManager;
        mFullBackupQueue = new ArrayList<>();
        mBackupHandler = backupHandler;
        mConstants = backupManagerConstants;

        mBaseStateDir = null;
        mDataDir = null;
@@ -527,9 +531,7 @@ public class UserBackupManagerService {
        mAgentTimeoutParameters = null;
        mActivityManagerInternal = null;
        mAlarmManager = null;
        mConstants = null;
        mWakelock = null;
        mBackupHandler = null;
        mBackupPreferences = null;
        mBackupPasswordManager = null;
        mPackageManagerBinder = null;
Loading