Merge "Restrict screen saver settings searches to enabled users." into udc-dev

This commit is contained in:
William Leshner
2023-02-27 17:30:48 +00:00
committed by Android (Google) Code Review
4 changed files with 43 additions and 21 deletions

View File

@@ -1293,4 +1293,15 @@ public final class Utils extends com.android.settingslib.Utils {
return context.createContextAsUser(mainUser, 0).getSystemService(UserManager.class)
.isUserForeground();
}
/**
* Returns if dreams are available to the current user.
*/
public static boolean areDreamsAvailableToCurrentUser(Context context) {
final boolean dreamsSupported = context.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsSupported);
final boolean dreamsOnlyEnabledForDockUser = context.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser);
return dreamsSupported && (!dreamsOnlyEnabledForDockUser || canCurrentUserDream(context));
}
}

View File

@@ -35,13 +35,7 @@ public class ScreenSaverPreferenceController extends BasePreferenceController im
@Override
public int getAvailabilityStatus() {
final boolean dreamsSupported = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsSupported);
final boolean dreamsOnlyEnabledForDockUser = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser);
return (dreamsSupported && (!dreamsOnlyEnabledForDockUser
|| Utils.canCurrentUserDream(mContext)))
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
return Utils.areDreamsAvailableToCurrentUser(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override

View File

@@ -36,6 +36,7 @@ import androidx.preference.Preference;
import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -213,6 +214,17 @@ public class DreamSettings extends DashboardFragment implements OnMainSwitchChan
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.dream_fragment_overview);
new SearchIndexProvider(R.xml.dream_fragment_overview);
static class SearchIndexProvider extends BaseSearchIndexProvider {
SearchIndexProvider(int xmlRes) {
super(xmlRes);
}
@Override
protected boolean isPageSearchEnabled(Context context) {
return Utils.areDreamsAvailableToCurrentUser(context);
}
}
}