Skip to content

Commit f6138f0

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Don't consider the boot completed until the animation is over." into jb-mr1-dev
2 parents 0fca2a3 + 20767b2 commit f6138f0

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import android.os.Process;
4949
import android.os.RemoteException;
5050
import android.os.SystemClock;
51+
import android.os.SystemService;
5152
import android.os.UserHandle;
5253
import android.os.WorkSource;
5354
import android.provider.Settings;
@@ -81,6 +82,8 @@ public final class PowerManagerService extends IPowerManager.Stub
8182
private static final int MSG_SANDMAN = 2;
8283
// Message: Sent when the screen on blocker is released.
8384
private static final int MSG_SCREEN_ON_BLOCKER_RELEASED = 3;
85+
// Message: Sent to poll whether the boot animation has terminated.
86+
private static final int MSG_CHECK_IF_BOOT_ANIMATION_FINISHED = 4;
8487

8588
// Dirty bit: mWakeLocks changed
8689
private static final int DIRTY_WAKE_LOCKS = 1 << 0;
@@ -153,6 +156,12 @@ public final class PowerManagerService extends IPowerManager.Stub
153156
// See point of use for more details.
154157
private static final int WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT = 95;
155158

159+
// The name of the boot animation service in init.rc.
160+
private static final String BOOT_ANIMATION_SERVICE = "bootanim";
161+
162+
// Poll interval in milliseconds for watching boot animation finished.
163+
private static final int BOOT_ANIMATION_POLL_INTERVAL = 200;
164+
156165
private Context mContext;
157166
private LightsService mLightsService;
158167
private BatteryService mBatteryService;
@@ -1662,6 +1671,29 @@ private void handleBatteryStateChangedLocked() {
16621671
updatePowerStateLocked();
16631672
}
16641673

1674+
private void startWatchingForBootAnimationFinished() {
1675+
mHandler.sendEmptyMessage(MSG_CHECK_IF_BOOT_ANIMATION_FINISHED);
1676+
}
1677+
1678+
private void checkIfBootAnimationFinished() {
1679+
if (DEBUG) {
1680+
Slog.d(TAG, "Check if boot animation finished...");
1681+
}
1682+
1683+
if (SystemService.isRunning(BOOT_ANIMATION_SERVICE)) {
1684+
mHandler.sendEmptyMessageDelayed(MSG_CHECK_IF_BOOT_ANIMATION_FINISHED,
1685+
BOOT_ANIMATION_POLL_INTERVAL);
1686+
return;
1687+
}
1688+
1689+
synchronized (mLock) {
1690+
if (!mBootCompleted) {
1691+
Slog.i(TAG, "Boot animation finished.");
1692+
handleBootCompletedLocked();
1693+
}
1694+
}
1695+
}
1696+
16651697
private void handleBootCompletedLocked() {
16661698
final long now = SystemClock.uptimeMillis();
16671699
mBootCompleted = true;
@@ -2170,9 +2202,13 @@ public void onReceive(Context context, Intent intent) {
21702202
private final class BootCompletedReceiver extends BroadcastReceiver {
21712203
@Override
21722204
public void onReceive(Context context, Intent intent) {
2173-
synchronized (mLock) {
2174-
handleBootCompletedLocked();
2175-
}
2205+
// This is our early signal that the system thinks it has finished booting.
2206+
// However, the boot animation may still be running for a few more seconds
2207+
// since it is ultimately in charge of when it terminates.
2208+
// Defer transitioning into the boot completed state until the animation exits.
2209+
// We do this so that the screen does not start to dim prematurely before
2210+
// the user has actually had a chance to interact with the device.
2211+
startWatchingForBootAnimationFinished();
21762212
}
21772213
}
21782214

@@ -2227,6 +2263,9 @@ public void handleMessage(Message msg) {
22272263
case MSG_SCREEN_ON_BLOCKER_RELEASED:
22282264
handleScreenOnBlockerReleased();
22292265
break;
2266+
case MSG_CHECK_IF_BOOT_ANIMATION_FINISHED:
2267+
checkIfBootAnimationFinished();
2268+
break;
22302269
}
22312270
}
22322271
}

0 commit comments

Comments
 (0)