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

Commit dd4c7f56 authored by Xiaomiao Zhang's avatar Xiaomiao Zhang
Browse files

Update to read browser and search settings provider keys as integers.

Test: local test
Test: atest SupervisionSafeSitesPreferenceTest
Test: atest SupervisionSafeSearchPreferenceTest
Bug: 412658995
Flag: android.app.supervision.flags.enable_web_content_filters_screen
Change-Id: I6f65ea0498dbf4f658037222142578e381557833
parent 7ba65889
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -35,10 +35,11 @@ class SupervisionSafeSearchDataStore(
            key == SupervisionSearchFilterOffPreference.KEY

    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) {
            SupervisionSearchFilterOffPreference.KEY -> !settingValue
            SupervisionSearchFilterOnPreference.KEY -> settingValue
            SupervisionSearchFilterOffPreference.KEY -> isFilterOff
            SupervisionSearchFilterOnPreference.KEY -> !isFilterOff
            else -> null
        }
            as T?
+4 −3
Original line number Diff line number Diff line
@@ -36,11 +36,12 @@ class SupervisionSafeSitesDataStore(
            key == SupervisionAllowAllSitesPreference.KEY

    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) {
            SupervisionAllowAllSitesPreference.KEY -> !settingValue
            SupervisionAllowAllSitesPreference.KEY -> isFilterOff

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

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

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

    @Test
    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()
        assertThat(filterOnWidget.isChecked).isFalse()

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

    @Test
    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()
        assertThat(blockExplicitSitesWidget.isChecked).isFalse()