feat(brightness suw): add brightness preferences in suw

Add brightness level and auto brightness preference in
accessibility_settings_for_setup_wizard.xml. Since the flagging has not
be supported yet for non-Manifest resources, for now we add the
preferences by default, and update the preferece availablity status in
each preference controllers based on the flag.

Bug: 311093618
Flag: ACONFIG com.android.settings.accessibility.add_brightness_settings_in_suw DEVELOPMENT
Test: manually
      atest AccessibilitySettingsForSetupWizardTest
      atest AutoBrightnessPreferenceFragmentForSetupWizardTest
      atest AutoBrightnessPreferenceControllerTest
      atest BrightnessLevelPreferenceControllerTest
Change-Id: I350d99138bdd14bf28828a39e42f707b5b1066c1
This commit is contained in:
Roy Chou
2024-04-18 16:34:26 +00:00
parent 23349d60c0
commit 042c8c7328
19 changed files with 490 additions and 24 deletions

View File

@@ -33,16 +33,22 @@ import android.content.Context;
import android.content.Intent;
import android.hardware.display.BrightnessInfo;
import android.os.PowerManager;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings.System;
import android.view.Display;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.accessibility.Flags;
import com.android.settings.core.SettingsBaseActivity;
import com.android.settingslib.transition.SettingsTransitionHelper;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -58,6 +64,9 @@ import org.robolectric.shadows.ShadowContentResolver;
@RunWith(RobolectricTestRunner.class)
public class BrightnessLevelPreferenceControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Mock
private PowerManager mPowerManager;
@Mock
@@ -90,10 +99,24 @@ public class BrightnessLevelPreferenceControllerTest {
}
@Test
public void isAvailable_shouldAlwaysReturnTrue() {
public void isAvailable_shouldAlwaysReturnTrueWhenNotInSetupWizard() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
public void isAvailable_inSetupWizardAndFlagOn_shouldReturnTrue() {
mController.setInSetupWizard(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
public void isAvailable_inSetupWizardAndFlagOff_shouldReturnFalse() {
mController.setInSetupWizard(true);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void onStart_shouldRegisterObserver() {
BrightnessLevelPreferenceController controller =
@@ -169,13 +192,14 @@ public class BrightnessLevelPreferenceControllerTest {
final BrightnessLevelPreferenceController controller =
new BrightnessLevelPreferenceController(activity, null);
final ShadowActivity shadowActivity = shadowOf(activity);
when(mPreference.getKey()).thenReturn("brightness");
String preferenceKey = mContext.getString(R.string.preference_key_brightness_level);
when(mPreference.getKey()).thenReturn(preferenceKey);
controller.handlePreferenceTreeClick(mPreference);
final Intent intent = shadowActivity.getNextStartedActivity();
assertThat(intent.getIntExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE, 0))
.isEqualTo(SettingsTransitionHelper.TransitionType.TRANSITION_NONE);
}
}