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

Commit 140d7da9 authored by Yvonne Jiang's avatar Yvonne Jiang Committed by Android (Google) Code Review
Browse files

Merge "Conditionally update SupervisionMainSwitchPreference summary based on...

Merge "Conditionally update SupervisionMainSwitchPreference summary based on supervision state." into main
parents 0260d257 e138b258
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -14525,7 +14525,9 @@ Data usage charges may apply.</string>
    <!-- Title of toggle to enable or disable device supervision [CHAR LIMIT=60] -->
    <string name="device_supervision_switch_title">Use device supervision</string>
    <!-- Description of device supervision toggle when PIN has never been set up [CHAR LIMIT=NONE] -->
    <string name="device_supervision_switch_no_pin_summary">Set up PIN to get started</string>
    <string name="device_supervision_switch_no_pin_summary">Set up PIN</string>
    <!-- Description of device supervision toggle when PIN is set up but supervision is not enabled [CHAR LIMIT=NONE] -->
    <string name="device_supervision_switch_paused_summary">Paused</string>
    <!-- Search keywords for supervision settings [CHAR LIMIT=NONE] -->
    <string name="keywords_supervision_settings">supervision, parental supervision, parental controls</string>
    <!-- Title for supervision PIN management settings entry [CHAR LIMIT=60] -->
+11 −3
Original line number Diff line number Diff line
@@ -62,10 +62,14 @@ class SupervisionMainSwitchPreference(
    override val title
        get() = R.string.device_supervision_switch_title

    // TODO(b/383568136): Make presence of summary conditional on whether PIN
    // has been set up before or not.
    override fun getSummary(context: Context): CharSequence? =
        if (!context.isSupervisingCredentialSet) {
            context.getString(R.string.device_supervision_switch_no_pin_summary)
        } else if (supervisionMainSwitchStorage.getBoolean(KEY)!!) {
            context.getString(R.string.switch_on_text)
        } else {
            context.getString(R.string.device_supervision_switch_paused_summary)
        }

    override fun storage(context: Context): KeyValueStore = supervisionMainSwitchStorage

@@ -121,6 +125,9 @@ class SupervisionMainSwitchPreference(
        }
        if (resultCode == Activity.RESULT_OK) {
            val mainSwitchPreference = lifeCycleContext.requirePreference<MainSwitchPreference>(KEY)

            // Value only needs to be toggled in the non-setup case. The setup flow will
            // unconditionally enable supervision internally when successful.
            val newValue =
                if (requestCode == REQUEST_CODE_SET_UP_SUPERVISION) {
                    true
@@ -128,6 +135,7 @@ class SupervisionMainSwitchPreference(
                    !supervisionMainSwitchStorage.getBoolean(KEY)!!
                }
            mainSwitchPreference.setChecked(newValue)
            lifeCycleContext.notifyPreferenceChange(KEY)
            updateDependentPreferencesEnabledState(mainSwitchPreference, newValue)
            updateDependentPreferenceSummary(mainSwitchPreference)
            lifeCycleContext.notifyPreferenceChange(SupervisionPinManagementScreen.KEY)
+24 −0
Original line number Diff line number Diff line
@@ -75,6 +75,30 @@ class SupervisionMainSwitchPreferenceTest {
        preference.onCreate(mockLifeCycleContext)
    }

    @Test
    fun getSummary_noPinSet_returnsNoPinSummary() {
        setSupervisionEnabled(false)
        setSupervisingProfileCreated(false)

        assertThat(preference.getSummary(context)).isEqualTo("Set up PIN")
    }

    @Test
    fun getSummary_disabled_pinSet_returnsPausedSummary() {
        setSupervisionEnabled(false)
        setSupervisingProfileCreated(true)

        assertThat(preference.getSummary(context)).isEqualTo("Paused")
    }

    @Test
    fun getSummary_enabled_pinSet_returnsOnSummary() {
        setSupervisionEnabled(true)
        setSupervisingProfileCreated(true)

        assertThat(preference.getSummary(context)).isEqualTo("On")
    }

    @Test
    fun checked_supervisionEnabled_returnTrue() {
        setSupervisionEnabled(true)