Loading core/java/android/provider/Settings.java +4 −2 Original line number Diff line number Diff line Loading @@ -4866,7 +4866,8 @@ public final class Settings { "display_color_mode_vendor_hint"; /** * The user selected min refresh rate in frames per second. * The user selected min refresh rate in frames per second. If infinite, the user wants * the highest possible refresh rate. * * If this isn't set, 0 will be used. * @hide Loading @@ -4875,7 +4876,8 @@ public final class Settings { public static final String MIN_REFRESH_RATE = "min_refresh_rate"; /** * The user selected peak refresh rate in frames per second. * The user selected peak refresh rate in frames per second. If infinite, the user wants * the highest possible refresh rate. * * If this isn't set, the system falls back to a device specific default. * @hide Loading core/java/com/android/internal/display/RefreshRateSettingsUtils.java 0 → 100644 +56 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.internal.display; import android.content.Context; import android.hardware.display.DisplayManager; import android.util.Log; import android.view.Display; /** * Constants and utility methods for refresh rate settings. */ public class RefreshRateSettingsUtils { private static final String TAG = "RefreshRateSettingsUtils"; public static final float DEFAULT_REFRESH_RATE = 60f; /** * Find the highest refresh rate among all the modes of the default display. * * @param context The context * @return The highest refresh rate */ public static float findHighestRefreshRateForDefaultDisplay(Context context) { final DisplayManager dm = context.getSystemService(DisplayManager.class); final Display display = dm.getDisplay(Display.DEFAULT_DISPLAY); if (display == null) { Log.w(TAG, "No valid default display device"); return DEFAULT_REFRESH_RATE; } float maxRefreshRate = DEFAULT_REFRESH_RATE; for (Display.Mode mode : display.getSupportedModes()) { if (mode.getRefreshRate() > maxRefreshRate) { maxRefreshRate = mode.getRefreshRate(); } } return maxRefreshRate; } } packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java +2 −0 Original line number Diff line number Diff line Loading @@ -101,5 +101,7 @@ public class SystemSettings { Settings.System.CAMERA_FLASH_NOTIFICATION, Settings.System.SCREEN_FLASH_NOTIFICATION, Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, Settings.System.PEAK_REFRESH_RATE, Settings.System.MIN_REFRESH_RATE, }; } packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java +3 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.provider.settings.validators.SettingsValidators.ANY_STRING import static android.provider.settings.validators.SettingsValidators.BOOLEAN_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NON_NEGATIVE_FLOAT_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NON_NEGATIVE_INTEGER_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.URI_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.VIBRATION_INTENSITY_VALIDATOR; Loading Loading @@ -236,5 +237,7 @@ public class SystemSettingsValidators { VALIDATORS.put(System.CAMERA_FLASH_NOTIFICATION, BOOLEAN_VALIDATOR); VALIDATORS.put(System.SCREEN_FLASH_NOTIFICATION, BOOLEAN_VALIDATOR); VALIDATORS.put(System.SCREEN_FLASH_NOTIFICATION_COLOR, ANY_INTEGER_VALIDATOR); VALIDATORS.put(System.PEAK_REFRESH_RATE, NON_NEGATIVE_FLOAT_VALIDATOR); VALIDATORS.put(System.MIN_REFRESH_RATE, NON_NEGATIVE_FLOAT_VALIDATOR); } } packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +52 −5 Original line number Diff line number Diff line Loading @@ -121,6 +121,7 @@ import android.util.proto.ProtoOutputStream; import com.android.internal.accessibility.util.AccessibilityUtils; import com.android.internal.annotations.GuardedBy; import com.android.internal.content.PackageMonitor; import com.android.internal.display.RefreshRateSettingsUtils; import com.android.internal.os.BackgroundThread; import com.android.internal.util.FrameworkStatsLog; import com.android.providers.settings.SettingsState.Setting; Loading Loading @@ -3878,7 +3879,7 @@ public class SettingsProvider extends ContentProvider { } private final class UpgradeController { private static final int SETTINGS_VERSION = 222; private static final int SETTINGS_VERSION = 223; private final int mUserId; Loading Loading @@ -5935,10 +5936,6 @@ public class SettingsProvider extends ContentProvider { if (currentVersion == 218) { // Version 219: Removed // TODO(b/211737588): Back up the Smooth Display setting // Future upgrades to the `peak_refresh_rate` and `min_refresh_rate` settings // should account for the database in a non-upgraded and upgraded (change id: // Ib2cb2dd100f06f5452083b7606109a486e795a0e) state. currentVersion = 219; } Loading Loading @@ -6004,6 +6001,56 @@ public class SettingsProvider extends ContentProvider { currentVersion = 222; } // Version 222: Set peak refresh rate and min refresh rate to infinity if it's // meant to be the highest possible refresh rate. This is needed so that we can // back up and restore those settings on other devices. Other devices might have // different highest possible refresh rates. if (currentVersion == 222) { final SettingsState systemSettings = getSystemSettingsLocked(userId); final Setting peakRefreshRateSetting = systemSettings.getSettingLocked(Settings.System.PEAK_REFRESH_RATE); final Setting minRefreshRateSetting = systemSettings.getSettingLocked(Settings.System.MIN_REFRESH_RATE); float highestRefreshRate = RefreshRateSettingsUtils .findHighestRefreshRateForDefaultDisplay(getContext()); if (!peakRefreshRateSetting.isNull()) { try { float peakRefreshRate = Float.parseFloat(peakRefreshRateSetting.getValue()); if (Math.round(peakRefreshRate) == Math.round(highestRefreshRate)) { systemSettings.insertSettingLocked( Settings.System.PEAK_REFRESH_RATE, String.valueOf(Float.POSITIVE_INFINITY), /* tag= */ null, /* makeDefault= */ false, SettingsState.SYSTEM_PACKAGE_NAME); } } catch (NumberFormatException e) { // Do nothing. Leave the value as is. } } if (!minRefreshRateSetting.isNull()) { try { float minRefreshRate = Float.parseFloat(minRefreshRateSetting.getValue()); if (Math.round(minRefreshRate) == Math.round(highestRefreshRate)) { systemSettings.insertSettingLocked( Settings.System.MIN_REFRESH_RATE, String.valueOf(Float.POSITIVE_INFINITY), /* tag= */ null, /* makeDefault= */ false, SettingsState.SYSTEM_PACKAGE_NAME); } } catch (NumberFormatException e) { // Do nothing. Leave the value as is. } } currentVersion = 223; } // vXXX: Add new settings above this point. if (currentVersion != newVersion) { Loading Loading
core/java/android/provider/Settings.java +4 −2 Original line number Diff line number Diff line Loading @@ -4866,7 +4866,8 @@ public final class Settings { "display_color_mode_vendor_hint"; /** * The user selected min refresh rate in frames per second. * The user selected min refresh rate in frames per second. If infinite, the user wants * the highest possible refresh rate. * * If this isn't set, 0 will be used. * @hide Loading @@ -4875,7 +4876,8 @@ public final class Settings { public static final String MIN_REFRESH_RATE = "min_refresh_rate"; /** * The user selected peak refresh rate in frames per second. * The user selected peak refresh rate in frames per second. If infinite, the user wants * the highest possible refresh rate. * * If this isn't set, the system falls back to a device specific default. * @hide Loading
core/java/com/android/internal/display/RefreshRateSettingsUtils.java 0 → 100644 +56 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.internal.display; import android.content.Context; import android.hardware.display.DisplayManager; import android.util.Log; import android.view.Display; /** * Constants and utility methods for refresh rate settings. */ public class RefreshRateSettingsUtils { private static final String TAG = "RefreshRateSettingsUtils"; public static final float DEFAULT_REFRESH_RATE = 60f; /** * Find the highest refresh rate among all the modes of the default display. * * @param context The context * @return The highest refresh rate */ public static float findHighestRefreshRateForDefaultDisplay(Context context) { final DisplayManager dm = context.getSystemService(DisplayManager.class); final Display display = dm.getDisplay(Display.DEFAULT_DISPLAY); if (display == null) { Log.w(TAG, "No valid default display device"); return DEFAULT_REFRESH_RATE; } float maxRefreshRate = DEFAULT_REFRESH_RATE; for (Display.Mode mode : display.getSupportedModes()) { if (mode.getRefreshRate() > maxRefreshRate) { maxRefreshRate = mode.getRefreshRate(); } } return maxRefreshRate; } }
packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java +2 −0 Original line number Diff line number Diff line Loading @@ -101,5 +101,7 @@ public class SystemSettings { Settings.System.CAMERA_FLASH_NOTIFICATION, Settings.System.SCREEN_FLASH_NOTIFICATION, Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, Settings.System.PEAK_REFRESH_RATE, Settings.System.MIN_REFRESH_RATE, }; }
packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java +3 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.provider.settings.validators.SettingsValidators.ANY_STRING import static android.provider.settings.validators.SettingsValidators.BOOLEAN_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.LENIENT_IP_ADDRESS_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NON_NEGATIVE_FLOAT_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NON_NEGATIVE_INTEGER_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.URI_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.VIBRATION_INTENSITY_VALIDATOR; Loading Loading @@ -236,5 +237,7 @@ public class SystemSettingsValidators { VALIDATORS.put(System.CAMERA_FLASH_NOTIFICATION, BOOLEAN_VALIDATOR); VALIDATORS.put(System.SCREEN_FLASH_NOTIFICATION, BOOLEAN_VALIDATOR); VALIDATORS.put(System.SCREEN_FLASH_NOTIFICATION_COLOR, ANY_INTEGER_VALIDATOR); VALIDATORS.put(System.PEAK_REFRESH_RATE, NON_NEGATIVE_FLOAT_VALIDATOR); VALIDATORS.put(System.MIN_REFRESH_RATE, NON_NEGATIVE_FLOAT_VALIDATOR); } }
packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +52 −5 Original line number Diff line number Diff line Loading @@ -121,6 +121,7 @@ import android.util.proto.ProtoOutputStream; import com.android.internal.accessibility.util.AccessibilityUtils; import com.android.internal.annotations.GuardedBy; import com.android.internal.content.PackageMonitor; import com.android.internal.display.RefreshRateSettingsUtils; import com.android.internal.os.BackgroundThread; import com.android.internal.util.FrameworkStatsLog; import com.android.providers.settings.SettingsState.Setting; Loading Loading @@ -3878,7 +3879,7 @@ public class SettingsProvider extends ContentProvider { } private final class UpgradeController { private static final int SETTINGS_VERSION = 222; private static final int SETTINGS_VERSION = 223; private final int mUserId; Loading Loading @@ -5935,10 +5936,6 @@ public class SettingsProvider extends ContentProvider { if (currentVersion == 218) { // Version 219: Removed // TODO(b/211737588): Back up the Smooth Display setting // Future upgrades to the `peak_refresh_rate` and `min_refresh_rate` settings // should account for the database in a non-upgraded and upgraded (change id: // Ib2cb2dd100f06f5452083b7606109a486e795a0e) state. currentVersion = 219; } Loading Loading @@ -6004,6 +6001,56 @@ public class SettingsProvider extends ContentProvider { currentVersion = 222; } // Version 222: Set peak refresh rate and min refresh rate to infinity if it's // meant to be the highest possible refresh rate. This is needed so that we can // back up and restore those settings on other devices. Other devices might have // different highest possible refresh rates. if (currentVersion == 222) { final SettingsState systemSettings = getSystemSettingsLocked(userId); final Setting peakRefreshRateSetting = systemSettings.getSettingLocked(Settings.System.PEAK_REFRESH_RATE); final Setting minRefreshRateSetting = systemSettings.getSettingLocked(Settings.System.MIN_REFRESH_RATE); float highestRefreshRate = RefreshRateSettingsUtils .findHighestRefreshRateForDefaultDisplay(getContext()); if (!peakRefreshRateSetting.isNull()) { try { float peakRefreshRate = Float.parseFloat(peakRefreshRateSetting.getValue()); if (Math.round(peakRefreshRate) == Math.round(highestRefreshRate)) { systemSettings.insertSettingLocked( Settings.System.PEAK_REFRESH_RATE, String.valueOf(Float.POSITIVE_INFINITY), /* tag= */ null, /* makeDefault= */ false, SettingsState.SYSTEM_PACKAGE_NAME); } } catch (NumberFormatException e) { // Do nothing. Leave the value as is. } } if (!minRefreshRateSetting.isNull()) { try { float minRefreshRate = Float.parseFloat(minRefreshRateSetting.getValue()); if (Math.round(minRefreshRate) == Math.round(highestRefreshRate)) { systemSettings.insertSettingLocked( Settings.System.MIN_REFRESH_RATE, String.valueOf(Float.POSITIVE_INFINITY), /* tag= */ null, /* makeDefault= */ false, SettingsState.SYSTEM_PACKAGE_NAME); } } catch (NumberFormatException e) { // Do nothing. Leave the value as is. } } currentVersion = 223; } // vXXX: Add new settings above this point. if (currentVersion != newVersion) { Loading