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

Commit e8288512 authored by Roy Chou's avatar Roy Chou
Browse files

chore(brightness suw): adjust auto brightness detail page footer content description

Ref to the bug, s2s and talkback pages' footer content descriptions are
prefixed with "About XXX" for talkbalk info announcement. Therefore, for
auto brightness detail page in SUW, we also prefix "About adaptive
brightness" to the footer preference content description, to improve
the consistency with other accessiblity feature suw pages.

Bug: 347859318
Flag: com.android.settings.accessibility.add_brightness_settings_in_suw
Test: manually
      atest AutoBrightnessPreferenceFragmentForSetupWizardTest
Change-Id: Ieda4bcffb4f4e11ea68c961beee5c2fff1b29f2c
parent 9bd19f46
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2753,6 +2753,9 @@
    <string name="brightness">Brightness level</string>
    <!-- Sound & display settings screen, setting option name to enable adaptive brightness [CHAR LIMIT=30] -->
    <string name="auto_brightness_title">Adaptive brightness</string>
    <!-- Note: The content description title is only applied in adaptive brightness detailed page in setup wizard flow, to make the consistency with other accessibility suw pages. -->
    <!-- ContentDescription title for adaptive brightness detailed page footer. [CHAR LIMIT=60] -->
    <string name="auto_brightness_content_description_title">About adaptive brightness</string>
    <!-- Description about the feature adaptive brightness -->
    <string name="auto_brightness_description">Your screen brightness will automatically adjust to your environment and activities. You can move the slider manually to help adaptive brightness learn your preferences.</string>
    <!-- Setting option summary when adaptive brightness is on [CHAR LIMIT=NONE] -->
+17 −0
Original line number Diff line number Diff line
@@ -27,11 +27,13 @@ import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;

import com.android.settings.R;
import com.android.settings.display.AutoBrightnessSettings;
import com.android.settingslib.Utils;
import com.android.settingslib.widget.FooterPreference;

import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupdesign.GlifPreferenceLayout;
@@ -41,10 +43,14 @@ import com.google.android.setupdesign.GlifPreferenceLayout;
 */
public class AutoBrightnessPreferenceFragmentForSetupWizard extends AutoBrightnessSettings {

    private static final String FOOTER_PREFERENCE_KEY = "auto_brightness_footer";

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        updateFooterContentDescription();

