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

Commit 04900a51 authored by Xiaomiao Zhang's avatar Xiaomiao Zhang
Browse files

Add learn more action to open the plink.

Bug: 411104868
Test: local manual test
Flag: android.app.supervision.flags.enable_web_content_filters_screen
Change-Id: If328d8a17c55d81680276cf5403f14f89388868d
parent 75c4eeb2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14602,6 +14602,8 @@ Data usage charges may apply.</string>
    <string name="supervision_web_content_filters_search_filter_on_title">Block explicit search result</string>
    <!-- Summary for web content filters search category filter on option [CHAR LIMIT=NONE] -->
    <string name="supervision_web_content_filters_search_filter_on_summary">For search engines on this device</string>
    <!-- Learn more link for web content filters footer. [CHAR LIMIT=NONE]-->
    <string name="supervision_web_content_filters_learn_more_link" translatable="false">https://support.google.com/android?p=device_supervision_web_filters</string>
    <!-- Title for web content filters search category filter off option [CHAR LIMIT=60] -->
    <string name="supervision_web_content_filters_search_filter_off_title">Filter off</string>
    <!-- Generic content description that is attached to the preview illustration at the top of an Accessibility feature toggle page. [CHAR LIMIT=NONE] -->
+29 −2
Original line number Diff line number Diff line
@@ -15,15 +15,42 @@
 */
package com.android.settings.supervision

import android.util.Log
import androidx.preference.Preference
import com.android.settings.R
import com.android.settings.widget.FooterPreferenceBinding
import com.android.settings.widget.FooterPreferenceMetadata
import com.android.settingslib.HelpUtils
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.widget.FooterPreference

class SupervisionWebContentFiltersFooterPreference : FooterPreferenceMetadata {
class SupervisionWebContentFiltersFooterPreference :
    FooterPreferenceMetadata, FooterPreferenceBinding {
    override val key: String
        get() = KEY

    // TODO(b/411104868): Add learn more link once help article link is retrieved.
    override fun bind(preference: Preference, metadata: PreferenceMetadata) {
        super.bind(preference, metadata)
        val footerPreference = preference as FooterPreference
        val context = preference.context

        footerPreference.setLearnMoreAction {
            val intent =
                HelpUtils.getHelpIntent(
                    context,
                    context.getString(R.string.supervision_web_content_filters_learn_more_link),
                    context::class.java.name,
                )
            if (intent != null) {
                context.startActivity(intent)
            } else {
                Log.w(TAG, "HelpIntent is null")
            }
        }
    }

    companion object {
        private const val TAG = "WebContentFilters"
        const val KEY = "web_content_filters_footer"
    }
}
+28 −2
Original line number Diff line number Diff line
@@ -15,18 +15,44 @@
 */
package com.android.settings.supervision

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.preference.PreferenceViewHolder
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settingslib.preference.createAndBindWidget
import com.android.settingslib.widget.FooterPreference
import com.android.settingslib.widget.preference.footer.R
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SupervisionWebContentFiltersFooterPreferenceTest {
    private val context: Context = ApplicationProvider.getApplicationContext()
    private val footerPreference = SupervisionWebContentFiltersFooterPreference()

    @Test
    fun getTitle() {
        assertThat(footerPreference.title)
            .isEqualTo(0)
        assertThat(footerPreference.title).isEqualTo(0)
    }

    @Test
    fun learnMoreTextExists() {
        footerPreference.createAndBindWidget<FooterPreference>(context).also {
            val holder =
                PreferenceViewHolder.createInstanceForTests(
                    LayoutInflater.from(context)
                        .inflate(R.layout.preference_footer, /* root= */ null)
                )
            it.onBindViewHolder(holder)
            val learnMoreView = holder.itemView.findViewById<TextView?>(R.id.settingslib_learn_more)
            assertThat(learnMoreView).isNotNull()
            assertThat(learnMoreView?.visibility).isEqualTo(View.VISIBLE)
            assertThat(learnMoreView?.text.toString())
                .isEqualTo(context.getString(R.string.settingslib_learn_more_text))
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -233,6 +233,8 @@ class SupervisionWebContentFiltersScreenTest {
                    )!!

                assertThat(footerPreference).isNotNull()

                //TODO(b/415843744): Add tests for learn more link clicks.
            }
    }
}