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

Commit 8612b376 authored by Bartosz Fabianowski's avatar Bartosz Fabianowski Committed by Android (Google) Code Review
Browse files

Merge "Address review comments from 02a1c080"

parents db6bad13 7f97228e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ class BackupManagerConstants extends ContentObserver {
                DEFAULT_FULL_BACKUP_REQUIRE_CHARGING);
        mFullBackupRequiredNetworkType = mParser.getInt(FULL_BACKUP_REQUIRED_NETWORK_TYPE,
                DEFAULT_FULL_BACKUP_REQUIRED_NETWORK_TYPE);
        final String backupFinishedNotificationReceivers = mParser.getString(
        String backupFinishedNotificationReceivers = mParser.getString(
                BACKUP_FINISHED_NOTIFICATION_RECEIVERS,
                DEFAULT_BACKUP_FINISHED_NOTIFICATION_RECEIVERS);
        if (backupFinishedNotificationReceivers.isEmpty()) {
@@ -190,6 +190,9 @@ class BackupManagerConstants extends ContentObserver {
        return mFullBackupRequiredNetworkType;
    }

    /**
     * Returns an array of package names that should be notified whenever a backup finishes.
     */
    public synchronized String[] getBackupFinishedNotificationReceivers() {
        if (RefactoredBackupManagerService.DEBUG_SCHEDULING) {
            Slog.v(TAG, "getBackupFinishedNotificationReceivers(...) returns "
+17 −29
Original line number Diff line number Diff line
@@ -16,19 +16,17 @@

package com.android.server.backup;

import static com.google.common.truth.Truth.assertThat;

import android.app.AlarmManager;
import android.content.Context;
import android.os.Handler;
import android.platform.test.annotations.Presubmit;
import android.provider.Settings;

import com.android.server.backup.testing.ShadowBackupTransportStub;
import com.android.server.backup.testing.ShadowContextImplForBackup;
import com.android.server.backup.testing.ShadowPackageManagerForBackup;
import com.android.server.testing.FrameworkRobolectricTestRunner;
import com.android.server.testing.SystemLoaderClasses;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,19 +34,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static com.google.common.truth.Truth.assertThat;

@RunWith(FrameworkRobolectricTestRunner.class)
@Config(
        manifest = Config.NONE,
        sdk = 26,
        shadows = {
                ShadowContextImplForBackup.class,
                ShadowBackupTransportStub.class,
                ShadowPackageManagerForBackup.class
        }
)
@SystemLoaderClasses({TransportManager.class})
@Config(manifest = Config.NONE, sdk = 26)
@SystemLoaderClasses({BackupManagerConstants.class})
@Presubmit
public class BackupManagerConstantsTest {
    private static final String PACKAGE_NAME = "some.package.name";
@@ -59,17 +47,13 @@ public class BackupManagerConstantsTest {
        MockitoAnnotations.initMocks(this);
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testDefaultValues() throws Exception {
        final Context context = RuntimeEnvironment.application.getApplicationContext();
        final Handler handler = new Handler();

        Settings.Secure.putString(context.getContentResolver(),
                Settings.Secure.BACKUP_MANAGER_CONSTANTS, null);
        Settings.Secure.putString(
                context.getContentResolver(), Settings.Secure.BACKUP_MANAGER_CONSTANTS, null);

        final BackupManagerConstants constants =
                new BackupManagerConstants(handler, context.getContentResolver());
@@ -93,17 +77,21 @@ public class BackupManagerConstantsTest {
        final Context context = RuntimeEnvironment.application.getApplicationContext();
        final Handler handler = new Handler();

        final String recievers_setting = "backup_finished_notification_receivers=" +
                PACKAGE_NAME + ':' + ANOTHER_PACKAGE_NAME;
        Settings.Secure.putString(context.getContentResolver(),
                Settings.Secure.BACKUP_MANAGER_CONSTANTS, recievers_setting);
        final String recieversSetting =
                "backup_finished_notification_receivers="
                        + PACKAGE_NAME
                        + ':'
                        + ANOTHER_PACKAGE_NAME;
        Settings.Secure.putString(
                context.getContentResolver(),
                Settings.Secure.BACKUP_MANAGER_CONSTANTS,
                recieversSetting);

        final BackupManagerConstants constants =
                new BackupManagerConstants(handler, context.getContentResolver());
        constants.start();

        assertThat(constants.getBackupFinishedNotificationReceivers()).isEqualTo(new String[] {
                PACKAGE_NAME,
                ANOTHER_PACKAGE_NAME});
        assertThat(constants.getBackupFinishedNotificationReceivers())
                .isEqualTo(new String[] {PACKAGE_NAME, ANOTHER_PACKAGE_NAME});
    }
}