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

Commit 2ec2c633 authored by Chandan Nath's avatar Chandan Nath Committed by Android (Google) Code Review
Browse files

Merge "If backup service is not available, remove Settings->Backup and...

Merge "If backup service is not available, remove Settings->Backup and Backup->"Backup is disabled by admin" from search results." into qt-dev
parents 01b63327 826a91c5
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -639,12 +639,7 @@ public class SettingsActivity extends SettingsBaseActivity
                showDev, isAdmin)
                || somethingChanged;

        // For profiles, we want them to be included in the profile select dialog even if
        // backup is not activated.
        // For other users, enable/disable backup settings depending on whether backup is activated
        // for the user.
        boolean enableBackupTile = um.isManagedProfile()
                || new BackupSettingsHelper(this).isBackupServiceActive();
        boolean enableBackupTile = new BackupSettingsHelper(this).showBackupSettingsForUser();
        somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
                UserBackupSettingsActivity.class.getName()), enableBackupTile, isAdmin)
                || somethingChanged;
+3 −0
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ public class BackupInactivePreferenceController extends BasePreferenceController

    @Override
    public int getAvailabilityStatus() {
        if (!new BackupSettingsHelper(mContext).showBackupSettingsForUser()) {
            return AVAILABLE_UNSEARCHABLE;
        }
        if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.BACKUP_INACTIVE)) {
            return UNSUPPORTED_ON_DEVICE;
        }
+8 −0
Original line number Diff line number Diff line
@@ -50,6 +50,14 @@ public class BackupSettingsHelper {
        mContext = context;
    }

    public boolean showBackupSettingsForUser() {
        // For profiles, we want them to be included in the profile select dialog even if
        // backup is not activated.
        // For other users, enable/disable backup settings depending on whether backup is activated
        // for the user.
        return UserManager.get(mContext).isManagedProfile() || isBackupServiceActive();
    }

    /**
     * If there is only one profile, show whether the backup is on or off.
     * Otherwise, show nothing.
+10 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public class UserBackupSettingsActivity extends FragmentActivity implements Inde
     */
    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider() {
                private static final String BACKUP_SEARCH_INDEX_KEY = "backup";
                private static final String BACKUP_SEARCH_INDEX_KEY = "Backup";

                @Override
                public List<SearchIndexableRaw> getRawDataToIndex(Context context,
@@ -119,6 +119,15 @@ public class UserBackupSettingsActivity extends FragmentActivity implements Inde

                    return result;
                }

                @Override
                public List<String> getNonIndexableKeys(Context context) {
                    final List<String> keys = super.getNonIndexableKeys(context);
                    if (!new BackupSettingsHelper(context).showBackupSettingsForUser()) {
                        keys.add(BACKUP_SEARCH_INDEX_KEY);
                    }
                    return keys;
                }
            };

    @VisibleForTesting
+18 −2
Original line number Diff line number Diff line
@@ -31,8 +31,10 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static com.android.settings.backup.UserBackupSettingsActivityTest.ShadowBackupSettingsHelper;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowPrivacySettingsUtils.class})
@Config(shadows = {ShadowPrivacySettingsUtils.class, ShadowBackupSettingsHelper.class})
public class BackupInactivePreferenceControllerTest {
    private Context mContext;
    private BackupInactivePreferenceController mController;
@@ -48,18 +50,32 @@ public class BackupInactivePreferenceControllerTest {
    @After
    public void tearDown() {
        ShadowPrivacySettingsUtils.reset();
        ShadowBackupSettingsHelper.reset();
    }

    @Test
    public void getAvailabilityStatus_isnotInvisibleKey_shouldBeAvailable() {
    public void getAvailabilityStatus_isnotInvisibleKey_showBackup_shouldBeAvailable() {
        ShadowPrivacySettingsUtils.setIsInvisibleKey(false);
        ShadowBackupSettingsHelper.showBackupSettingsForUser = true;

        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.AVAILABLE);
    }

    @Test
    public void getAvailabilityStatus_isnotInvisibleKey_dontShowBackup_shouldBeUnsearchable() {
        ShadowPrivacySettingsUtils.setIsInvisibleKey(false);
        ShadowBackupSettingsHelper.showBackupSettingsForUser = false;

        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.AVAILABLE_UNSEARCHABLE);
    }

    @Test
    public void getAvailabilityStatus_isInvisibleKey_shouldBeDisabledUnsupported() {
        ShadowPrivacySettingsUtils.setIsInvisibleKey(true);
        ShadowBackupSettingsHelper.showBackupSettingsForUser = true;

        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
    }
Loading