Merge "feat(brightness suw): add brightness preferences in suw" into main
This commit is contained in:
@@ -23,6 +23,7 @@ import static com.android.settings.accessibility.AccessibilitySettingsForSetupWi
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -45,7 +46,10 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.display.AutoBrightnessPreferenceController;
|
||||
import com.android.settings.display.BrightnessLevelPreferenceController;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupdesign.GlifPreferenceLayout;
|
||||
@@ -88,7 +92,7 @@ public class AccessibilitySettingsForSetupWizardTest {
|
||||
private GlifPreferenceLayout mGlifLayoutView;
|
||||
@Mock
|
||||
private FooterBarMixin mFooterBarMixin;
|
||||
private AccessibilitySettingsForSetupWizard mFragment;
|
||||
private TestAccessibilitySettingsForSetupWizard mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -141,6 +145,19 @@ public class AccessibilitySettingsForSetupWizardTest {
|
||||
assertThat(mFragment.mSelectToSpeakPreference.getKey()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreferenceControllers_brightnessPreferencesControllersAreCreated() {
|
||||
mFragment.onAttach(mContext);
|
||||
|
||||
List<AbstractPreferenceController> controllers =
|
||||
mFragment.createPreferenceControllers(mContext);
|
||||
|
||||
assertTrue(controllers.stream().anyMatch(
|
||||
controller -> controller instanceof BrightnessLevelPreferenceController));
|
||||
assertTrue(controllers.stream().anyMatch(
|
||||
controller -> controller instanceof AutoBrightnessPreferenceController));
|
||||
}
|
||||
|
||||
private void addEnabledServiceInfo(ComponentName componentName, boolean isAccessibilityTool) {
|
||||
final AccessibilityServiceInfo a11yServiceInfo = mock(AccessibilityServiceInfo.class);
|
||||
when(a11yServiceInfo.getComponentName()).thenReturn(componentName);
|
||||
@@ -170,12 +187,14 @@ public class AccessibilitySettingsForSetupWizardTest {
|
||||
|
||||
private final Context mContext;
|
||||
private final PreferenceManager mPreferenceManager;
|
||||
final PreferenceScreen mPreferenceScreen;
|
||||
|
||||
TestAccessibilitySettingsForSetupWizard(Context context) {
|
||||
super();
|
||||
mContext = context;
|
||||
mPreferenceManager = new PreferenceManager(context);
|
||||
mPreferenceManager.setPreferences(mPreferenceManager.createPreferenceScreen(context));
|
||||
mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(context));
|
||||
mPreferenceManager.setPreferences(mPreferenceScreen);
|
||||
mDisplayMagnificationPreference = new Preference(context);
|
||||
mScreenReaderPreference = new RestrictedPreference(context);
|
||||
mSelectToSpeakPreference = new RestrictedPreference(context);
|
||||
|
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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 androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupdesign.GlifPreferenceLayout;
|
||||
|
||||
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();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private GlifPreferenceLayout mGlifLayoutView;
|
||||
@Mock
|
||||
private FooterBarMixin mFooterBarMixin;
|
||||
private AutoBrightnessPreferenceFragmentForSetupWizard mFragment;
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHeaderText_onViewCreated_verifyAction() {
|
||||
final String title = "title";
|
||||
doReturn(title).when(mContext).getString(R.string.auto_brightness_title);
|
||||
|
||||
mFragment.onViewCreated(mGlifLayoutView, null);
|
||||
|
||||
verify(mGlifLayoutView).setHeaderText(title);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_returnsCorrectCategory() {
|
||||
assertThat(mFragment.getMetricsCategory()).isEqualTo(
|
||||
SettingsEnums.SUW_ACCESSIBILITY_AUTO_BRIGHTNESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onViewCreated_verifyAction() {
|
||||
mFragment.onViewCreated(mGlifLayoutView, null);
|
||||
|
||||
verify(mFooterBarMixin).setPrimaryButton(any());
|
||||
}
|
||||
}
|
@@ -21,18 +21,24 @@ import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.Flags;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@@ -44,6 +50,9 @@ import org.robolectric.annotation.Config;
|
||||
@Config(shadows = {SettingsShadowResources.class})
|
||||
public class AutoBrightnessPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private static final String PREFERENCE_KEY = "auto_brightness";
|
||||
|
||||
private Context mContext;
|
||||
@@ -121,13 +130,34 @@ public class AutoBrightnessPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_configTrueSet_shouldReturnAvailableUnsearchable() {
|
||||
public void getAvailabilityStatusNotInSUW_configTrueSet_shouldReturnAvailableUnsearchable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available, true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
|
||||
public void getAvailabilityStatusInSUW_configTrueAndFlagOn_shouldReturnAvailableUnsearchable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available, true);
|
||||
mController.setInSetupWizard(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
|
||||
public void
|
||||
getAvailabilityStatusInSUW_configTrueAndFlagOff_shouldReturnConditionallyUnavailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available, true);
|
||||
mController.setInSetupWizard(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_configFalseSet_shouldReturnUnsupportedOnDevice() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
|
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -228,6 +228,8 @@ public class BatteryTestUtils {
|
||||
|
||||
/** Create a power anomaly event proto of adaptive brightness. */
|
||||
public static PowerAnomalyEvent createAdaptiveBrightnessAnomalyEvent(boolean changeSettings) {
|
||||
// TODO: migrate "auto_brightness_entry" to use R.string.preference_key_auto_brightness
|
||||
// if we can access the Context here. (b/338314718)
|
||||
WarningBannerInfo.Builder warningBannerInfoBuilder =
|
||||
WarningBannerInfo.newBuilder()
|
||||
.setMainButtonDestination(DisplaySettings.class.getName())
|
||||
|
Reference in New Issue
Block a user