Skip to content

Commit 86e85ef

Browse files
Iliyan MalchevAndroid (Google) Code Review
authored andcommitted
Merge "Set backlight brightness in correct order." into jb-mr1-dev
2 parents 1f13a98 + 735f740 commit 86e85ef

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

services/java/com/android/server/power/DisplayPowerState.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,24 @@ private void invalidate(int dirty) {
239239
private void apply() {
240240
if (mDirty != 0) {
241241
if ((mDirty & DIRTY_SCREEN_ON) != 0 && !mScreenOn) {
242+
mScreenBrightnessModulator.setBrightness(0, true /*sync*/);
242243
PowerManagerService.nativeSetScreenState(false);
243244
}
244245

245246
if ((mDirty & DIRTY_ELECTRON_BEAM) != 0) {
246247
mElectronBeam.draw(mElectronBeamLevel);
247248
}
248249

249-
if ((mDirty & (DIRTY_BRIGHTNESS | DIRTY_SCREEN_ON | DIRTY_ELECTRON_BEAM)) != 0) {
250-
mScreenBrightnessModulator.setBrightness(mScreenOn ?
251-
(int)(mScreenBrightness * mElectronBeamLevel) : 0);
252-
}
253-
254250
if ((mDirty & DIRTY_SCREEN_ON) != 0 && mScreenOn) {
255251
PowerManagerService.nativeSetScreenState(true);
256252
}
257253

254+
if ((mDirty & (DIRTY_BRIGHTNESS | DIRTY_SCREEN_ON | DIRTY_ELECTRON_BEAM)) != 0
255+
&& mScreenOn) {
256+
mScreenBrightnessModulator.setBrightness(
257+
(int)(mScreenBrightness * mElectronBeamLevel), false /*sync*/);
258+
}
259+
258260
mDirty = 0;
259261

260262
if (mCleanListener != null) {

services/java/com/android/server/power/PhotonicModulator.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ public PhotonicModulator(Executor executor, LightsService.Light light,
4949
}
5050

5151
/**
52-
* Asynchronously sets the backlight brightness.
52+
* Sets the backlight brightness, synchronously or asynchronously.
5353
*
5454
* @param lightValue The new light value, from 0 to 255.
55+
* @param sync If true, waits for the brightness change to complete before returning.
5556
*/
56-
public void setBrightness(int lightValue) {
57+
public void setBrightness(int lightValue, boolean sync) {
5758
synchronized (mLock) {
5859
if (lightValue != mPendingLightValue) {
5960
mPendingLightValue = lightValue;
@@ -63,6 +64,15 @@ public void setBrightness(int lightValue) {
6364
mExecutor.execute(mTask);
6465
}
6566
}
67+
if (sync) {
68+
while (mPendingChange) {
69+
try {
70+
mLock.wait();
71+
} catch (InterruptedException ex) {
72+
// ignore it
73+
}
74+
}
75+
}
6676
}
6777
}
6878

@@ -76,6 +86,7 @@ public void run() {
7686
if (newLightValue == mActualLightValue) {
7787
mSuspendBlocker.release();
7888
mPendingChange = false;
89+
mLock.notifyAll();
7990
return;
8091
}
8192
mActualLightValue = newLightValue;

0 commit comments

Comments
 (0)