Files
app_Settings/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java
Piotr Wilczyński 96343a9eff Refresh rate preference controllers aware of multiple displays
Set mPeakRefreshRate in the preference controllers to the highest refresh rate among all the modes of all the displays. It'll then be used to determine two things:
- if the setting is available
- the summary of the setting

This should only be done if the back up smooth display feature flag is enabled. If it's disabled, mPeakRefreshRate is passed to DisplayModeDirector and used for the votes. If the highest refresh rate of one display is 120 and that of the other is 130, we shouldn't set the vote to 130 for both displays. With the flag enabled, DisplayModeDirector figures out the highest refresh rate for each display.

Bug: 310238382
Test: atest PeakRefreshRatePreferenceControllerTest
Test: atest ForcePeakRefreshRatePreferenceControllerTest
Test: atest RefreshRateSettingsUtilsTest
Change-Id: I369927ba22df70958178505d8fc7c5747aaa8fdd
2024-02-23 18:01:22 +00:00

117 lines
4.2 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.development;
import static com.android.internal.display.RefreshRateSettingsUtils.DEFAULT_REFRESH_RATE;
import static com.android.internal.display.RefreshRateSettingsUtils.findHighestRefreshRateAmongAllDisplays;
import static com.android.internal.display.RefreshRateSettingsUtils.findHighestRefreshRateForDefaultDisplay;
import android.content.Context;
import android.provider.Settings;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.TwoStatePreference;
import com.android.server.display.feature.flags.Flags;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
public class ForcePeakRefreshRatePreferenceController extends DeveloperOptionsPreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
@VisibleForTesting
static float NO_CONFIG = 0f;
@VisibleForTesting
float mPeakRefreshRate;
private static final String TAG = "ForcePeakRefreshRateCtr";
private static final String PREFERENCE_KEY = "pref_key_peak_refresh_rate";
public ForcePeakRefreshRatePreferenceController(Context context) {
super(context);
mPeakRefreshRate = Flags.backUpSmoothDisplayAndForcePeakRefreshRate()
? findHighestRefreshRateAmongAllDisplays(context)
: findHighestRefreshRateForDefaultDisplay(context);
Log.d(TAG, "DEFAULT_REFRESH_RATE : " + DEFAULT_REFRESH_RATE
+ " mPeakRefreshRate : " + mPeakRefreshRate);
}
@Override
public String getPreferenceKey() {
return PREFERENCE_KEY;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean isEnabled = (Boolean) newValue;
forcePeakRefreshRate(isEnabled);
return true;
}
@Override
public void updateState(Preference preference) {
((TwoStatePreference) mPreference).setChecked(isForcePeakRefreshRateEnabled());
}
@Override
public boolean isAvailable() {
if (mContext.getResources().getBoolean(R.bool.config_show_smooth_display)) {
return mPeakRefreshRate > DEFAULT_REFRESH_RATE;
} else {
return false;
}
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled();
Settings.System.putFloat(mContext.getContentResolver(),
Settings.System.MIN_REFRESH_RATE, NO_CONFIG);
((TwoStatePreference) mPreference).setChecked(false);
}
@VisibleForTesting
void forcePeakRefreshRate(boolean enable) {
final float valueIfEnabled = Flags.backUpSmoothDisplayAndForcePeakRefreshRate()
? Float.POSITIVE_INFINITY : mPeakRefreshRate;
final float peakRefreshRate = enable ? valueIfEnabled : NO_CONFIG;
Settings.System.putFloat(mContext.getContentResolver(),
Settings.System.MIN_REFRESH_RATE, peakRefreshRate);
}
boolean isForcePeakRefreshRateEnabled() {
final float peakRefreshRate = Settings.System.getFloat(mContext.getContentResolver(),
Settings.System.MIN_REFRESH_RATE, NO_CONFIG);
return Math.round(peakRefreshRate) == Math.round(mPeakRefreshRate)
|| Float.isInfinite(peakRefreshRate);
}
}