1. 程式人生 > >修改Android 休眠邏輯使系統關屏而不進入休眠

修改Android 休眠邏輯使系統關屏而不進入休眠

default:
Slog.i(TAG, "Going to sleep by user request...");
reason = PowerManager.GO_TO_SLEEP_REASON_USER;
+
+ if(ifSendNoSleepBroadcast()) return false;

break;
}

@@ -1727,6 +1739,21 @@ public final class PowerManagerService extends IPowerManager.Stub
return true;
}

+ private boolean ifSendNoSleepBroadcast() {
+ ActivityManager am = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
+ ComponentName cn = am.getRunningTasks(Integer.MAX_VALUE).get(0).topActivity;
+ if (null != cn && (cn.getClassName()).contains(VINCI_MEDIA_PLAY_ACTIVITY)) {
+ //not true sleep
+ Intent noSleepAction = new Intent("VINCI_MEDIA_PLAY_NOSLEEP_ACTION");
+ if (mContext != null) {
+ mContext.sendBroadcast(noSleepAction);
+ Log.e(TAG, "======I will send broadcast to top activity.\n");
+ return true;
+ }
+ }
+ return false;
+ }
+

@Override // Binder call
public void nap(long eventTime) {
if (eventTime > SystemClock.uptimeMillis()) {
@@ -1799,18 +1826,22 @@ public final class PowerManagerService extends IPowerManager.Stub

// Phase 0: Basic state updates.
updateIsPoweredLocked(mDirty);
+ Slog.e(TAG, "after updateIsPoweredLocked ======\n");
updateStayOnLocked(mDirty);
+ Slog.e(TAG, "after updateStayOnLocked ======\n");

// 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;
+ Slog.e(TAG, "updatePowerStateLocked before for loop ======\n");
for (;;) {
int dirtyPhase1 = mDirty;
dirtyPhase2 |= dirtyPhase1;
mDirty = 0;

+ Slog.e(TAG, "in for loop ======\n");
updateWakeLockSummaryLocked(dirtyPhase1);
updateUserActivitySummaryLocked(now, dirtyPhase1);
if (!updateWakefulnessLocked(dirtyPhase1)) {
@@ -2136,6 +2167,7 @@ else
Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT);
msg.setAsynchronous(true);
mHandler.sendMessageAtTime(msg, nextTimeout);
+ Slog.e(TAG, "PMS send MSG_USER_ACTIVITY_TIMEOUT broadcast======\n");
}
} else {
mUserActivitySummary = 0;
@@ -2181,6 +2213,8 @@ else
Slog.d(TAG, "handleUserActivityTimeout");
}

+ if(!hasVinciWakelock && ifSendNoSleepBroadcast()) return;
+

mDirty |= DIRTY_USER_ACTIVITY;
updatePowerStateLocked();
} else {