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

Commit 3415634c authored by Jeff Brown's avatar Jeff Brown Committed by Android Git Automerger
Browse files

am 72f1e3b9: am 1cbff0e3: Merge "Improve screen brightness boost behavior." into lmp-sprout-dev

* commit '72f1e3b9':
  Improve screen brightness boost behavior.
parents 46112fe1 72f1e3b9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -998,6 +998,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }
                break;
            case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
                Slog.i(TAG, "Starting brightness boost.");
                if (!interactive) {
                    wakeUpFromPowerKey(eventTime);
                }
                mPowerManager.boostScreenBrightness(eventTime);
                break;
        }
+10 −3
Original line number Diff line number Diff line
@@ -582,11 +582,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        state = mPowerState.getScreenState();

        // Use zero brightness when screen is off.
        // Use full brightness when screen brightness is boosted.
        if (state == Display.STATE_OFF) {
            brightness = PowerManager.BRIGHTNESS_OFF;
        } else if (mPowerRequest.boostScreenBrightness) {
            brightness = PowerManager.BRIGHTNESS_ON;
        }

        // Configure auto-brightness.
@@ -601,6 +598,16 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    mPowerRequest.screenAutoBrightnessAdjustment, state != Display.STATE_ON);
        }

        // Apply brightness boost.
        // We do this here after configuring auto-brightness so that we don't
        // disable the light sensor during this temporary state.  That way when
        // boost ends we will be able to resume normal auto-brightness behavior
        // without any delay.
        if (mPowerRequest.boostScreenBrightness
                && brightness != PowerManager.BRIGHTNESS_OFF) {
            brightness = PowerManager.BRIGHTNESS_ON;
        }

        // Apply auto-brightness.
        boolean slowChange = false;
        if (brightness < 0) {
+51 −33
Original line number Diff line number Diff line
@@ -1234,6 +1234,7 @@ public final class PowerManagerService extends SystemService
            // Phase 0: Basic state updates.
            updateIsPoweredLocked(mDirty);
            updateStayOnLocked(mDirty);
            updateScreenBrightnessBoostLocked(mDirty);

            // Phase 1: Update wakefulness.
            // Loop because the wake lock and user activity computations are influenced
@@ -1465,7 +1466,8 @@ public final class PowerManagerService extends SystemService
    private void updateUserActivitySummaryLocked(long now, int dirty) {
        // Update the status of the user activity timeout timer.
        if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY
                | DIRTY_WAKEFULNESS | DIRTY_SETTINGS)) != 0) {
                | DIRTY_WAKEFULNESS | DIRTY_SETTINGS
                | DIRTY_SCREEN_BRIGHTNESS_BOOST)) != 0) {
            mHandler.removeMessages(MSG_USER_ACTIVITY_TIMEOUT);

            long nextTimeout = 0;
@@ -1641,7 +1643,8 @@ public final class PowerManagerService extends SystemService
                || mProximityPositive
                || (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) != 0
                || (mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT
                        | USER_ACTIVITY_SCREEN_DIM)) != 0;
                        | USER_ACTIVITY_SCREEN_DIM)) != 0
                || mScreenBrightnessBoostInProgress;
    }

    /**
@@ -1828,9 +1831,6 @@ public final class PowerManagerService extends SystemService
                | DIRTY_SETTINGS | DIRTY_SCREEN_BRIGHTNESS_BOOST)) != 0) {
            mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked();

            // Handle screen brightness boost timeout.
            updateScreenBrightnessBoostLocked();

            // Determine appropriate screen brightness and auto-brightness adjustments.
            int screenBrightness = mScreenBrightnessSettingDefault;
            float screenAutoBrightnessAdjustment = 0.0f;
@@ -1879,7 +1879,7 @@ public final class PowerManagerService extends SystemService
            }

            mDisplayReady = mDisplayManagerInternal.requestPowerState(mDisplayPowerRequest,
                    mRequestWaitForNegativeProximity) && !mScreenBrightnessBoostInProgress;
                    mRequestWaitForNegativeProximity);
            mRequestWaitForNegativeProximity = false;

            if (DEBUG_SPEW) {
@@ -1896,13 +1896,15 @@ public final class PowerManagerService extends SystemService
        return mDisplayReady && !oldDisplayReady;
    }

    private void updateScreenBrightnessBoostLocked() {
    private void updateScreenBrightnessBoostLocked(int dirty) {
        if ((dirty & DIRTY_SCREEN_BRIGHTNESS_BOOST) != 0) {
            if (mScreenBrightnessBoostInProgress) {
                final long now = SystemClock.uptimeMillis();
                mHandler.removeMessages(MSG_SCREEN_BRIGHTNESS_BOOST_TIMEOUT);
                if (mLastScreenBrightnessBoostTime > mLastSleepTime) {
                    final long boostTimeout = mLastScreenBrightnessBoostTime +
                            SCREEN_BRIGHTNESS_BOOST_TIMEOUT;
                if (boostTimeout > SystemClock.uptimeMillis()) {
                    if (boostTimeout > now) {
                        Message msg = mHandler.obtainMessage(MSG_SCREEN_BRIGHTNESS_BOOST_TIMEOUT);
                        msg.setAsynchronous(true);
                        mHandler.sendMessageAtTime(msg, boostTimeout);
@@ -1910,6 +1912,9 @@ public final class PowerManagerService extends SystemService
                    }
                }
                mScreenBrightnessBoostInProgress = false;
                userActivityNoUpdateLocked(now,
                        PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
            }
        }
    }

@@ -1940,7 +1945,8 @@ public final class PowerManagerService extends SystemService

        if ((mWakeLockSummary & WAKE_LOCK_SCREEN_BRIGHT) != 0
                || (mUserActivitySummary & USER_ACTIVITY_SCREEN_BRIGHT) != 0
                || !mBootCompleted) {
                || !mBootCompleted
                || mScreenBrightnessBoostInProgress) {
            return DisplayPowerRequest.POLICY_BRIGHT;
        }

@@ -2037,16 +2043,14 @@ public final class PowerManagerService extends SystemService
        final boolean needWakeLockSuspendBlocker = ((mWakeLockSummary & WAKE_LOCK_CPU) != 0);
        final boolean needDisplaySuspendBlocker = needDisplaySuspendBlockerLocked();
        final boolean autoSuspend = !needDisplaySuspendBlocker;
        final boolean interactive = mDisplayPowerRequest.isBrightOrDim();

        // Disable auto-suspend if needed.
        if (!autoSuspend) {
            if (mDecoupleHalAutoSuspendModeFromDisplayConfig) {
        // FIXME We should consider just leaving auto-suspend enabled forever since
        // we already hold the necessary wakelocks.
        if (!autoSuspend && mDecoupleHalAutoSuspendModeFromDisplayConfig) {
            setHalAutoSuspendModeLocked(false);
        }
            if (mDecoupleHalInteractiveModeFromDisplayConfig) {
                setHalInteractiveModeLocked(true);
            }
        }

        // First acquire suspend blockers if needed.
        if (needWakeLockSuspendBlocker && !mHoldingWakeLockSuspendBlocker) {
@@ -2058,6 +2062,22 @@ public final class PowerManagerService extends SystemService
            mHoldingDisplaySuspendBlocker = true;
        }

        // Inform the power HAL about interactive mode.
        // Although we could set interactive strictly based on the wakefulness
        // as reported by isInteractive(), it is actually more desirable to track
        // the display policy state instead so that the interactive state observed
        // by the HAL more accurately tracks transitions between AWAKE and DOZING.
        // Refer to getDesiredScreenPolicyLocked() for details.
        if (mDecoupleHalInteractiveModeFromDisplayConfig) {
            // When becoming non-interactive, we want to defer sending this signal
            // until the display is actually ready so that all transitions have
            // completed.  This is probably a good sign that things have gotten
            // too tangled over here...
            if (interactive || mDisplayReady) {
                setHalInteractiveModeLocked(interactive);
            }
        }

        // Then release suspend blockers if needed.
        if (!needWakeLockSuspendBlocker && mHoldingWakeLockSuspendBlocker) {
            mWakeLockSuspendBlocker.release();
@@ -2069,15 +2089,10 @@ public final class PowerManagerService extends SystemService
        }

        // Enable auto-suspend if needed.
        if (autoSuspend) {
            if (mDecoupleHalInteractiveModeFromDisplayConfig) {
                setHalInteractiveModeLocked(false);
            }
            if (mDecoupleHalAutoSuspendModeFromDisplayConfig) {
        if (autoSuspend && mDecoupleHalAutoSuspendModeFromDisplayConfig) {
            setHalAutoSuspendModeLocked(true);
        }
    }
    }

    /**
     * Return true if we must keep a suspend blocker active on behalf of the display.
@@ -2097,6 +2112,9 @@ public final class PowerManagerService extends SystemService
                return true;
            }
        }
        if (mScreenBrightnessBoostInProgress) {
            return true;
        }
        // Let the system suspend if the screen is off or dozing.
        return false;
    }