        if (view instanceof GlifPreferenceLayout) {
            final GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
            final String title = getContext().getString(
@@ -78,4 +84,15 @@ public class AutoBrightnessPreferenceFragmentForSetupWizard extends AutoBrightne
    public int getMetricsCategory() {
        return SettingsEnums.SUW_ACCESSIBILITY_AUTO_BRIGHTNESS;
    }

    private void updateFooterContentDescription() {
        final PreferenceScreen screen = getPreferenceScreen();
        final FooterPreference footerPreference = screen.findPreference(FOOTER_PREFERENCE_KEY);
        if (footerPreference != null) {
            String title = getString(R.string.auto_brightness_content_description_title);
            final StringBuilder sb = new StringBuilder();
            sb.append(title).append("\n\n").append(footerPreference.getTitle());
            footerPreference.setContentDescription(sb);
        }
    }
}
+64 −40
Original line number Diff line number Diff line
@@ -18,78 +18,102 @@ package com.android.settings.accessibility;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.lifecycle.LifecycleOwner;
import androidx.test.core.app.ApplicationProvider;
import androidx.fragment.app.FragmentFactory;
import androidx.fragment.app.testing.FragmentScenario;
import androidx.lifecycle.Lifecycle;
import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settingslib.widget.FooterPreference;

import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupdesign.GlifLayout;
import com.google.android.setupdesign.GlifPreferenceLayout;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;

/** Tests for {@link AutoBrightnessPreferenceFragmentForSetupWizard}. */
@RunWith(RobolectricTestRunner.class)
public class AutoBrightnessPreferenceFragmentForSetupWizardTest {

    @Rule
    public final MockitoRule mMockito = MockitoJUnit.rule();
    // Same as AutoBrightnessPreferenceFragmentForSetupWizard#FOOTER_PREFERENCE_KEY
    private static final String FOOTER_PREFERENCE_KEY = "auto_brightness_footer";

    private FragmentScenario<AutoBrightnessPreferenceFragmentForSetupWizard> mFragmentScenario;

    @Spy
    private final Context mContext = ApplicationProvider.getApplicationContext();
    @Mock
    private GlifPreferenceLayout mGlifLayoutView;
    @Mock
    private FooterBarMixin mFooterBarMixin;
    private AutoBrightnessPreferenceFragmentForSetupWizard mFragment;
    private GlifLayout mGlifLayout;

    @Before
    public void setUp() {
        mFragment = spy(new AutoBrightnessPreferenceFragmentForSetupWizard());
        doReturn(mock(LifecycleOwner.class)).when(mFragment).getViewLifecycleOwner();
        doReturn(mContext).when(mFragment).getContext();
        when(mGlifLayoutView.getMixin(eq(FooterBarMixin.class))).thenReturn(mFooterBarMixin);
        mFragmentScenario = FragmentScenario
                .launch(
                        AutoBrightnessPreferenceFragmentForSetupWizard.class,
                        /* fragmentArgs= */ (Bundle) null,
                        R.style.GlifTheme,
                        /* factory= */ (FragmentFactory) null)
                .moveToState(Lifecycle.State.RESUMED);
        mFragmentScenario.onFragment(fragment -> mFragment = fragment);

        View view = mFragment.getView();
        assertThat(view).isInstanceOf(GlifPreferenceLayout.class);
        mGlifLayout = (GlifLayout) view;
    }

    @After
    public void tearDown() {
        mFragmentScenario.close();
    }

    @Test
    public void onViewCreated_verifyGlifHerderText() {
        assertThat(mGlifLayout.getHeaderText())
                .isEqualTo(mFragment.getString(R.string.auto_brightness_title));
    }

    @Test
    public void setHeaderText_onViewCreated_verifyAction() {
        final String title = "title";
        doReturn(title).when(mContext).getString(R.string.auto_brightness_title);
    public void onViewCreated_verifyGlifFooter() {
        FooterBarMixin footerMixin = mGlifLayout.getMixin(FooterBarMixin.class);
        assertThat(footerMixin).isNotNull();

        mFragment.onViewCreated(mGlifLayoutView, null);
        Button footerButton = footerMixin.getPrimaryButtonView();
        assertThat(footerButton).isNotNull();
        assertThat(footerButton.getText().toString()).isEqualTo(mFragment.getString(R.string.done));

        verify(mGlifLayoutView).setHeaderText(title);
        footerButton.performClick();
        assertThat(mFragment.getActivity().isFinishing()).isTrue();
    }

    @Test
    public void getMetricsCategory_returnsCorrectCategory() {
        assertThat(mFragment.getMetricsCategory()).isEqualTo(
                SettingsEnums.SUW_ACCESSIBILITY_AUTO_BRIGHTNESS);
    public void onViewCreated_verifyFooterPreference() {
        Preference pref = mFragment.findPreference(FOOTER_PREFERENCE_KEY);
        assertThat(pref).isInstanceOf(FooterPreference.class);

        FooterPreference footerPref = (FooterPreference) pref;
        String exactTitle = footerPref.getTitle().toString();
        assertThat(exactTitle).isEqualTo(mFragment.getString(R.string.auto_brightness_description));

        // Ensure that footer content description has "About XXX" prefix for consistency with other
        // accessibility suw pages
        String expectedContentDescription =
                mFragment.getString(R.string.auto_brightness_content_description_title)
                        + "\n\n" + exactTitle;
        assertThat(footerPref.getContentDescription().toString())
                .isEqualTo(expectedContentDescription);
    }

    @Test
    public void onViewCreated_verifyAction() {
        mFragment.onViewCreated(mGlifLayoutView, null);

        verify(mFooterBarMixin).setPrimaryButton(any());
    public void getMetricsCategory_returnsCorrectCategory() {
        assertThat(mFragment.getMetricsCategory()).isEqualTo(
                SettingsEnums.SUW_ACCESSIBILITY_AUTO_BRIGHTNESS);
    }
}