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

Commit c3e97122 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Clean up BackupSettingsHelper.getSummary()

Backup item in System page no longer has summary.

Bug: 310513318
Test: m RunSettingsRoboTests
Change-Id: I0bb3b9114287546c279a5f30b65fb7081af54e44
parent 63b69694
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -6094,10 +6094,6 @@
    <!-- Backup and reset Settings screen --><skip />
    <!-- Backup and reset settings menu and activity title -->
    <string name="privacy_settings_title">Backup</string>
    <!-- Summary for the Backup settings when it is turned on. -->
    <string name="backup_summary_state_on">On</string>
    <!-- Summary for the Backup settings when it is turned off. -->
    <string name="backup_summary_state_off">Off</string>
    <!-- Backup section title -->
    <string name="backup_section_title">Backup &amp; restore</string>
    <!-- Personal data section title -->
+0 −19
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.Intent;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.Log;

@@ -50,24 +49,6 @@ public class BackupSettingsHelper {
        mContext = context;
    }

    /**
     * If there is only one profile, show whether the backup is on or off.
     * Otherwise, show nothing.
     */
    public String getSummary() {
        UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        if (userManager.getUserProfiles().size() == 1) {
            try {
                int resId = mBackupManager.isBackupEnabled()
                        ? R.string.backup_summary_state_on : R.string.backup_summary_state_off;
                return mContext.getText(resId).toString();
            } catch (RemoteException e) {
                Log.e(TAG, "Error getting isBackupEnabled", e);
            }
        }
        return null;
    }

    /**
     * Returns an intent to launch backup settings from backup transport if the intent was provided
     * by the transport. Otherwise returns the intent to launch the default backup settings screen.
+0 −37
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;

import com.android.settings.R;

@@ -48,8 +47,6 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowUserManager;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = BackupSettingsHelperTest.ShadowBackupManagerStub.class)
@@ -72,46 +69,12 @@ public class BackupSettingsHelperTest {
    @Mock
    private static IBackupManager mBackupManager;

    private ShadowUserManager mUserManager;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mContext = spy(RuntimeEnvironment.application.getApplicationContext());
        when(mBackupManager.getCurrentTransport()).thenReturn("test_transport");
        mBackupSettingsHelper = new BackupSettingsHelper(mContext);
        mUserManager = Shadow.extract(mContext.getSystemService(Context.USER_SERVICE));
    }

    @Test
    public void testGetSummary_backupEnabledOnlyOneProfile_showsOn() throws Exception {
        mUserManager.addUserProfile(new UserHandle(0));
        when(mBackupManager.isBackupEnabled()).thenReturn(true);

        String backupSummary = mBackupSettingsHelper.getSummary();

        assertThat(backupSummary).isEqualTo(mContext.getString(R.string.backup_summary_state_on));
    }

    @Test
    public void testGetSummary_backupDisabledOnlyOneProfile_showsOff() throws Exception {
        mUserManager.addUserProfile(new UserHandle(0));
        when(mBackupManager.isBackupEnabled()).thenReturn(false);

        String backupSummary = mBackupSettingsHelper.getSummary();

        assertThat(backupSummary).isEqualTo(mContext.getString(R.string.backup_summary_state_off));
    }

    @Test
    public void testGetSummary_TwoProfiles_returnsNull() throws Exception {
        mUserManager.addUserProfile(new UserHandle(0));
        mUserManager.addUserProfile(new UserHandle(10));
        when(mBackupManager.isBackupEnabled()).thenReturn(true);

        String backupSummary = mBackupSettingsHelper.getSummary();

        assertThat(backupSummary).isNull();
    }

    @Test