If backup service is not available, remove Settings->Backup and Backup->"Backup is disabled by
admin" from search results. "Backup -> Backup" still appears due to the PrivacySettingsActivity. On clicking that, we get "Backup is disabled by admin" which is OK Bug: 129743816 Test: 1. atest -v UserBackupSettingsActivityTest 2. atest -v BackupInactivePreferenceControllerTest 3. Create and switch to secondary user. Type "backup" in settings search. Note that only "Backup->Backup" is shown and on clicking it, we get "Backup is disabled by admin" Change-Id: Ic13e2d745c9511cbebe27aa4c6f5cd89b277fc37
This commit is contained in:
@@ -639,12 +639,7 @@ public class SettingsActivity extends SettingsBaseActivity
|
|||||||
showDev, isAdmin)
|
showDev, isAdmin)
|
||||||
|| somethingChanged;
|
|| somethingChanged;
|
||||||
|
|
||||||
// For profiles, we want them to be included in the profile select dialog even if
|
boolean enableBackupTile = new BackupSettingsHelper(this).showBackupSettingsForUser();
|
||||||
// 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();
|
|
||||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||||
UserBackupSettingsActivity.class.getName()), enableBackupTile, isAdmin)
|
UserBackupSettingsActivity.class.getName()), enableBackupTile, isAdmin)
|
||||||
|| somethingChanged;
|
|| somethingChanged;
|
||||||
|
@@ -28,6 +28,9 @@ public class BackupInactivePreferenceController extends BasePreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
|
if (!new BackupSettingsHelper(mContext).showBackupSettingsForUser()) {
|
||||||
|
return AVAILABLE_UNSEARCHABLE;
|
||||||
|
}
|
||||||
if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.BACKUP_INACTIVE)) {
|
if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.BACKUP_INACTIVE)) {
|
||||||
return UNSUPPORTED_ON_DEVICE;
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
|
@@ -50,6 +50,14 @@ public class BackupSettingsHelper {
|
|||||||
mContext = context;
|
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.
|
* If there is only one profile, show whether the backup is on or off.
|
||||||
* Otherwise, show nothing.
|
* Otherwise, show nothing.
|
||||||
|
@@ -98,7 +98,7 @@ public class UserBackupSettingsActivity extends FragmentActivity implements Inde
|
|||||||
*/
|
*/
|
||||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider() {
|
||||||
private static final String BACKUP_SEARCH_INDEX_KEY = "backup";
|
private static final String BACKUP_SEARCH_INDEX_KEY = "Backup";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
|
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
|
||||||
@@ -119,6 +119,15 @@ public class UserBackupSettingsActivity extends FragmentActivity implements Inde
|
|||||||
|
|
||||||
return result;
|
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
|
@VisibleForTesting
|
||||||
|
@@ -31,8 +31,10 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import static com.android.settings.backup.UserBackupSettingsActivityTest.ShadowBackupSettingsHelper;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowPrivacySettingsUtils.class})
|
@Config(shadows = {ShadowPrivacySettingsUtils.class, ShadowBackupSettingsHelper.class})
|
||||||
public class BackupInactivePreferenceControllerTest {
|
public class BackupInactivePreferenceControllerTest {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BackupInactivePreferenceController mController;
|
private BackupInactivePreferenceController mController;
|
||||||
@@ -48,18 +50,32 @@ public class BackupInactivePreferenceControllerTest {
|
|||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
ShadowPrivacySettingsUtils.reset();
|
ShadowPrivacySettingsUtils.reset();
|
||||||
|
ShadowBackupSettingsHelper.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_isnotInvisibleKey_shouldBeAvailable() {
|
public void getAvailabilityStatus_isnotInvisibleKey_showBackup_shouldBeAvailable() {
|
||||||
ShadowPrivacySettingsUtils.setIsInvisibleKey(false);
|
ShadowPrivacySettingsUtils.setIsInvisibleKey(false);
|
||||||
|
ShadowBackupSettingsHelper.showBackupSettingsForUser = true;
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus())
|
assertThat(mController.getAvailabilityStatus())
|
||||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_isnotInvisibleKey_dontShowBackup_shouldBeUnsearchable() {
|
||||||
|
ShadowPrivacySettingsUtils.setIsInvisibleKey(false);
|
||||||
|
ShadowBackupSettingsHelper.showBackupSettingsForUser = false;
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_isInvisibleKey_shouldBeDisabledUnsupported() {
|
public void getAvailabilityStatus_isInvisibleKey_shouldBeDisabledUnsupported() {
|
||||||
ShadowPrivacySettingsUtils.setIsInvisibleKey(true);
|
ShadowPrivacySettingsUtils.setIsInvisibleKey(true);
|
||||||
|
ShadowBackupSettingsHelper.showBackupSettingsForUser = true;
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus())
|
assertThat(mController.getAvailabilityStatus())
|
||||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,6 @@ import android.app.Application;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.UserHandle;
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
@@ -53,8 +52,7 @@ import org.robolectric.annotation.Resetter;
|
|||||||
import org.robolectric.shadows.ShadowPackageManager;
|
import org.robolectric.shadows.ShadowPackageManager;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {UserBackupSettingsActivityTest.ShadowBackupSettingsHelper.class,
|
@Config(shadows = {UserBackupSettingsActivityTest.ShadowBackupSettingsHelper.class})
|
||||||
UserBackupSettingsActivityTest.ShadowUserHandle.class})
|
|
||||||
public class UserBackupSettingsActivityTest {
|
public class UserBackupSettingsActivityTest {
|
||||||
private ActivityController<UserBackupSettingsActivity> mActivityController;
|
private ActivityController<UserBackupSettingsActivity> mActivityController;
|
||||||
private UserBackupSettingsActivity mActivity;
|
private UserBackupSettingsActivity mActivity;
|
||||||
@@ -85,7 +83,7 @@ public class UserBackupSettingsActivityTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void resetShadows() {
|
public void resetShadows() {
|
||||||
ShadowUserHandle.reset();
|
ShadowBackupSettingsHelper.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -125,7 +123,9 @@ public class UserBackupSettingsActivityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNonIndexableKeys_SystemUser() {
|
public void getNonIndexableKeys_whenShowBackupSettings() {
|
||||||
|
ShadowBackupSettingsHelper.showBackupSettingsForUser = true;
|
||||||
|
|
||||||
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
||||||
mApplication, true)).isNotEmpty();
|
mApplication, true)).isNotEmpty();
|
||||||
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||||
@@ -133,17 +133,24 @@ public class UserBackupSettingsActivityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNonIndexableKeys_NonSystemUser() {
|
public void getNonIndexableKeys_whenDontShowBackupSettings() {
|
||||||
ShadowUserHandle.setUid(1); // Non-SYSTEM user.
|
ShadowBackupSettingsHelper.showBackupSettingsForUser = false;
|
||||||
|
|
||||||
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(
|
||||||
mApplication, true)).isNotEmpty();
|
mApplication, true)).isNotEmpty();
|
||||||
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
assertThat(UserBackupSettingsActivity.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||||
mApplication)).isEmpty();
|
mApplication)).contains("Backup");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implements(BackupSettingsHelper.class)
|
@Implements(BackupSettingsHelper.class)
|
||||||
public static class ShadowBackupSettingsHelper {
|
public static class ShadowBackupSettingsHelper {
|
||||||
|
static boolean showBackupSettingsForUser = true;
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public boolean showBackupSettingsForUser() {
|
||||||
|
return showBackupSettingsForUser;
|
||||||
|
}
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
protected Intent getIntentForBackupSettings() {
|
protected Intent getIntentForBackupSettings() {
|
||||||
return mIntent;
|
return mIntent;
|
||||||
@@ -153,24 +160,10 @@ public class UserBackupSettingsActivityTest {
|
|||||||
protected boolean isBackupProvidedByManufacturer() {
|
protected boolean isBackupProvidedByManufacturer() {
|
||||||
return mIsBackupProvidedByOEM;
|
return mIsBackupProvidedByOEM;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Implements(UserHandle.class)
|
|
||||||
public static class ShadowUserHandle {
|
|
||||||
private static int sUid = 0; // SYSTEM by default
|
|
||||||
|
|
||||||
public static void setUid(int uid) {
|
|
||||||
sUid = uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Implementation
|
|
||||||
protected static int myUserId() {
|
|
||||||
return sUid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Resetter
|
@Resetter
|
||||||
public static void reset() {
|
public static void reset() {
|
||||||
sUid = 0;
|
showBackupSettingsForUser = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user