Always show backup settings (even if backup is deactivated).
Previously, 1) we showed backup settings for main users (including secondary non-profile users) only when backup was activated 2) for profile users, we always showed backup settings. However, this results in a nullpointer when opening Settings when backup is deactivated for both main and profile user. This CL fixes that nullpointer(and also changes existing functionality since keeping existing functionality and fixing the nullpointer would be too large a code change) For more details, see https://b.corp.google.com/issues/129843872#comment9 and https://b.corp.google.com/issues/129843872#comment12 Bug: 129843872 Test: 1. atest -v UserBackupSettingsActivityTest 2. atest -v BackupInactivePreferenceControllerTest 3a) backup not active for main and profile user. shows "isn't active" for both 3b) backup active for main only. shows backup settings for main user and "isn't active" for profile. 3c) backup active for both. shows backup settings for both. 3d) backup active for profile only is not possible (as profile backup is only active when main user backup is active). if we try to force set it, we get "isn't active" for both 3e) backup not active for secondary user. shows "isn't active" 3f) backup active for secondary user. shows backup settings. Change-Id: Icb87a047068d29eda560c45dfa4ae02bc991b1af
This commit is contained in:
@@ -639,9 +639,8 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
showDev, isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
boolean enableBackupTile = new BackupSettingsHelper(this).showBackupSettingsForUser();
|
||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||
UserBackupSettingsActivity.class.getName()), enableBackupTile, isAdmin)
|
||||
UserBackupSettingsActivity.class.getName()), true, isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||
|
@@ -28,7 +28,7 @@ public class BackupInactivePreferenceController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!new BackupSettingsHelper(mContext).showBackupSettingsForUser()) {
|
||||
if (!new BackupSettingsHelper(mContext).isBackupServiceActive()) {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.BACKUP_INACTIVE)) {
|
||||
|
@@ -50,14 +50,6 @@ 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.
|
||||
|
@@ -123,7 +123,7 @@ public class UserBackupSettingsActivity extends FragmentActivity implements Inde
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> keys = super.getNonIndexableKeys(context);
|
||||
if (!new BackupSettingsHelper(context).showBackupSettingsForUser()) {
|
||||
if (!new BackupSettingsHelper(context).isBackupServiceActive()) {
|
||||
keys.add(BACKUP_SEARCH_INDEX_KEY);
|
||||
}
|
||||
return keys;
|
||||
|
@@ -54,18 +54,18 @@ public class BackupInactivePreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_isnotInvisibleKey_showBackup_shouldBeAvailable() {
|
||||
public void getAvailabilityStatus_isnotInvisibleKey_backupActive_shouldBeAvailable() {
|
||||
ShadowPrivacySettingsUtils.setIsInvisibleKey(false);
|
||||
ShadowBackupSettingsHelper.showBackupSettingsForUser = true;
|
||||
ShadowBackupSettingsHelper.isBackupServiceActive = true;
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_isnotInvisibleKey_dontShowBackup_shouldBeUnsearchable() {
|
||||
public void getAvailabilityStatus_isnotInvisibleKey_backupNotActive_shouldBeUnsearchable() {
|
||||
ShadowPrivacySettingsUtils.setIsInvisibleKey(false);
|
||||
ShadowBackupSettingsHelper.showBackupSettingsForUser = false;
|
||||
ShadowBackupSettingsHelper.isBackupServiceActive = false;
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||
@@ -74,7 +74,7 @@ public class BackupInactivePreferenceControllerTest {
|
||||
@Test
|
||||
public void getAvailabilityStatus_isInvisibleKey_shouldBeDisabledUnsupported() {
|
||||
ShadowPrivacySettingsUtils.setIsInvisibleKey(true);
|
||||
ShadowBackupSettingsHelper.showBackupSettingsForUser = true;
|
||||
ShadowBackupSettingsHelper.isBackupServiceActive = true;
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
|
@@ -123,8 +123,8 @@ public class UserBackupSettingsActivityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_whenShowBackupSettings() {
|
||||
ShadowBackupSettingsHelper.showBackupSettingsForUser = true;
|
||||
public void getNonIndexableKeys_whenBackupServiceActive() {
|
||||
ShadowBackupSettingsHelper.isBackupServiceActive = true;
|
||||
|
||||
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
||||
mApplication, true)).isNotEmpty();
|
||||
@@ -133,8 +133,8 @@ public class UserBackupSettingsActivityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_whenDontShowBackupSettings() {
|
||||
ShadowBackupSettingsHelper.showBackupSettingsForUser = false;
|
||||
public void getNonIndexableKeys_whenBackupServiceNotActive() {
|
||||
ShadowBackupSettingsHelper.isBackupServiceActive = false;
|
||||
|
||||
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
||||
mApplication, true)).isNotEmpty();
|
||||
@@ -144,11 +144,11 @@ public class UserBackupSettingsActivityTest {
|
||||
|
||||
@Implements(BackupSettingsHelper.class)
|
||||
public static class ShadowBackupSettingsHelper {
|
||||
static boolean showBackupSettingsForUser = true;
|
||||
static boolean isBackupServiceActive = true;
|
||||
|
||||
@Implementation
|
||||
public boolean showBackupSettingsForUser() {
|
||||
return showBackupSettingsForUser;
|
||||
public boolean isBackupServiceActive() {
|
||||
return isBackupServiceActive;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
@@ -163,7 +163,7 @@ public class UserBackupSettingsActivityTest {
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
showBackupSettingsForUser = true;
|
||||
isBackupServiceActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user