new Intent(NOTIFICATION_PULSE_ACTION).setPackage(getPackageName()),
PendingIntent.FLAG_UPDATE_CURRENT);
mDisplayStateWhenOn = mDisplayStateSupported ? Display.STATE_DOZE : Display.STATE_ON;
- setDozeScreenState(mDisplayStateWhenOn);
+ mDisplayOff.run();
}
@Override
mHandler.postDelayed(mDisplayOff, millis);
}
- public void startDozing() {
- if (DEBUG) Log.d(mTag, "startDozing mDreaming=" + mDreaming);
- if (!mDreaming) {
- Log.w(mTag, "Not dozing, no longer dreaming");
- return;
- }
-
- super.startDozing();
- }
-
@Override
public void onDreamingStopped() {
if (DEBUG) Log.d(mTag, "onDreamingStopped isDozing=" + isDozing());
mWakeLock.release();
}
listenForPulseSignals(false);
- stopDozing();
- dozingStopped();
- }
-
- @Override
- public void onDetachedFromWindow() {
- if (DEBUG) Log.d(mTag, "onDetachedFromWindow");
- super.onDetachedFromWindow();
-
- dozingStopped();
- }
-
- @Override
- public void onDestroy() {
- if (DEBUG) Log.d(mTag, "onDestroy");
- super.onDestroy();
-
dozingStopped();
+ mHandler.removeCallbacks(mDisplayOff);
}
private void requestDoze() {
// We might override this below based on other factors.
int state;
int brightness = PowerManager.BRIGHTNESS_DEFAULT;
+ boolean performScreenOffTransition = false;
switch (mPowerRequest.policy) {
case DisplayPowerRequest.POLICY_OFF:
state = Display.STATE_OFF;
+ performScreenOffTransition = true;
break;
case DisplayPowerRequest.POLICY_DOZE:
if (mPowerRequest.dozeScreenState != Display.STATE_UNKNOWN) {
state = Display.STATE_ON;
break;
}
+ assert(state != Display.STATE_UNKNOWN);
// Apply the proximity sensor.
if (mProximitySensor != null) {
// Wait for previous on animation to complete beforehand.
unblockScreenOn();
if (!mColorFadeOnAnimator.isStarted()) {
- if (mPowerRequest.policy == DisplayPowerRequest.POLICY_OFF) {
+ if (performScreenOffTransition) {
// Perform screen off animation.
if (!mColorFadeOffAnimator.isStarted()) {
if (mPowerState.getColorFadeLevel() == 0.0f) {
pw.println(" mScreenBrightnessDarkConfig=" + mScreenBrightnessDarkConfig);
pw.println(" mScreenBrightnessRangeMinimum=" + mScreenBrightnessRangeMinimum);
pw.println(" mScreenBrightnessRangeMaximum=" + mScreenBrightnessRangeMaximum);
- pw.println(" mUseSoftwareAutoBrightnessConfig="
- + mUseSoftwareAutoBrightnessConfig);
+ pw.println(" mUseSoftwareAutoBrightnessConfig=" + mUseSoftwareAutoBrightnessConfig);
+ pw.println(" mColorFadeFadesConfig=" + mColorFadeFadesConfig);
mHandler.runWithScissors(new Runnable() {
@Override
import com.android.internal.app.IBatteryStats;
import com.android.internal.os.BackgroundThread;
import com.android.server.EventLogTags;
-import com.android.server.LocalServices;
import com.android.server.ServiceThread;
+import com.android.server.SystemService;
import com.android.server.am.BatteryStatsService;
import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
-import android.os.SystemService;
import android.os.Trace;
import android.os.UserHandle;
import android.os.WorkSource;
* The power manager service is responsible for coordinating power management
* functions on the device.
*/
-public final class PowerManagerService extends com.android.server.SystemService
+public final class PowerManagerService extends SystemService
implements Watchdog.Monitor {
private static final String TAG = "PowerManagerService";
// True if dreams should be activated on dock.
private boolean mDreamsActivateOnDockSetting;
+ // True if doze should not be started until after the screen off transition.
+ private boolean mDozeAfterScreenOffConfig;
+
// The minimum screen off timeout, in milliseconds.
private int mMinimumScreenOffTimeoutConfig;
com.android.internal.R.integer.config_dreamsBatteryLevelMinimumWhenNotPowered);
mDreamsBatteryLevelDrainCutoffConfig = resources.getInteger(
com.android.internal.R.integer.config_dreamsBatteryLevelDrainCutoff);
+ mDozeAfterScreenOffConfig = resources.getBoolean(
+ com.android.internal.R.bool.config_dozeAfterScreenOff);
mMinimumScreenOffTimeoutConfig = resources.getInteger(
com.android.internal.R.integer.config_minimumScreenOffTimeout);
mMaximumScreenDimDurationConfig = resources.getInteger(
}
}
- // Phase 2: Update dreams and display power state.
- updateDreamLocked(dirtyPhase2);
- updateDisplayPowerStateLocked(dirtyPhase2);
+ // Phase 2: Update display power state.
+ boolean displayBecameReady = updateDisplayPowerStateLocked(dirtyPhase2);
+
+ // Phase 3: Update dream state (depends on display ready signal).
+ updateDreamLocked(dirtyPhase2, displayBecameReady);
- // Phase 3: Send notifications, if needed.
+ // Phase 4: Send notifications, if needed.
if (mDisplayReady) {
finishInteractiveStateChangeLocked();
}
- // Phase 4: Update suspend blocker.
+ // Phase 5: Update suspend blocker.
// Because we might release the last suspend blocker here, we need to make sure
// we finished everything else first!
updateSuspendBlockerLocked();
/**
* Determines whether to post a message to the sandman to update the dream state.
*/
- private void updateDreamLocked(int dirty) {
+ private void updateDreamLocked(int dirty, boolean displayBecameReady) {
if ((dirty & (DIRTY_WAKEFULNESS
| DIRTY_USER_ACTIVITY
| DIRTY_WAKE_LOCKS
| DIRTY_IS_POWERED
| DIRTY_STAY_ON
| DIRTY_PROXIMITY_POSITIVE
- | DIRTY_BATTERY_STATE)) != 0) {
- scheduleSandmanLocked();
+ | DIRTY_BATTERY_STATE)) != 0 || displayBecameReady) {
+ if (mDisplayReady) {
+ scheduleSandmanLocked();
+ }
}
}
synchronized (mLock) {
mSandmanScheduled = false;
wakefulness = mWakefulness;
- if (mSandmanSummoned) {
+ if (mSandmanSummoned && mDisplayReady) {
startDreaming = ((wakefulness == WAKEFULNESS_DREAMING && canDreamLocked())
|| wakefulness == WAKEFULNESS_DOZING);
mSandmanSummoned = false;
* has been updated so we come back here to double-check and finish up.
*
* This function recalculates the display power state each time.
+ *
+ * @return True if the display became ready.
*/
- private void updateDisplayPowerStateLocked(int dirty) {
+ private boolean updateDisplayPowerStateLocked(int dirty) {
+ final boolean oldDisplayReady = mDisplayReady;
if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS
| DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED
| DIRTY_SETTINGS | DIRTY_SCREEN_ON_BLOCKER_RELEASED)) != 0) {
+ ", mBootCompleted=" + mBootCompleted);
}
}
+ return mDisplayReady && !oldDisplayReady;
}
private static boolean isValidBrightness(int value) {
return DisplayPowerRequest.POLICY_OFF;
}
- if ((mWakeLockSummary & WAKE_LOCK_DOZE) != 0) {
- return DisplayPowerRequest.POLICY_DOZE;
+ if (mWakefulness == WAKEFULNESS_DOZING) {
+ if ((mWakeLockSummary & WAKE_LOCK_DOZE) != 0) {
+ return DisplayPowerRequest.POLICY_DOZE;
+ }
+ if (mDozeAfterScreenOffConfig) {
+ return DisplayPowerRequest.POLICY_OFF;
+ }
+ // Fall through and preserve the current screen policy if not configured to
+ // doze after screen off. This causes the screen off transition to be skipped.
}
if ((mWakeLockSummary & WAKE_LOCK_SCREEN_BRIGHT) != 0
pw.println(" mDreamsEnabledSetting=" + mDreamsEnabledSetting);
pw.println(" mDreamsActivateOnSleepSetting=" + mDreamsActivateOnSleepSetting);
pw.println(" mDreamsActivateOnDockSetting=" + mDreamsActivateOnDockSetting);
+ pw.println(" mDozeAfterScreenOffConfig=" + mDozeAfterScreenOffConfig);
pw.println(" mLowPowerModeSetting=" + mLowPowerModeSetting);
pw.println(" mAutoLowPowerModeEnabled=" + mAutoLowPowerModeEnabled);
pw.println(" mAutoLowPowerModeSnoozing=" + mAutoLowPowerModeSnoozing);