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

Commit 46dcfcf8 authored by Xiaomiao Zhang's avatar Xiaomiao Zhang Committed by Android (Google) Code Review
Browse files

Merge "Update to read browser and search settings provider keys as integers." into main

parents e414867a dd4c7f56
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -35,10 +35,11 @@ class SupervisionSafeSearchDataStore(
            key == SupervisionSearchFilterOffPreference.KEY
            key == SupervisionSearchFilterOffPreference.KEY


    override fun <T : Any> getValue(key: String, valueType: Class<T>): T? {
    override fun <T : Any> getValue(key: String, valueType: Class<T>): T? {
        val settingValue = (settingsStore.getBoolean(SEARCH_CONTENT_FILTERS_ENABLED) == true)
        val settingValue = settingsStore.getInt(SEARCH_CONTENT_FILTERS_ENABLED)
        val isFilterOff: Boolean = settingValue == null || settingValue <= 0
        return when (key) {
        return when (key) {
            SupervisionSearchFilterOffPreference.KEY -> !settingValue
            SupervisionSearchFilterOffPreference.KEY -> isFilterOff
            SupervisionSearchFilterOnPreference.KEY -> settingValue
            SupervisionSearchFilterOnPreference.KEY -> !isFilterOff
            else -> null
            else -> null
        }
        }
            as T?
            as T?
+4 −3
Original line number Original line Diff line number Diff line
@@ -36,11 +36,12 @@ class SupervisionSafeSitesDataStore(
            key == SupervisionAllowAllSitesPreference.KEY
            key == SupervisionAllowAllSitesPreference.KEY


    override fun <T : Any> getValue(key: String, valueType: Class<T>): T? {
    override fun <T : Any> getValue(key: String, valueType: Class<T>): T? {
        val settingValue = (settingsStore.getBoolean(BROWSER_CONTENT_FILTERS_ENABLED) == true)
        val settingValue = settingsStore.getInt(BROWSER_CONTENT_FILTERS_ENABLED)
        val isFilterOff: Boolean = settingValue == null || settingValue <= 0
        return when (key) {
        return when (key) {
            SupervisionAllowAllSitesPreference.KEY -> !settingValue
            SupervisionAllowAllSitesPreference.KEY -> isFilterOff


            SupervisionBlockExplicitSitesPreference.KEY -> settingValue
            SupervisionBlockExplicitSitesPreference.KEY -> !isFilterOff


            else -> null
            else -> null
        }
        }
+3 −3
Original line number Original line Diff line number Diff line
@@ -43,13 +43,13 @@ class SupervisionWebContentFiltersScreen : PreferenceScreenCreator, PreferenceSu


    override fun getSummary(context: Context): CharSequence? {
    override fun getSummary(context: Context): CharSequence? {
        val dataStore = SettingsSecureStore.get(context)
        val dataStore = SettingsSecureStore.get(context)
        return if (dataStore.getBoolean(BROWSER_CONTENT_FILTERS_ENABLED) == true) {
        return if (dataStore.getInt(BROWSER_CONTENT_FILTERS_ENABLED) == 1) {
            if (dataStore.getBoolean(SEARCH_CONTENT_FILTERS_ENABLED) == true) {
            if (dataStore.getInt(SEARCH_CONTENT_FILTERS_ENABLED) == 1) {
                context.getString(R.string.supervision_web_content_filters_summary_both_on)
                context.getString(R.string.supervision_web_content_filters_summary_both_on)
            } else {
            } else {
                context.getString(R.string.supervision_web_content_filters_summary_chrome_on)
                context.getString(R.string.supervision_web_content_filters_summary_chrome_on)
            }
            }
        } else if (dataStore.getBoolean(SEARCH_CONTENT_FILTERS_ENABLED) == true) {
        } else if (dataStore.getInt(SEARCH_CONTENT_FILTERS_ENABLED) == 1) {
            context.getString(R.string.supervision_web_content_filters_summary_search_on)
            context.getString(R.string.supervision_web_content_filters_summary_search_on)
        } else {
        } else {
            context.getString(R.string.supervision_web_content_filters_summary_both_off)
            context.getString(R.string.supervision_web_content_filters_summary_both_off)
+1 −1
Original line number Original line Diff line number Diff line
@@ -153,7 +153,7 @@ class SupervisionSafeSearchPreferenceTest {


    @Test
    @Test
    fun clickFilterOn_enablesFilter() {
    fun clickFilterOn_enablesFilter() {
        Settings.Secure.putInt(context.getContentResolver(), SEARCH_CONTENT_FILTERS_ENABLED, 0)
        Settings.Secure.putInt(context.getContentResolver(), SEARCH_CONTENT_FILTERS_ENABLED, -1)
        val filterOnWidget = getFilterOnWidget()
        val filterOnWidget = getFilterOnWidget()
        assertThat(filterOnWidget.isChecked).isFalse()
        assertThat(filterOnWidget.isChecked).isFalse()


+1 −1
Original line number Original line Diff line number Diff line
@@ -156,7 +156,7 @@ class SupervisionSafeSitesPreferenceTest {


    @Test
    @Test
    fun clickBlockExplicitSites_enablesFilter() {
    fun clickBlockExplicitSites_enablesFilter() {
        Settings.Secure.putInt(context.getContentResolver(), BROWSER_CONTENT_FILTERS_ENABLED, 0)
        Settings.Secure.putInt(context.getContentResolver(), BROWSER_CONTENT_FILTERS_ENABLED, -1)
        val blockExplicitSitesWidget = getBlockExplicitSitesWidget()
        val blockExplicitSitesWidget = getBlockExplicitSitesWidget()
        assertThat(blockExplicitSitesWidget.isChecked).isFalse()
        assertThat(blockExplicitSitesWidget.isChecked).isFalse()