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

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

Merge "Back up the smooth display setting" into udc-d1-dev am: 50f84a92

parents c239cef7 50f84a92
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -4696,22 +4696,16 @@ public final class Settings {
                "display_color_mode_vendor_hint";
        /**
         * The user selected min refresh rate in frames per second.
         *
         * If this isn't set, 0 will be used.
         * Whether or not the peak refresh rate should be forced. 0=no, 1=yes
         * @hide
         */
        @Readable
        public static final String MIN_REFRESH_RATE = "min_refresh_rate";
        public static final String FORCE_PEAK_REFRESH_RATE = "force_peak_refresh_rate";
        /**
         * The user selected peak refresh rate in frames per second.
         *
         * If this isn't set, the system falls back to a device specific default.
         * Whether or not the peak refresh rate should be used for some content. 0=no, 1=yes
         * @hide
         */
        @Readable
        public static final String PEAK_REFRESH_RATE = "peak_refresh_rate";
        public static final String SMOOTH_DISPLAY = "smooth_display";
        /**
         * The amount of time in milliseconds before the device goes to sleep or begins
+92 −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.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;
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -100,5 +100,6 @@ public class SystemSettings {
        Settings.System.CAMERA_FLASH_NOTIFICATION,
        Settings.System.SCREEN_FLASH_NOTIFICATION,
        Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
        Settings.System.SMOOTH_DISPLAY
    };
}
+1 −0
Original line number Diff line number Diff line
@@ -227,5 +227,6 @@ 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);
    }
}
+48 −6
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ 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;
@@ -3748,7 +3749,7 @@ public class SettingsProvider extends ContentProvider {
        }

        private final class UpgradeController {
            private static final int SETTINGS_VERSION = 218;
            private static final int SETTINGS_VERSION = 219;

            private final int mUserId;

@@ -5732,8 +5733,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,6 +5841,47 @@ 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);

                    currentVersion = 219;
                }

                // vXXX: Add new settings above this point.

                if (currentVersion != newVersion) {
Loading