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

Commit 39aa2a5c authored by Lucas Silva's avatar Lucas Silva
Browse files

Allow dream to timeout in preview mode

If a dream is started in preview mode, it never times out currently due
to the wakelock which is acquired by the KEEP_SCREEN_ON flag. This
change avoids setting that flag on the dream window when in preview
mode, which allows dream previews to timeout. If dreams are enabled, the
dream will be restarted in non-preview mode after the timeout. Otherwise
the screen will turn off.

Fixes: 271872132
Test: flashed device and verified timeout occurs in preview mode and
dreams remain bright and do not timeout in regular mode.
Flag: NONE

Change-Id: Id47408d714706a426e8eec4ddfeb6d3d7e481335
parent db6f702b
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -263,6 +263,7 @@ public class DreamService extends Service implements Window.Callback {
    private boolean mCanDoze;
    private boolean mDozing;
    private boolean mWindowless;
    private boolean mPreviewMode;
    private int mDozeScreenState = Display.STATE_UNKNOWN;
    private int mDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;

@@ -647,12 +648,13 @@ public class DreamService extends Service implements Window.Callback {
    }

    /**
     * Marks this dream as keeping the screen bright while dreaming.
     * Marks this dream as keeping the screen bright while dreaming. In preview mode, the screen
     * is always allowed to dim and overrides the value specified here.
     *
     * @param screenBright True to keep the screen bright while dreaming.
     */
    public void setScreenBright(boolean screenBright) {
        if (mScreenBright != screenBright) {
        if (mScreenBright != screenBright && !mPreviewMode) {
            mScreenBright = screenBright;
            int flag = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
            applyWindowFlags(mScreenBright ? flag : 0, flag);
@@ -661,7 +663,7 @@ public class DreamService extends Service implements Window.Callback {

    /**
     * Returns whether this dream keeps the screen bright while dreaming.
     * Defaults to false, allowing the screen to dim if necessary.
     * Defaults to true, preventing the screen from dimming.
     *
     * @see #setScreenBright(boolean)
     */
@@ -1280,6 +1282,11 @@ public class DreamService extends Service implements Window.Callback {

        mDreamToken = dreamToken;
        mCanDoze = canDoze;
        mPreviewMode = isPreviewMode;
        if (mPreviewMode) {
            // Allow screen to dim when in preview mode.
            mScreenBright = false;
        }
        // This is not a security check to prevent malicious dreams but a guard rail to stop
        // third-party dreams from being windowless and not working well as a result.
        if (mWindowless && !mCanDoze && !isCallerSystemUi()) {