@@ -1282,22 +1282,35 @@ private boolean updateWakefulnessLocked(int dirty) {
12821282 return changed ;
12831283 }
12841284
1285- // Also used when exiting a dream to determine whether we should go back
1286- // to being fully awake or else go to sleep for good.
1285+ /**
1286+ * Returns true if the device should go to sleep now.
1287+ * Also used when exiting a dream to determine whether we should go back
1288+ * to being fully awake or else go to sleep for good.
1289+ */
12871290 private boolean isItBedTimeYetLocked () {
1288- return mBootCompleted && !mStayOn
1289- && (mWakeLockSummary
1290- & (WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_SCREEN_DIM
1291- | WAKE_LOCK_PROXIMITY_SCREEN_OFF )) == 0
1292- && (mUserActivitySummary
1293- & (USER_ACTIVITY_SCREEN_BRIGHT | USER_ACTIVITY_SCREEN_DIM )) == 0 ;
1291+ return mBootCompleted && !isScreenBeingKeptOnLocked ();
1292+ }
1293+
1294+ /**
1295+ * Returns true if the screen is being kept on by a wake lock, user activity
1296+ * or the stay on while powered setting.
1297+ */
1298+ private boolean isScreenBeingKeptOnLocked () {
1299+ return mStayOn
1300+ || (mWakeLockSummary & (WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_SCREEN_DIM
1301+ | WAKE_LOCK_PROXIMITY_SCREEN_OFF )) != 0
1302+ || (mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT
1303+ | USER_ACTIVITY_SCREEN_DIM )) != 0 ;
12941304 }
12951305
12961306 /**
12971307 * Determines whether to post a message to the sandman to update the dream state.
12981308 */
12991309 private void updateDreamLocked (int dirty ) {
13001310 if ((dirty & (DIRTY_WAKEFULNESS
1311+ | DIRTY_USER_ACTIVITY
1312+ | DIRTY_WAKE_LOCKS
1313+ | DIRTY_BOOT_COMPLETED
13011314 | DIRTY_SETTINGS
13021315 | DIRTY_IS_POWERED
13031316 | DIRTY_STAY_ON
@@ -1380,15 +1393,15 @@ private void handleSandman() { // runs on handler thread
13801393 }
13811394
13821395 /**
1383- * Returns true if the device is allowed to dream in its current state,
1384- * assuming that there was either an explicit request to nap or the user activity
1385- * timeout expired and no wake locks are held.
1396+ * Returns true if the device is allowed to dream in its current state
1397+ * assuming that it is currently napping or dreaming.
13861398 */
13871399 private boolean canDreamLocked () {
1388- return mIsPowered
1389- && mDreamsSupportedConfig
1400+ return mDreamsSupportedConfig
13901401 && mDreamsEnabledSetting
1391- && mDisplayPowerRequest .screenState != DisplayPowerRequest .SCREEN_STATE_OFF ;
1402+ && mDisplayPowerRequest .screenState != DisplayPowerRequest .SCREEN_STATE_OFF
1403+ && mBootCompleted
1404+ && (mIsPowered || isScreenBeingKeptOnLocked ());
13921405 }
13931406
13941407 /**
0 commit comments