Skip to content

Commit f75724b

Browse files
author
Jeff Brown
committed
Initialize screen state earlier in the boot process.
The system depends on receiving reliable vsync signals from surface flinger during the boot process. If it doesn't get them because the screen is off then a hang may occur. This isn't a problem when surface flinger manages the screen blanking itself but it is a problem for devices that still rely on early-suspend. When early-suspend is involved, the screen may be off without surface flinger knowing. This is a problem because surface flinger will only synthesize fake vsyncs when it knows the screen is off, otherwise relying on the hardware to generate vsync signals itself. Unfortunately, the hardware won't generate vsync signals if the screen was turned off by early-suspend, so we have a problem. Bug: 6975688 Change-Id: Iaf4527f716bf4ea72cc3e6fdaf060855697b02f2
1 parent ba94170 commit f75724b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ final class DisplayPowerState {
4949
private static final int DIRTY_ELECTRON_BEAM = 1 << 1;
5050
private static final int DIRTY_BRIGHTNESS = 1 << 2;
5151

52-
private static final int DIRTY_ALL = 0xffffffff;
53-
5452
private final Choreographer mChoreographer;
5553
private final ElectronBeam mElectronBeam;
5654
private final PhotonicModulator mScreenBrightnessModulator;
@@ -68,10 +66,16 @@ public DisplayPowerState(ElectronBeam electronBean,
6866
mElectronBeam = electronBean;
6967
mScreenBrightnessModulator = screenBrightnessModulator;
7068

69+
// At boot time, we know that the screen is on and the electron beam
70+
// animation is not playing. We don't know the screen's brightness though,
71+
// so prepare to set it to a known state when the state is next applied.
72+
// Although we set the brightness to full on here, the display power controller
73+
// will reset the brightness to a new level immediately before the changes
74+
// actually have a chance to be applied.
7175
mScreenOn = true;
7276
mElectronBeamLevel = 1.0f;
7377
mScreenBrightness = PowerManager.BRIGHTNESS_ON;
74-
invalidate(DIRTY_ALL);
78+
invalidate(DIRTY_BRIGHTNESS);
7579
}
7680

7781
public static final FloatProperty<DisplayPowerState> ELECTRON_BEAM_LEVEL =

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ public PowerManagerService() {
296296
}
297297

298298
nativeInit();
299+
nativeSetPowerState(true, true);
299300
}
300301

301302
/**
@@ -305,6 +306,14 @@ public PowerManagerService() {
305306
public void init(Context context, LightsService ls,
306307
ActivityManagerService am, BatteryService bs, IBatteryStats bss,
307308
DisplayManagerService dm) {
309+
// Forcibly turn the screen on at boot so that it is in a known power state.
310+
// We do this in init() rather than in the constructor because setting the
311+
// screen state requires a call into surface flinger which then needs to call back
312+
// into the activity manager to check permissions. Unfortunately the
313+
// activity manager is not running when the constructor is called, so we
314+
// have to defer setting the screen state until this point.
315+
nativeSetScreenState(true);
316+
308317
mContext = context;
309318
mLightsService = ls;
310319
mBatteryService = bs;

0 commit comments

Comments
 (0)