Don't wait for brightness changes

On some devices, changing the brightness is quite slow, because the
change needs to wait for the vsync signal. However, when we are also
running a brightness change animation, as soon as the last change has
been sent there is a new one pending, leading to that we never reach
"clean" state in the PowerManagerService and thus we don't notify
clients about the state change, which can delay the animation for waking
up while dozing by as much as a second.

To fix this, if we only issue a brightness change, we don't block on
that because it's not relevant for us.

Bug: 22879546
Change-Id: Idad7e90c436bfbc38581fe8ce24d606e432b7952
This commit is contained in:
Jorim Jaggi
2015-08-24 13:54:19 -07:00
parent b1cebd9ecf
commit 6e90ea0336

View File

@@ -341,7 +341,8 @@ final class DisplayPowerState {
private int mPendingBacklight = INITIAL_BACKLIGHT; private int mPendingBacklight = INITIAL_BACKLIGHT;
private int mActualState = INITIAL_SCREEN_STATE; private int mActualState = INITIAL_SCREEN_STATE;
private int mActualBacklight = INITIAL_BACKLIGHT; private int mActualBacklight = INITIAL_BACKLIGHT;
private boolean mChangeInProgress; private boolean mStateChangeInProgress;
private boolean mBacklightChangeInProgress;
public PhotonicModulator() { public PhotonicModulator() {
super("PhotonicModulator"); super("PhotonicModulator");
@@ -349,7 +350,9 @@ final class DisplayPowerState {
public boolean setState(int state, int backlight) { public boolean setState(int state, int backlight) {
synchronized (mLock) { synchronized (mLock) {
if (state != mPendingState || backlight != mPendingBacklight) { boolean stateChanged = state != mPendingState;
boolean backlightChanged = backlight != mPendingBacklight;
if (stateChanged || backlightChanged) {
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "Requesting new screen state: state=" Slog.d(TAG, "Requesting new screen state: state="
+ Display.stateToString(state) + ", backlight=" + backlight); + Display.stateToString(state) + ", backlight=" + backlight);
@@ -358,12 +361,15 @@ final class DisplayPowerState {
mPendingState = state; mPendingState = state;
mPendingBacklight = backlight; mPendingBacklight = backlight;
if (!mChangeInProgress) { boolean changeInProgress = mStateChangeInProgress || mBacklightChangeInProgress;
mChangeInProgress = true; mStateChangeInProgress = stateChanged;
mBacklightChangeInProgress = backlightChanged;
if (!changeInProgress) {
mLock.notifyAll(); mLock.notifyAll();
} }
} }
return !mChangeInProgress; return !mStateChangeInProgress;
} }
} }
@@ -375,7 +381,8 @@ final class DisplayPowerState {
pw.println(" mPendingBacklight=" + mPendingBacklight); pw.println(" mPendingBacklight=" + mPendingBacklight);
pw.println(" mActualState=" + Display.stateToString(mActualState)); pw.println(" mActualState=" + Display.stateToString(mActualState));
pw.println(" mActualBacklight=" + mActualBacklight); pw.println(" mActualBacklight=" + mActualBacklight);
pw.println(" mChangeInProgress=" + mChangeInProgress); pw.println(" mStateChangeInProgress=" + mStateChangeInProgress);
pw.println(" mBacklightChangeInProgress=" + mBacklightChangeInProgress);
} }
} }
@@ -392,10 +399,15 @@ final class DisplayPowerState {
stateChanged = (state != mActualState); stateChanged = (state != mActualState);
backlight = mPendingBacklight; backlight = mPendingBacklight;
backlightChanged = (backlight != mActualBacklight); backlightChanged = (backlight != mActualBacklight);
if (!stateChanged && !backlightChanged) { if (!stateChanged) {
// All changed applied, notify outer class and wait for more. // State changed applied, notify outer class.
mChangeInProgress = false;
postScreenUpdateThreadSafe(); postScreenUpdateThreadSafe();
mStateChangeInProgress = false;
}
if (!backlightChanged) {
mBacklightChangeInProgress = false;
}
if (!stateChanged && !backlightChanged) {
try { try {
mLock.wait(); mLock.wait();
} catch (InterruptedException ex) { } } catch (InterruptedException ex) { }