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

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

Merge "Dynamically set summary of web content filters entry." into main

parents ed2db34e fb20a260
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -14486,6 +14486,14 @@ Data usage charges may apply.</string>
    <string name="supervision_add_pin_recovery_title">Tap to add recovery</string>
    <string name="supervision_add_pin_recovery_title">Tap to add recovery</string>
    <!-- Title for web content filters entry [CHAR LIMIT=60] -->
    <!-- Title for web content filters entry [CHAR LIMIT=60] -->
    <string name="supervision_web_content_filters_title">Web content filters</string>
    <string name="supervision_web_content_filters_title">Web content filters</string>
    <!-- Summary for web content filters entry both on case [CHAR LIMIT=60] -->
    <string name="supervision_web_content_filters_summary_both_on">ON / Chrome &amp; Search filters set</string>
    <!-- Summary for web content filters entry chrome on [CHAR LIMIT=60] -->
    <string name="supervision_web_content_filters_summary_chrome_on">ON / Chrome filter set</string>
    <!-- Summary for web content filters entry chrome on [CHAR LIMIT=60] -->
    <string name="supervision_web_content_filters_summary_search_on">ON / Search filter set</string>
    <!-- Summary for web content filters entry chrome on [CHAR LIMIT=60] -->
    <string name="supervision_web_content_filters_summary_both_off">No filters set</string>
    <!-- Title for web content filters browser category [CHAR LIMIT=60] -->
    <!-- Title for web content filters browser category [CHAR LIMIT=60] -->
    <string name="supervision_web_content_filters_browser_title">Google Chrome and Web</string>
    <string name="supervision_web_content_filters_browser_title">Google Chrome and Web</string>
    <!-- Title for web content filters browser category block explicit sites option [CHAR LIMIT=60] -->
    <!-- Title for web content filters browser category block explicit sites option [CHAR LIMIT=60] -->
+20 −2
Original line number Original line Diff line number Diff line
@@ -17,15 +17,19 @@ package com.android.settings.supervision


import android.app.supervision.flags.Flags
import android.app.supervision.flags.Flags
import android.content.Context
import android.content.Context
import android.provider.Settings.Secure.BROWSER_CONTENT_FILTERS_ENABLED
import android.provider.Settings.Secure.SEARCH_CONTENT_FILTERS_ENABLED
import com.android.settings.R
import com.android.settings.R
import com.android.settingslib.datastore.SettingsSecureStore
import com.android.settingslib.metadata.PreferenceCategory
import com.android.settingslib.metadata.PreferenceCategory
import com.android.settingslib.metadata.PreferenceSummaryProvider
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.preferenceHierarchy
import com.android.settingslib.metadata.preferenceHierarchy
import com.android.settingslib.preference.PreferenceScreenCreator
import com.android.settingslib.preference.PreferenceScreenCreator


/** Web content filters landing page (Settings > Supervision > Web content filters). */
/** Web content filters landing page (Settings > Supervision > Web content filters). */
@ProvidePreferenceScreen(SupervisionWebContentFiltersScreen.KEY)
@ProvidePreferenceScreen(SupervisionWebContentFiltersScreen.KEY)
class SupervisionWebContentFiltersScreen : PreferenceScreenCreator {
class SupervisionWebContentFiltersScreen : PreferenceScreenCreator, PreferenceSummaryProvider {
    override fun isFlagEnabled(context: Context) = Flags.enableWebContentFiltersScreen()
    override fun isFlagEnabled(context: Context) = Flags.enableWebContentFiltersScreen()


    override val key: String
    override val key: String
@@ -34,10 +38,24 @@ class SupervisionWebContentFiltersScreen : PreferenceScreenCreator {
    override val title: Int
    override val title: Int
        get() = R.string.supervision_web_content_filters_title
        get() = R.string.supervision_web_content_filters_title


    // TODO(b/395134536) update the summary once the string is finalized.
    override val icon: Int
    override val icon: Int
        get() = R.drawable.ic_globe
        get() = R.drawable.ic_globe


    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) {
                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) {
            context.getString(R.string.supervision_web_content_filters_summary_search_on)
        } else {
            context.getString(R.string.supervision_web_content_filters_summary_both_off)
        }
    }

    override fun fragmentClass() = SupervisionWebContentFiltersFragment::class.java
    override fun fragmentClass() = SupervisionWebContentFiltersFragment::class.java


    override fun getPreferenceHierarchy(context: Context) =
    override fun getPreferenceHierarchy(context: Context) =
+33 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,9 @@ import android.content.IntentFilter
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import android.platform.test.flag.junit.SetFlagsRule
import android.provider.Settings
import android.provider.Settings.Secure.BROWSER_CONTENT_FILTERS_ENABLED
import android.provider.Settings.Secure.SEARCH_CONTENT_FILTERS_ENABLED
import androidx.fragment.app.testing.FragmentScenario
import androidx.fragment.app.testing.FragmentScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -72,6 +75,36 @@ class SupervisionWebContentFiltersScreenTest {
            .isEqualTo(R.string.supervision_web_content_filters_title)
            .isEqualTo(R.string.supervision_web_content_filters_title)
    }
    }


    @Test
    @EnableFlags(Flags.FLAG_ENABLE_WEB_CONTENT_FILTERS_SCREEN)
    fun getSummary() {
        // Filters are default off.
        assertThat(supervisionWebContentFiltersScreen.getSummary(context))
            .isEqualTo(context.getString(R.string.supervision_web_content_filters_summary_both_off))

        // Enable browser filters.
        Settings.Secure.putInt(context.getContentResolver(), BROWSER_CONTENT_FILTERS_ENABLED, 1)

        assertThat(supervisionWebContentFiltersScreen.getSummary(context))
            .isEqualTo(
                context.getString(R.string.supervision_web_content_filters_summary_chrome_on)
            )

        // Enable search filters.
        Settings.Secure.putInt(context.getContentResolver(), SEARCH_CONTENT_FILTERS_ENABLED, 1)

        assertThat(supervisionWebContentFiltersScreen.getSummary(context))
            .isEqualTo(context.getString(R.string.supervision_web_content_filters_summary_both_on))

        // Disable browser filters.
        Settings.Secure.putInt(context.getContentResolver(), BROWSER_CONTENT_FILTERS_ENABLED, 0)

        assertThat(supervisionWebContentFiltersScreen.getSummary(context))
            .isEqualTo(
                context.getString(R.string.supervision_web_content_filters_summary_search_on)
            )
    }

    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_WEB_CONTENT_FILTERS_SCREEN)
    @EnableFlags(Flags.FLAG_ENABLE_WEB_CONTENT_FILTERS_SCREEN)
    fun flagEnabled() {
    fun flagEnabled() {