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

Commit efe48f78 authored by dshivangi's avatar dshivangi Committed by Shivangi Dubey
Browse files

Add 'Stay unlocked on fold' toogle to settings

Added 'Stay unlocked on fold' toogle to display settings. Enabling this
setting will allow user to keep their device awake after the fold the
device.

Test: atest StayAwakeOnFoldPreferenceControllerTest LogicalDisplayMapperTest
Test: manual
  Built and flashed foldable device and manually tested by
    1. unfolded device -> enable setting -> folded device
    2. unfolded device -> disabled setting -> folded devices
  Built and flashed non-foldable device and manually tested by
    1. Went to Settings -> display -> the toogle setting is not visible
Bug: 274447767
Change-Id: I09915082b759c235811fc143184a19e2b84f1c8e
parent 43d8d44e
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -4698,6 +4698,15 @@ public final class Settings {
        @Readable
        @Readable
        public static final String PEAK_REFRESH_RATE = "peak_refresh_rate";
        public static final String PEAK_REFRESH_RATE = "peak_refresh_rate";
        /**
         * Control whether to stay awake on fold
         *
         * If this isn't set, the system falls back to a device specific default.
         * @hide
         */
        @Readable
        public static final String STAY_AWAKE_ON_FOLD = "stay_awake_on_fold";
        /**
        /**
         * The amount of time in milliseconds before the device goes to sleep or begins
         * The amount of time in milliseconds before the device goes to sleep or begins
         * to dream after a period of inactivity.  This value is also known as the
         * to dream after a period of inactivity.  This value is also known as the
+1 −0
Original line number Original line Diff line number Diff line
@@ -61,6 +61,7 @@ public class SystemSettings {
        Settings.System.TTY_MODE,
        Settings.System.TTY_MODE,
        Settings.System.MASTER_MONO,
        Settings.System.MASTER_MONO,
        Settings.System.MASTER_BALANCE,
        Settings.System.MASTER_BALANCE,
        Settings.System.STAY_AWAKE_ON_FOLD,
        Settings.System.SOUND_EFFECTS_ENABLED,
        Settings.System.SOUND_EFFECTS_ENABLED,
        Settings.System.HAPTIC_FEEDBACK_ENABLED,
        Settings.System.HAPTIC_FEEDBACK_ENABLED,
        Settings.System.POWER_SOUNDS_ENABLED,       // moved to global
        Settings.System.POWER_SOUNDS_ENABLED,       // moved to global
+1 −0
Original line number Original line Diff line number Diff line
@@ -218,6 +218,7 @@ public class SystemSettingsValidators {
        VALIDATORS.put(System.WIFI_STATIC_DNS1, LENIENT_IP_ADDRESS_VALIDATOR);
        VALIDATORS.put(System.WIFI_STATIC_DNS1, LENIENT_IP_ADDRESS_VALIDATOR);
        VALIDATORS.put(System.WIFI_STATIC_DNS2, LENIENT_IP_ADDRESS_VALIDATOR);
        VALIDATORS.put(System.WIFI_STATIC_DNS2, LENIENT_IP_ADDRESS_VALIDATOR);
        VALIDATORS.put(System.SHOW_BATTERY_PERCENT, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.SHOW_BATTERY_PERCENT, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.STAY_AWAKE_ON_FOLD, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.NOTIFICATION_LIGHT_PULSE, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.NOTIFICATION_LIGHT_PULSE, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.WEAR_ACCESSIBILITY_GESTURE_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.WEAR_ACCESSIBILITY_GESTURE_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.CLOCKWORK_BLUETOOTH_SETTINGS_PREF, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.CLOCKWORK_BLUETOOTH_SETTINGS_PREF, BOOLEAN_VALIDATOR);
+3 −1
Original line number Original line Diff line number Diff line
@@ -156,6 +156,7 @@ import com.android.server.display.layout.Layout;
import com.android.server.display.mode.DisplayModeDirector;
import com.android.server.display.mode.DisplayModeDirector;
import com.android.server.display.utils.SensorUtils;
import com.android.server.display.utils.SensorUtils;
import com.android.server.input.InputManagerInternal;
import com.android.server.input.InputManagerInternal;
import com.android.server.utils.FoldSettingWrapper;
import com.android.server.wm.SurfaceAnimationThread;
import com.android.server.wm.SurfaceAnimationThread;
import com.android.server.wm.WindowManagerInternal;
import com.android.server.wm.WindowManagerInternal;


@@ -539,7 +540,8 @@ public final class DisplayManagerService extends SystemService {
        mUiHandler = UiThread.getHandler();
        mUiHandler = UiThread.getHandler();
        mDisplayDeviceRepo = new DisplayDeviceRepository(mSyncRoot, mPersistentDataStore);
        mDisplayDeviceRepo = new DisplayDeviceRepository(mSyncRoot, mPersistentDataStore);
        mLogicalDisplayMapper = new LogicalDisplayMapper(mContext, mDisplayDeviceRepo,
        mLogicalDisplayMapper = new LogicalDisplayMapper(mContext, mDisplayDeviceRepo,
                new LogicalDisplayListener(), mSyncRoot, mHandler);
                new LogicalDisplayListener(), mSyncRoot, mHandler,
                new FoldSettingWrapper(mContext.getContentResolver()));
        mDisplayModeDirector = new DisplayModeDirector(context, mHandler);
        mDisplayModeDirector = new DisplayModeDirector(context, mHandler);
        mBrightnessSynchronizer = new BrightnessSynchronizer(mContext);
        mBrightnessSynchronizer = new BrightnessSynchronizer(mContext);
        Resources resources = mContext.getResources();
        Resources resources = mContext.getResources();
+12 −7
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import android.view.DisplayInfo;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.display.layout.DisplayIdProducer;
import com.android.server.display.layout.DisplayIdProducer;
import com.android.server.display.layout.Layout;
import com.android.server.display.layout.Layout;
import com.android.server.utils.FoldSettingWrapper;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Arrays;
@@ -142,6 +143,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
    private final Listener mListener;
    private final Listener mListener;
    private final DisplayManagerService.SyncRoot mSyncRoot;
    private final DisplayManagerService.SyncRoot mSyncRoot;
    private final LogicalDisplayMapperHandler mHandler;
    private final LogicalDisplayMapperHandler mHandler;
    private final FoldSettingWrapper mFoldSettingWrapper;
    private final PowerManager mPowerManager;
    private final PowerManager mPowerManager;


    /**
    /**
@@ -189,21 +191,23 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {


    LogicalDisplayMapper(@NonNull Context context, @NonNull DisplayDeviceRepository repo,
    LogicalDisplayMapper(@NonNull Context context, @NonNull DisplayDeviceRepository repo,
            @NonNull Listener listener, @NonNull DisplayManagerService.SyncRoot syncRoot,
            @NonNull Listener listener, @NonNull DisplayManagerService.SyncRoot syncRoot,
            @NonNull Handler handler) {
            @NonNull Handler handler, FoldSettingWrapper foldSettingWrapper) {
        this(context, repo, listener, syncRoot, handler,
        this(context, repo, listener, syncRoot, handler,
                new DeviceStateToLayoutMap((isDefault) -> isDefault ? DEFAULT_DISPLAY
                new DeviceStateToLayoutMap((isDefault) -> isDefault ? DEFAULT_DISPLAY
                        : sNextNonDefaultDisplayId++));
                        : sNextNonDefaultDisplayId++), foldSettingWrapper);
    }
    }


    LogicalDisplayMapper(@NonNull Context context, @NonNull DisplayDeviceRepository repo,
    LogicalDisplayMapper(@NonNull Context context, @NonNull DisplayDeviceRepository repo,
            @NonNull Listener listener, @NonNull DisplayManagerService.SyncRoot syncRoot,
            @NonNull Listener listener, @NonNull DisplayManagerService.SyncRoot syncRoot,
            @NonNull Handler handler, @NonNull DeviceStateToLayoutMap deviceStateToLayoutMap) {
            @NonNull Handler handler, @NonNull DeviceStateToLayoutMap deviceStateToLayoutMap,
            FoldSettingWrapper foldSettingWrapper) {
        mSyncRoot = syncRoot;
        mSyncRoot = syncRoot;
        mPowerManager = context.getSystemService(PowerManager.class);
        mPowerManager = context.getSystemService(PowerManager.class);
        mInteractive = mPowerManager.isInteractive();
        mInteractive = mPowerManager.isInteractive();
        mHandler = new LogicalDisplayMapperHandler(handler.getLooper());
        mHandler = new LogicalDisplayMapperHandler(handler.getLooper());
        mDisplayDeviceRepo = repo;
        mDisplayDeviceRepo = repo;
        mListener = listener;
        mListener = listener;
        mFoldSettingWrapper = foldSettingWrapper;
        mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
        mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
        mSupportsConcurrentInternalDisplays = context.getResources().getBoolean(
        mSupportsConcurrentInternalDisplays = context.getResources().getBoolean(
                com.android.internal.R.bool.config_supportsConcurrentInternalDisplays);
                com.android.internal.R.bool.config_supportsConcurrentInternalDisplays);
@@ -531,9 +535,10 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
     * Returns if the device should be put to sleep or not.
     * Returns if the device should be put to sleep or not.
     *
     *
     * Includes a check to verify that the device state that we are moving to, {@code pendingState},
     * Includes a check to verify that the device state that we are moving to, {@code pendingState},
     * is the same as the physical state of the device, {@code baseState}. Different values for
     * is the same as the physical state of the device, {@code baseState}. Also if the
     * these parameters indicate a device state override is active, and we shouldn't put the device
     * 'Stay Awake On Fold' is not enabled. Different values for these parameters indicate a device
     * to sleep to provide a better user experience.
     * state override is active, and we shouldn't put the device to sleep to provide a better user
     * experience.
     *
     *
     * @param pendingState device state we are moving to
     * @param pendingState device state we are moving to
     * @param currentState device state we are currently in
     * @param currentState device state we are currently in
@@ -551,7 +556,7 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                && mDeviceStatesOnWhichToSleep.get(pendingState)
                && mDeviceStatesOnWhichToSleep.get(pendingState)
                && !mDeviceStatesOnWhichToSleep.get(currentState)
                && !mDeviceStatesOnWhichToSleep.get(currentState)
                && !isOverrideActive
                && !isOverrideActive
                && isInteractive && isBootCompleted;
                && isInteractive && isBootCompleted && !mFoldSettingWrapper.shouldStayAwakeOnFold();
    }
    }


    private boolean areAllTransitioningDisplaysOffLocked() {
    private boolean areAllTransitioningDisplaysOffLocked() {
Loading