当前位置:   article > 正文

android6.0休眠流程,按电源键休眠流程(framework层)_android needwakelocksuspendblocker

android needwakelocksuspendblocker

这里以Android6.0为例frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.javaPowerManager mPowerManager;

private void powerPress(long eventTime, boolean interactive, int count) {

if (mScreenOnEarly && !mScreenOnFully) {

Slog.i(TAG, "Suppressed redundant power key press while "

  • “already in the process of turning the screen on.”);

return;

}

Slog.i(TAG,“eventTime=”+eventTime+" interactive=“+interactive+” count=“+count+” mShortPressOnPowerBehavior="+mShortPressOnPowerBehavior

+" mBeganFromNonInteractive="+mBeganFromNonInteractive);

if (count == 2) {

powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);

} else if (count == 3) {

powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);

} else if (interactive && !mBeganFromNonInteractive) {

switch (mShortPressOnPowerBehavior) {

case SHORT_PRESS_POWER_NOTHING:

break;

case SHORT_PRESS_POWER_GO_TO_SLEEP:

mPowerManager.goToSleep(eventTime,

PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);

break;

case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:

mPowerManager.goToSleep(eventTime,

PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,

PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);

break;

case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:

mPowerManager.goToSleep(eventTime,

PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,

PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);

launchHomeFromHotKey();

break;

case SHORT_PRESS_POWER_GO_HOME:

launchHomeFromHotKey(true /* awakenFromDreams */, false /respectKeyguard/);

break;

}

}

}

//按电源键跑的是SHORT_PRESS_POWER_GO_TO_SLEEPframeworks/base/core/java/android/os/PowerManager.java

final IPowerManager mService;

public void goToSleep(long time, int reason, int flags) {

try {

mService.goToSleep(time, reason, flags);

} catch (RemoteException e) {

}

}

frameworks/base/core/java/android/os/IPowerManager.aidlframeworks/base/services/core/java/com/android/server/power/PowerManagerService.java

public void goToSleep(long eventTime, int reason, int flags) {

if (eventTime > SystemClock.uptimeMillis()) {

throw new IllegalArgumentException(“event time must not be in the future”);

}

mContext.enforceCallingOrSelfPermission(

android.Manifest.permission.DEVICE_POWER, null);

final int uid = Binder.getCallingUid();

final long ident = Binder.clearCallingIdentity();

try {

goToSleepInternal(eventTime, reason, flags, uid);

} finally {

Binder.restoreCallingIdentity(ident);

}

}

private void goToSleepInternal(long eventTime, int reason, int flags, int uid) {

synchronized (mLock) {

if (goToSleepNoUpdateLocked(eventTime, reason, flags, uid)) {

updatePowerStateLocked();

}

}

}

private boolean goToSleepNoUpdateLocked(long eventTime, int reason, int flags, int uid) {

if (DEBUG_SPEW) {

Slog.d(TAG, “goToSleepNoUpdateLocked: eventTime=” + eventTime

  • “, reason=” + reason + “, flags=” + flags + “, uid=” + uid);

}

if (eventTime < mLastWakeTime

|| mWakefulness == WAKEFULNESS_ASLEEP

|| mWakefulness == WAKEFULNESS_DOZING

|| !mBootCompleted || !mSystemReady) {

return false;

}

Trace.traceBegin(Trace.TRACE_TAG_POWER, “goToSleep”);

try {

switch (reason) {

case PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN:

Slog.i(TAG, "Going to sleep due to device administration policy "

  • “(uid " + uid +”)…");

break;

case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT:

Slog.i(TAG, “Going to sleep due to screen timeout (uid " + uid +”)…");

break;

case PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH:

Slog.i(TAG, “Going to sleep due to lid switch (uid " + uid +”)…");

break;

case PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON:

Slog.i(TAG, “Going to sleep due to power button (uid " + uid +”)…");

break;

case PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON:

Slog.i(TAG, “Going to sleep due to sleep button (uid " + uid +”)…");

break;

case PowerManager.GO_TO_SLEEP_REASON_HDMI:

Slog.i(TAG, “Going to sleep due to HDMI standby (uid " + uid +”)…");

break;

default:

Slog.i(TAG, “Going to sleep by application request (uid " + uid +”)…");

reason = PowerManager.GO_TO_SLEEP_REASON_APPLICATION;

break;

}

mLastSleepTime = eventTime;

mSandmanSummoned = true;

setWakefulnessLocked(WAKEFULNESS_DOZING, reason);

// Report the number of wake locks that will be cleared by going to sleep.

int numWakeLocksCleared = 0;

final int numWakeLocks = mWakeLocks.size();

for (int i = 0; i < numWakeLocks; i++) {

final WakeLock wakeLock = mWakeLocks.get(i);

switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {

case PowerManager.FULL_WAKE_LOCK:

case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:

case PowerManager.SCREEN_DIM_WAKE_LOCK:

numWakeLocksCleared += 1;

break;

}

}

EventLog.writeEvent(EventLogTags.POWER_SLEEP_REQUESTED, numWakeLocksCleared);

// Skip dozing if requested.

if ((flags & PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE) != 0) {

reallyGoToSleepNoUpdateLocked(eventTime, uid);

}

} finally {

Trace.traceEnd(Trace.TRACE_TAG_POWER);

}

return true;

}

private void updatePowerStateLocked() {

if (!mSystemReady || mDirty == 0) {

return;

}

if (!Thread.holdsLock(mLock)) {

Slog.wtf(TAG, “Power manager lock was not held when calling updatePowerStateLocked”);

}

Trace.traceBegin(Trace.TRACE_TAG_POWER, “updatePowerState”);

try {

// Phase 0: Basic state updates.

updateIsPoweredLocked(mDirty);

updateStayOnLocked(mDirty);

updateScreenBrightnessBoostLocked(mDirty);

// Phase 1: Update wakefulness.

// Loop because the wake lock and user activity computations are influenced

// by changes in wakefulness.

final long now = SystemClock.uptimeMillis();

int dirtyPhase2 = 0;

for (;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/889012
推荐阅读
相关标签