Fix problems with determining when to kill apps for wake usage.
Also improve debug printing of various times.
Change-Id: Ifcc288fd1bcbf44c069875ba97925b9e7ffe9a48
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 2f26135..2a5b944 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -27,7 +27,6 @@
import android.os.Parcelable;
import android.os.Process;
import android.os.SystemClock;
-import android.os.BatteryStats.Uid.Proc.ExcessiveWake;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
@@ -1241,25 +1240,31 @@
int mWakeLockNesting;
public void noteStartWakeLocked(int uid, int pid, String name, int type) {
- if (mWakeLockNesting == 0) {
- mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG;
- if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: "
- + Integer.toHexString(mHistoryCur.states));
- addHistoryRecordLocked(SystemClock.elapsedRealtime());
+ if (type == WAKE_TYPE_PARTIAL) {
+ // Only care about partial wake locks, since full wake locks
+ // will be canceled when the user puts the screen to sleep.
+ if (mWakeLockNesting == 0) {
+ mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG;
+ if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: "
+ + Integer.toHexString(mHistoryCur.states));
+ addHistoryRecordLocked(SystemClock.elapsedRealtime());
+ }
+ mWakeLockNesting++;
}
- mWakeLockNesting++;
if (uid >= 0) {
getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type);
}
}
public void noteStopWakeLocked(int uid, int pid, String name, int type) {
- mWakeLockNesting--;
- if (mWakeLockNesting == 0) {
- mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG;
- if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: "
- + Integer.toHexString(mHistoryCur.states));
- addHistoryRecordLocked(SystemClock.elapsedRealtime());
+ if (type == WAKE_TYPE_PARTIAL) {
+ mWakeLockNesting--;
+ if (mWakeLockNesting == 0) {
+ mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG;
+ if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: "
+ + Integer.toHexString(mHistoryCur.states));
+ addHistoryRecordLocked(SystemClock.elapsedRealtime());
+ }
}
if (uid >= 0) {
getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type);
@@ -1353,7 +1358,7 @@
// Fake a wake lock, so we consider the device waked as long
// as the screen is on.
- noteStartWakeLocked(-1, -1, "dummy", 0);
+ noteStartWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL);
}
}
@@ -1369,7 +1374,7 @@
mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(this);
}
- noteStopWakeLocked(-1, -1, "dummy", 0);
+ noteStopWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL);
}
}
@@ -3463,7 +3468,7 @@
if (t != null) {
t.startRunningLocked(BatteryStatsImpl.this);
}
- if (pid >= 0) {
+ if (pid >= 0 && type == WAKE_TYPE_PARTIAL) {
Pid p = getPidStatsLocked(pid);
p.mWakeStart = SystemClock.elapsedRealtime();
}
@@ -3474,7 +3479,7 @@
if (t != null) {
t.stopRunningLocked(BatteryStatsImpl.this);
}
- if (pid >= 0) {
+ if (pid >= 0 && type == WAKE_TYPE_PARTIAL) {
Pid p = mPids.get(pid);
if (p != null) {
p.mWakeSum += SystemClock.elapsedRealtime() - p.mWakeStart;