- Convert "Smooth display" and "Force peak refresh rate" to a boolean. If they are a boolean, they can be backed up without being device-specific. - Back up "Smooth display" and add a validator - Upgrade the settings in SettingsProvider - Create a utils class - RefreshRateSettingsUtils Bug: 211737588 Test: atest DisplayModeDirectorTest Test: atest ForcePeakRefreshRatePreferenceControllerTest Test: atest PeakRefreshRatePreferenceControllerTest Test: atest SettingsBackupTest Test: atest SettingsProviderTest Change-Id: Ib2cb2dd100f06f5452083b7606109a486e795a0e
121 lines
3.8 KiB
Java
121 lines
3.8 KiB
Java
/*
|
|
* Copyright (C) 2020 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.display;
|
|
|
|
import static com.android.internal.display.RefreshRateSettingsUtils.DEFAULT_REFRESH_RATE;
|
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
|
|
import android.content.Context;
|
|
import android.provider.Settings;
|
|
|
|
import androidx.preference.SwitchPreference;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.robolectric.RobolectricTestRunner;
|
|
import org.robolectric.RuntimeEnvironment;
|
|
import org.robolectric.annotation.Config;
|
|
|
|
@RunWith(RobolectricTestRunner.class)
|
|
public class PeakRefreshRatePreferenceControllerTest {
|
|
|
|
private Context mContext;
|
|
private PeakRefreshRatePreferenceController mController;
|
|
private SwitchPreference mPreference;
|
|
|
|
@Before
|
|
public void setUp() {
|
|
mContext = RuntimeEnvironment.application;
|
|
mController = new PeakRefreshRatePreferenceController(mContext, "key");
|
|
mPreference = new SwitchPreference(RuntimeEnvironment.application);
|
|
}
|
|
|
|
@Test
|
|
@Config(qualifiers = "mcc999")
|
|
public void getAvailabilityStatus_withConfigNoShow_returnUnsupported() {
|
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
|
}
|
|
|
|
@Test
|
|
public void getAvailabilityStatus_refreshRateLargerThanDefault_returnAvailable() {
|
|
mController.mPeakRefreshRate = DEFAULT_REFRESH_RATE + 1;
|
|
|
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
|
}
|
|
|
|
@Test
|
|
public void getAvailabilityStatus_refreshRateEqualToDefault_returnUnsupported() {
|
|
mController.mPeakRefreshRate = DEFAULT_REFRESH_RATE;
|
|
|
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
|
}
|
|
|
|
@Test
|
|
public void setChecked_enableSmoothDisplay() {
|
|
mController.setChecked(true);
|
|
|
|
assertThat(Settings.System.getInt(mContext.getContentResolver(),
|
|
Settings.System.SMOOTH_DISPLAY, -1))
|
|
.isEqualTo(1);
|
|
}
|
|
|
|
@Test
|
|
public void setChecked_disableSmoothDisplay() {
|
|
mController.setChecked(false);
|
|
|
|
assertThat(Settings.System.getInt(mContext.getContentResolver(),
|
|
Settings.System.SMOOTH_DISPLAY, -1))
|
|
.isEqualTo(0);
|
|
}
|
|
|
|
@Test
|
|
public void isChecked_enableSmoothDisplay_returnTrue() {
|
|
enableSmoothDisplayPreference();
|
|
|
|
assertThat(mController.isChecked()).isTrue();
|
|
}
|
|
|
|
@Test
|
|
public void isChecked_disableSmoothDisplay_returnFalse() {
|
|
disableSmoothDisplayPreference();
|
|
|
|
assertThat(mController.isChecked()).isFalse();
|
|
}
|
|
|
|
private void enableSmoothDisplayPreference() {
|
|
mController.mPeakRefreshRate = 88f;
|
|
|
|
Settings.System.putInt(
|
|
mContext.getContentResolver(),
|
|
Settings.System.SMOOTH_DISPLAY,
|
|
1);
|
|
}
|
|
|
|
private void disableSmoothDisplayPreference() {
|
|
mController.mPeakRefreshRate = 88f;
|
|
|
|
Settings.System.putInt(
|
|
mContext.getContentResolver(),
|
|
Settings.System.SMOOTH_DISPLAY,
|
|
0);
|
|
}
|
|
}
|