Disable screen saver setting for non-system users.

On devices where non-system users are not allowed to dream, disable the
screen saver setting when the current user is not the system user.

Bug: 213906883
Test: atest ScreenSaverPreferenceControllerTest
Test: Manually with the following steps:
Step 1: On a device with the config setting
config_dreamsOnlyEnabledForSystemUser set to false, make sure that
non-system users can still access the screen saver setting.
Step 2: On a device with the config setting
config_dreamsOnlyEnabledForSystemUser setting is set to true, make sure
that non-system users can not access (or see) the screen saver setting.
Step 3: Make sure that system users can still see the screen saver
setting on a device where config_dreamsOnlyEnabledForSystemUser is set
to true.

Change-Id: I7e167ed5a1ea183c725ba89a57b8d0b372064b82
This commit is contained in:
Will
2022-04-12 16:22:06 -07:00
parent 32f8460aac
commit 640247eb58
2 changed files with 122 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
package com.android.settings.display;
import android.content.Context;
import android.os.UserManager;
import androidx.preference.Preference;
@@ -32,8 +33,11 @@ public class ScreenSaverPreferenceController extends AbstractPreferenceControlle
@Override
public boolean isAvailable() {
return mContext.getResources().getBoolean(
final boolean dreamsSupported = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsSupported);
final boolean dreamsOnlyEnabledForSystemUser = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsOnlyEnabledForSystemUser);
return dreamsSupported && (!dreamsOnlyEnabledForSystemUser || isSystemUser());
}
@Override
@@ -45,4 +49,9 @@ public class ScreenSaverPreferenceController extends AbstractPreferenceControlle
public void updateState(Preference preference) {
preference.setSummary(DreamSettings.getSummaryTextWithDreamName(mContext));
}
private boolean isSystemUser() {
final UserManager userManager = mContext.getSystemService(UserManager.class);
return userManager.isSystemUser();
}
}