Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8a66fa0 authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Automerger Merge Worker
Browse files

Merge "Revert "Back up the smooth display setting"" into udc-d1-dev am: 561e58b0

parents 92368d41 561e58b0
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -4677,16 +4677,22 @@ public final class Settings {
                "display_color_mode_vendor_hint";
        /**
         * Whether or not the peak refresh rate should be forced. 0=no, 1=yes
         * The user selected min refresh rate in frames per second.
         *
         * If this isn't set, 0 will be used.
         * @hide
         */
        public static final String FORCE_PEAK_REFRESH_RATE = "force_peak_refresh_rate";
        @Readable
        public static final String MIN_REFRESH_RATE = "min_refresh_rate";
        /**
         * Whether or not the peak refresh rate should be used for some content. 0=no, 1=yes
         * The user selected peak refresh rate in frames per second.
         *
         * If this isn't set, the system falls back to a device specific default.
         * @hide
         */
        public static final String SMOOTH_DISPLAY = "smooth_display";
        @Readable
        public static final String PEAK_REFRESH_RATE = "peak_refresh_rate";
        /**
         * The amount of time in milliseconds before the device goes to sleep or begins
+0 −92
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.ContentResolver;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.provider.Settings;
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 (Math.round(mode.getRefreshRate()) > maxRefreshRate) {
                maxRefreshRate = mode.getRefreshRate();
            }
        }
        return maxRefreshRate;
    }

    /**
     * Get the min refresh rate which is determined by
     * {@link Settings.System.FORCE_PEAK_REFRESH_RATE}.
     * @param context The context
     * @return The min refresh rate
     */
    public static float getMinRefreshRate(Context context) {
        final ContentResolver cr = context.getContentResolver();
        int forcePeakRefreshRateSetting = Settings.System.getIntForUser(cr,
                Settings.System.FORCE_PEAK_REFRESH_RATE, -1, cr.getUserId());
        return forcePeakRefreshRateSetting == 1
                ? findHighestRefreshRateForDefaultDisplay(context)
                : 0;
    }

    /**
     * Get the peak refresh rate which is determined by {@link Settings.System.SMOOTH_DISPLAY}.
     * @param context The context
     * @param defaultPeakRefreshRate The refresh rate to return if the setting doesn't have a value
     * @return The peak refresh rate
     */
    public static float getPeakRefreshRate(Context context, float defaultPeakRefreshRate) {
        final ContentResolver cr = context.getContentResolver();
        int smoothDisplaySetting = Settings.System.getIntForUser(cr,
                Settings.System.SMOOTH_DISPLAY, -1, cr.getUserId());
        switch (smoothDisplaySetting) {
            case 0:
                return DEFAULT_REFRESH_RATE;
            case 1:
                return findHighestRefreshRateForDefaultDisplay(context);
            default:
                return defaultPeakRefreshRate;
        }
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -100,6 +100,5 @@ public class SystemSettings {
        Settings.System.CAMERA_FLASH_NOTIFICATION,
        Settings.System.SCREEN_FLASH_NOTIFICATION,
        Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
        Settings.System.SMOOTH_DISPLAY
    };
}
+0 −1
Original line number Diff line number Diff line
@@ -226,6 +226,5 @@ 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.SMOOTH_DISPLAY, BOOLEAN_VALIDATOR);
    }
}
+10 −43
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OV

import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
import static com.android.internal.accessibility.util.AccessibilityUtils.ACCESSIBILITY_MENU_IN_SYSTEM;
import static com.android.internal.display.RefreshRateSettingsUtils.DEFAULT_REFRESH_RATE;
import static com.android.providers.settings.SettingsState.FALLBACK_FILE_SUFFIX;
import static com.android.providers.settings.SettingsState.getTypeFromKey;
import static com.android.providers.settings.SettingsState.getUserIdFromKey;
@@ -5732,8 +5731,8 @@ public class SettingsProvider extends ContentProvider {
                    final Setting currentSetting = secureSettings
                            .getSettingLocked(Settings.Secure.CREDENTIAL_SERVICE);
                    if (currentSetting.isNull()) {
                        final int resourceId = com.android.internal.R.array
                                .config_defaultCredentialProviderService;
                        final int resourceId =
                            com.android.internal.R.array.config_defaultCredentialProviderService;
                        final Resources resources = getContext().getResources();
                        // If the config has not be defined we might get an exception.
                        final List<String> providers = new ArrayList<>();
@@ -5840,44 +5839,12 @@ public class SettingsProvider extends ContentProvider {
                    currentVersion = 218;
                }

                // v218: Convert Smooth Display and Force Peak Refresh Rate to a boolean
                if (currentVersion == 218) {
                    final String peakRefreshRateSettingName = "peak_refresh_rate";
                    final String minRefreshRateSettingName = "min_refresh_rate";

                    final SettingsState systemSettings = getSystemSettingsLocked(userId);
                    final Setting peakRefreshRateSetting =
                            systemSettings.getSettingLocked(peakRefreshRateSettingName);
                    final Setting minRefreshRateSetting =
                            systemSettings.getSettingLocked(minRefreshRateSettingName);

                    float peakRefreshRate = DEFAULT_REFRESH_RATE;
                    float minRefreshRate = 0;
                    try {
                        if (!peakRefreshRateSetting.isNull()) {
                            peakRefreshRate = Float.parseFloat(peakRefreshRateSetting.getValue());
                        }
                    } catch (NumberFormatException e) {
                        // Do nothing. Overwrite with default value.
                    }
                    try {
                        if (!minRefreshRateSetting.isNull()) {
                            minRefreshRate = Float.parseFloat(minRefreshRateSetting.getValue());
                        }
                    } catch (NumberFormatException e) {
                        // Do nothing. Overwrite with default value.
                    }

                    systemSettings.deleteSettingLocked(peakRefreshRateSettingName);
                    systemSettings.deleteSettingLocked(minRefreshRateSettingName);

                    systemSettings.insertSettingLocked(Settings.System.SMOOTH_DISPLAY,
                            peakRefreshRate > DEFAULT_REFRESH_RATE ? "1" : "0", /* tag= */ null,
                            /* makeDefault= */ false, SettingsState.SYSTEM_PACKAGE_NAME);
                    systemSettings.insertSettingLocked(Settings.System.FORCE_PEAK_REFRESH_RATE,
                            minRefreshRate > 0 ? "1" : "0", /* tag= */ null,
                            /* makeDefault= */ false, SettingsState.SYSTEM_PACKAGE_NAME);

                    // 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