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

Commit 05e76fe3 authored by Michael Wright's avatar Michael Wright
Browse files

Add config to force display to transition to off after doze

Some display hardware can't do the transition from doze display states
to the on display state cleanly, so in order to hide any janky-ness of
the transition we force the display off and cover the screen with a
black surface. This lets us keep the screen black until SystemUI and the
display are both ready.

Bug: 63531607
Test: manual
Change-Id: I66bd483e5f01e1dbd5069465aa122828af5f1903
parent 3789b629
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1132,6 +1132,15 @@ public final class Display {
        return state == STATE_OFF || state == STATE_DOZE_SUSPEND;
    }

    /**
     * Returns true if the display may be in a reduced operating mode while in the
     * specified display power state.
     * @hide
     */
    public static boolean isDozeState(int state) {
        return state == STATE_DOZE || state == STATE_DOZE_SUSPEND;
    }

    /**
     * A mode supported by a given display.
     *
+5 −0
Original line number Diff line number Diff line
@@ -1862,6 +1862,11 @@
         states. -->
    <bool name="config_dozeAlwaysOnDisplayAvailable">false</bool>

    <!-- Whether the display hardware requires we go to the off state before transitioning
         out of any doze states. -->
    <bool name="config_displayTransitionOffAfterDoze">false</bool>


    <!-- Power Management: Specifies whether to decouple the auto-suspend state of the
         device from the display on/off state.

+1 −0
Original line number Diff line number Diff line
@@ -3064,6 +3064,7 @@
  <java-symbol type="bool" name="config_handleVolumeKeysInWindowManager" />
  <java-symbol type="integer" name="config_inCallNotificationVolumeRelative" />
  <java-symbol type="bool" name="config_dozeAlwaysOnDisplayAvailable" />
  <java-symbol type="bool" name="config_displayTransitionOffAfterDoze" />
  <java-symbol type="integer" name="config_storageManagerDaystoRetainDefault" />
  <java-symbol type="string" name="config_headlineFontFamily" />
  <java-symbol type="string" name="config_headlineFontFamilyLight" />
+34 −2
Original line number Diff line number Diff line
@@ -165,6 +165,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // a stylish color fade animation instead.
    private boolean mColorFadeFadesConfig;

    // True if we need to transition to the off state when coming out of a doze state.
    // Some display hardware will show artifacts (flickers, etc) when transitioning from a doze
    // to a fully on state. In order to hide these, we first transition to off to let the system
    // animate the screen on as it normally would, which is a much smoother experience.
    private boolean mTransitionOffAfterDozeConfig;

    // The pending power request.
    // Initially null until the first call to requestPowerState.
    // Guarded by mLock.
@@ -410,6 +416,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mColorFadeFadesConfig = resources.getBoolean(
                com.android.internal.R.bool.config_animateScreenLights);

        mTransitionOffAfterDozeConfig = resources.getBoolean(
                com.android.internal.R.bool.config_displayTransitionOffAfterDoze);

        if (!DEBUG_PRETEND_PROXIMITY_SENSOR_ABSENT) {
            mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
            if (mProximitySensor != null) {
@@ -877,6 +886,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    }

    private boolean setScreenState(int state) {
        return setScreenState(state, false /*force*/);
    }

    private boolean setScreenState(int state, boolean force) {
        final boolean isOff = (state == Display.STATE_OFF);
        if (mPowerState.getScreenState() != state) {

@@ -887,9 +900,17 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    mReportedScreenStateToPolicy = REPORTED_TO_POLICY_SCREEN_TURNING_OFF;
                    blockScreenOff();
                    mWindowManagerPolicy.screenTurningOff(mPendingScreenOffUnblocker);
                    if (force) {
                        // If we're forcing the power state transition then immediately
                        // unblock the screen off event. This keeps the lifecycle consistent,
                        // so WindowManagerPolicy will always see screenTurningOff before
                        // screenTurnedOff, but we don't actually block on them for the state
                        // change.
                        unblockScreenOff();
                    } else {
                        return false;
                    }
                } else if (mPendingScreenOffUnblocker != null) {

                    // Abort doing the state change until screen off is unblocked.
                    return false;
                }
@@ -968,6 +989,17 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mPendingScreenOff = false;
        }

        if (mTransitionOffAfterDozeConfig &&
                Display.isDozeState(mPowerState.getScreenState())
                && !Display.isDozeState(target)) {
            setScreenState(Display.STATE_OFF, true /*force*/);
            // Skip the screen off animation and add a black surface to hide the
            // contents of the screen. This will also trigger another power state update so that we
            // end up converging on the target state.
            mColorFadeOffAnimator.end();
            return;
        }

        // If we were in the process of turning off the screen but didn't quite
        // finish.  Then finish up now to prevent a jarring transition back
        // to screen on if we skipped blocking screen on as usual.