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

Commit f1975a24 authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "Don't back up Smooth Display if feature flag off" into main

parents b8f85fbe fd8b8d07
Loading
Loading
Loading
Loading
+91 −79
Original line number Diff line number Diff line
@@ -19,6 +19,11 @@ package android.provider.settings.backup;
import android.compat.annotation.UnsupportedAppUsage;
import android.provider.Settings;

import com.android.server.display.feature.flags.Flags;

import java.util.ArrayList;
import java.util.List;

/** Information about the system settings to back up */
public class SystemSettings {

@@ -30,7 +35,10 @@ public class SystemSettings {
     *       make sure that they are ordered appropriately.
     */
    @UnsupportedAppUsage
    public static final String[] SETTINGS_TO_BACKUP = {
    public static final String[] SETTINGS_TO_BACKUP = getSettingsToBackUp();

    private static String[] getSettingsToBackUp() {
        List<String> settings = new ArrayList<>(List.of(
                Settings.System.STAY_ON_WHILE_PLUGGED_IN,   // moved to global
                Settings.System.WIFI_USE_STATIC_IP,
                Settings.System.WIFI_STATIC_IP,
@@ -102,10 +110,14 @@ 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,
                Settings.System.NOTIFICATION_COOLDOWN_ENABLED,
                Settings.System.NOTIFICATION_COOLDOWN_ALL,
        Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED,
    };
                Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED
        ));
        if (Flags.backUpSmoothDisplayAndForcePeakRefreshRate()) {
            settings.add(Settings.System.PEAK_REFRESH_RATE);
            settings.add(Settings.System.MIN_REFRESH_RATE);
        }
        return settings.toArray(new String[0]);
    }
}
+66 −54
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.provider.settings.backup.SystemSettings;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.server.display.feature.flags.Flags;

import org.junit.Test;
import org.junit.runner.RunWith;

@@ -53,59 +55,6 @@ public class SettingsBackupTest {
    public static final String HYBRID_SYSUI_BATTERY_WARNING_FLAGS =
            "hybrid_sysui_battery_warning_flags";

    /**
     * The following denylists contain settings that should *not* be backed up and restored to
     * another device.  As a general rule, anything that is not user configurable should be
     * denied (and conversely, things that *are* user configurable *should* be backed up)
     */
    private static final Set<String> BACKUP_DENY_LIST_SYSTEM_SETTINGS =
            newHashSet(
                    Settings.System.ADVANCED_SETTINGS, // candidate for backup?
                    Settings.System.ALARM_ALERT_CACHE, // internal cache
                    Settings.System.APPEND_FOR_LAST_AUDIBLE, // suffix deprecated since API 2
                    Settings.System.EGG_MODE, // I am the lolrus
                    Settings.System.END_BUTTON_BEHAVIOR, // bug?
                    Settings.System
                            .HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, // candidate for backup?
                    Settings.System.LOCKSCREEN_DISABLED, // ?
                    Settings.System.MEDIA_BUTTON_RECEIVER, // candidate for backup?
                    Settings.System.MUTE_STREAMS_AFFECTED, //  candidate for backup?
                    Settings.System.NOTIFICATION_SOUND_CACHE, // internal cache
                    Settings.System.POINTER_LOCATION, // backup candidate?
                    Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, // used for testing only
                    Settings.System.RINGTONE_CACHE, // internal cache
                    Settings.System.SCREEN_BRIGHTNESS, // removed in P
                    Settings.System.SETUP_WIZARD_HAS_RUN, // Only used by SuW
                    Settings.System.SHOW_GTALK_SERVICE_STATUS, // candidate for backup?
                    Settings.System.SHOW_TOUCHES,
                    Settings.System.SHOW_KEY_PRESSES,
                    Settings.System.SHOW_ROTARY_INPUT,
                    Settings.System.SIP_ADDRESS_ONLY, // value, not a setting
                    Settings.System.SIP_ALWAYS, // value, not a setting
                    Settings.System.SYSTEM_LOCALES, // bug?
                    Settings.System.USER_ROTATION, // backup candidate?
                    Settings.System.VIBRATE_IN_SILENT, // deprecated?
                    Settings.System.VOLUME_ACCESSIBILITY, // used internally, changing value will
                                                          // not change volume
                    Settings.System.VOLUME_ALARM, // deprecated since API 2?
                    Settings.System.VOLUME_ASSISTANT, // candidate for backup?
                    Settings.System.VOLUME_BLUETOOTH_SCO, // deprecated since API 2?
                    Settings.System.VOLUME_MASTER, // candidate for backup?
                    Settings.System.VOLUME_MUSIC, // deprecated since API 2?
                    Settings.System.VOLUME_NOTIFICATION, // deprecated since API 2?
                    Settings.System.VOLUME_RING, // deprecated since API 2?
                    Settings.System.VOLUME_SYSTEM, // deprecated since API 2?
                    Settings.System.VOLUME_VOICE, // deprecated since API 2?
                    Settings.System.WHEN_TO_MAKE_WIFI_CALLS, // bug?
                    Settings.System.WINDOW_ORIENTATION_LISTENER_LOG, // used for debugging only
                    Settings.System.SCREEN_BRIGHTNESS_FLOAT,
                    Settings.System.SCREEN_BRIGHTNESS_FOR_ALS,
                    Settings.System.WEAR_ACCESSIBILITY_GESTURE_ENABLED_DURING_OOBE,
                    Settings.System.WEAR_TTS_PREWARM_ENABLED,
                    Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ,
                    Settings.System.MULTI_AUDIO_FOCUS_ENABLED // form-factor/OEM specific
                    );

    private static final Set<String> BACKUP_DENY_LIST_GLOBAL_SETTINGS =
            newHashSet(
                    Settings.Global.ACTIVITY_MANAGER_CONSTANTS,
@@ -862,7 +811,7 @@ public class SettingsBackupTest {
        checkSettingsBackedUpOrDenied(
                getCandidateSettings(Settings.System.class),
                newHashSet(SystemSettings.SETTINGS_TO_BACKUP),
                BACKUP_DENY_LIST_SYSTEM_SETTINGS);
                getBackUpDenyListSystemSettings());
    }

    @Test
@@ -937,6 +886,69 @@ public class SettingsBackupTest {
        checkSettingsBackedUpOrDenied(allSettings, keys, BACKUP_DENY_LIST_SECURE_SETTINGS);
    }

    /**
     * The following denylists contain settings that should *not* be backed up and restored to
     * another device.  As a general rule, anything that is not user configurable should be
     * denied (and conversely, things that *are* user configurable *should* be backed up)
     */
    private static Set<String> getBackUpDenyListSystemSettings() {
        Set<String> settings =
                newHashSet(
                        Settings.System.ADVANCED_SETTINGS, // candidate for backup?
                        Settings.System.ALARM_ALERT_CACHE, // internal cache
                        Settings.System.APPEND_FOR_LAST_AUDIBLE, // suffix deprecated since API 2
                        Settings.System.EGG_MODE, // I am the lolrus
                        Settings.System.END_BUTTON_BEHAVIOR, // bug?
                        Settings.System
                                .HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY,
                        // candidate for backup?
                        Settings.System.LOCKSCREEN_DISABLED, // ?
                        Settings.System.MEDIA_BUTTON_RECEIVER, // candidate for backup?
                        Settings.System.MUTE_STREAMS_AFFECTED, //  candidate for backup?
                        Settings.System.NOTIFICATION_SOUND_CACHE, // internal cache
                        Settings.System.POINTER_LOCATION, // backup candidate?
                        Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING,
                        // used for testing only
                        Settings.System.RINGTONE_CACHE, // internal cache
                        Settings.System.SCREEN_BRIGHTNESS, // removed in P
                        Settings.System.SETUP_WIZARD_HAS_RUN, // Only used by SuW
                        Settings.System.SHOW_GTALK_SERVICE_STATUS, // candidate for backup?
                        Settings.System.SHOW_TOUCHES,
                        Settings.System.SHOW_KEY_PRESSES,
                        Settings.System.SHOW_ROTARY_INPUT,
                        Settings.System.SIP_ADDRESS_ONLY, // value, not a setting
                        Settings.System.SIP_ALWAYS, // value, not a setting
                        Settings.System.SYSTEM_LOCALES, // bug?
                        Settings.System.USER_ROTATION, // backup candidate?
                        Settings.System.VIBRATE_IN_SILENT, // deprecated?
                        Settings.System.VOLUME_ACCESSIBILITY,
                        // used internally, changing value will
                        // not change volume
                        Settings.System.VOLUME_ALARM, // deprecated since API 2?
                        Settings.System.VOLUME_ASSISTANT, // candidate for backup?
                        Settings.System.VOLUME_BLUETOOTH_SCO, // deprecated since API 2?
                        Settings.System.VOLUME_MASTER, // candidate for backup?
                        Settings.System.VOLUME_MUSIC, // deprecated since API 2?
                        Settings.System.VOLUME_NOTIFICATION, // deprecated since API 2?
                        Settings.System.VOLUME_RING, // deprecated since API 2?
                        Settings.System.VOLUME_SYSTEM, // deprecated since API 2?
                        Settings.System.VOLUME_VOICE, // deprecated since API 2?
                        Settings.System.WHEN_TO_MAKE_WIFI_CALLS, // bug?
                        Settings.System.WINDOW_ORIENTATION_LISTENER_LOG, // used for debugging only
                        Settings.System.SCREEN_BRIGHTNESS_FLOAT,
                        Settings.System.SCREEN_BRIGHTNESS_FOR_ALS,
                        Settings.System.WEAR_ACCESSIBILITY_GESTURE_ENABLED_DURING_OOBE,
                        Settings.System.WEAR_TTS_PREWARM_ENABLED,
                        Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ,
                        Settings.System.MULTI_AUDIO_FOCUS_ENABLED // form-factor/OEM specific
                );
        if (!Flags.backUpSmoothDisplayAndForcePeakRefreshRate()) {
            settings.add(Settings.System.MIN_REFRESH_RATE);
            settings.add(Settings.System.PEAK_REFRESH_RATE);
        }
        return settings;
    }

    private static void checkSettingsBackedUpOrDenied(
            Set<String> settings, Set<String> settingsToBackup, Set<String> denylist) {
        Set<String> settingsNotBackedUp = difference(settings, settingsToBackup);
+14 −4
Original line number Diff line number Diff line
@@ -970,9 +970,14 @@ public class DisplayModeDirector {

                if (!mIsBackUpSmoothDisplayAndForcePeakRefreshRateEnabled) {
                    // The flag had been turned off, we need to restore the original value
                    Settings.System.putFloatForUser(cr,
                            Settings.System.MIN_REFRESH_RATE, minRefreshRate, cr.getUserId());
                    Settings.System.putFloatForUser(cr, Settings.System.MIN_REFRESH_RATE,
                            highestRefreshRate, cr.getUserId());
                }
            } else if (mIsBackUpSmoothDisplayAndForcePeakRefreshRateEnabled
                    && Math.round(minRefreshRate) == Math.round(highestRefreshRate)) {
                // The flag has been turned on, we need to upgrade the setting
                Settings.System.putFloatForUser(cr, Settings.System.MIN_REFRESH_RATE,
                        Float.POSITIVE_INFINITY, cr.getUserId());
            }

            float peakRefreshRate = Settings.System.getFloatForUser(cr,
@@ -983,9 +988,14 @@ public class DisplayModeDirector {

                if (!mIsBackUpSmoothDisplayAndForcePeakRefreshRateEnabled) {
                    // The flag had been turned off, we need to restore the original value
                    Settings.System.putFloatForUser(cr,
                            Settings.System.PEAK_REFRESH_RATE, peakRefreshRate, cr.getUserId());
                }
                    Settings.System.putFloatForUser(cr, Settings.System.PEAK_REFRESH_RATE,
                            highestRefreshRate, cr.getUserId());
                }
            } else if (mIsBackUpSmoothDisplayAndForcePeakRefreshRateEnabled
                    && Math.round(peakRefreshRate) == Math.round(highestRefreshRate)) {
                // The flag has been turned on, we need to upgrade the setting
                Settings.System.putFloatForUser(cr, Settings.System.PEAK_REFRESH_RATE,
                        Float.POSITIVE_INFINITY, cr.getUserId());
            }

            updateRefreshRateSettingLocked(minRefreshRate, peakRefreshRate, mDefaultRefreshRate);