summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2014-03-08 14:39:10 -0800
committerDianne Hackborn <hackbod@google.com>2014-03-11 10:02:40 -0700
commite5167ca61e2c5607aad9041b44158581bc61b4d8 (patch)
tree6acca96f495bd7f55903b5ab6552e2ae1b075783 /services
parent30df0be25410dab7ed2074ed169ec5d7953fde1e (diff)
downloadframeworks_base-e5167ca61e2c5607aad9041b44158581bc61b4d8.zip
frameworks_base-e5167ca61e2c5607aad9041b44158581bc61b4d8.tar.gz
frameworks_base-e5167ca61e2c5607aad9041b44158581bc61b4d8.tar.bz2
Reduce wake lock noise in battery history.
When the work source of a wake lock was changed, this would cause the old wake lock to be released in battery stats before the new one was acquired (the power manager would correctly keep holding the associated wake lock). This resulted in a pointless entry in the battery history showing the last wake lock being released and a new one acquired. This change adds a new path in to battery stats to report when a wake lock has changed, allowing it to acquire the new wake locks first before the old ones, so it can't drop down to zero wake locks. This also provides better timing information, as the same current time can be used for both operations. In addition, added a new kind of history entry for the current time, so you can tell when in actual world clock time the battery data is happening. Change-Id: Ibbf2eed83bb93f31f60267889b7bc5b9e71e355f
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/AlarmManagerService.java30
-rw-r--r--services/core/java/com/android/server/am/BatteryStatsService.java16
-rw-r--r--services/core/java/com/android/server/power/Notifier.java33
-rw-r--r--services/core/java/com/android/server/power/PowerManagerService.java18
4 files changed, 80 insertions, 17 deletions
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java
index bda0183..9de3efe 100644
--- a/services/core/java/com/android/server/AlarmManagerService.java
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -426,8 +426,10 @@ class AlarmManagerService extends SystemService {
final Pair<String, ComponentName> mTarget;
final BroadcastStats mBroadcastStats;
final FilterStats mFilterStats;
+ final int mAlarmType;
- InFlight(AlarmManagerService service, PendingIntent pendingIntent, WorkSource workSource) {
+ InFlight(AlarmManagerService service, PendingIntent pendingIntent, WorkSource workSource,
+ int alarmType) {
mPendingIntent = pendingIntent;
mWorkSource = workSource;
Intent intent = pendingIntent.getIntent();
@@ -441,6 +443,7 @@ class AlarmManagerService extends SystemService {
mBroadcastStats.filterStats.put(mTarget, fs);
}
mFilterStats = fs;
+ mAlarmType = alarmType;
}
}
@@ -1280,17 +1283,12 @@ class AlarmManagerService extends SystemService {
// we have an active broadcast so stay awake.
if (mBroadcastRefCount == 0) {
- setWakelockWorkSource(alarm.operation, alarm.workSource);
- mWakeLock.setUnimportantForLogging(
- alarm.operation == mTimeTickSender);
- mWakeLock.setHistoryTag(alarm.operation.getTag(
- alarm.type == ELAPSED_REALTIME_WAKEUP
- || alarm.type == RTC_WAKEUP
- ? "*walarm*:" : "*alarm*:"));
+ setWakelockWorkSource(alarm.operation, alarm.workSource,
+ alarm.type, true);
mWakeLock.acquire();
}
final InFlight inflight = new InFlight(AlarmManagerService.this,
- alarm.operation, alarm.workSource);
+ alarm.operation, alarm.workSource, alarm.type);
mInFlight.add(inflight);
mBroadcastRefCount++;
@@ -1345,9 +1343,17 @@ class AlarmManagerService extends SystemService {
* @param pi PendingIntent to attribute blame to if ws is null.
* @param ws WorkSource to attribute blame.
*/
- void setWakelockWorkSource(PendingIntent pi, WorkSource ws) {
+ void setWakelockWorkSource(PendingIntent pi, WorkSource ws, int type, boolean first) {
try {
+ mWakeLock.setUnimportantForLogging(pi == mTimeTickSender);
if (ws != null) {
+ if (first) {
+ mWakeLock.setHistoryTag(pi.getTag(
+ type == ELAPSED_REALTIME_WAKEUP || type == RTC_WAKEUP
+ ? "*walarm*:" : "*alarm*:"));
+ } else {
+ mWakeLock.setHistoryTag(null);
+ }
mWakeLock.setWorkSource(ws);
return;
}
@@ -1355,6 +1361,7 @@ class AlarmManagerService extends SystemService {
final int uid = ActivityManagerNative.getDefault()
.getUidForIntentSender(pi.getTarget());
if (uid >= 0) {
+ mWakeLock.setHistoryTag(null);
mWakeLock.setWorkSource(new WorkSource(uid));
return;
}
@@ -1579,7 +1586,8 @@ class AlarmManagerService extends SystemService {
// the next of our alarms is now in flight. reattribute the wakelock.
if (mInFlight.size() > 0) {
InFlight inFlight = mInFlight.get(0);
- setWakelockWorkSource(inFlight.mPendingIntent, inFlight.mWorkSource);
+ setWakelockWorkSource(inFlight.mPendingIntent, inFlight.mWorkSource,
+ inFlight.mAlarmType, false);
} else {
// should never happen
mLog.w("Alarm wakelock still held but sent queue empty");
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index 39bfc23..3414daf 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -29,6 +29,7 @@ import android.os.IBinder;
import android.os.Parcel;
import android.os.Process;
import android.os.ServiceManager;
+import android.os.SystemClock;
import android.os.UserHandle;
import android.os.WorkSource;
import android.telephony.SignalStrength;
@@ -133,14 +134,15 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
boolean unimportantForLogging) {
enforceCallingPermission();
synchronized (mStats) {
- mStats.noteStartWakeLocked(uid, pid, name, historyName, type, unimportantForLogging);
+ mStats.noteStartWakeLocked(uid, pid, name, historyName, type, unimportantForLogging,
+ SystemClock.elapsedRealtime());
}
}
public void noteStopWakelock(int uid, int pid, String name, int type) {
enforceCallingPermission();
synchronized (mStats) {
- mStats.noteStopWakeLocked(uid, pid, name, type);
+ mStats.noteStopWakeLocked(uid, pid, name, type, SystemClock.elapsedRealtime());
}
}
@@ -153,6 +155,16 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
}
}
+ public void noteChangeWakelockFromSource(WorkSource ws, int pid, String name, int type,
+ WorkSource newWs, int newPid, String newName,
+ String newHistoryName, int newType, boolean newUnimportantForLogging) {
+ enforceCallingPermission();
+ synchronized (mStats) {
+ mStats.noteChangeWakelockFromSourceLocked(ws, pid, name, type,
+ newWs, newPid, newName, newHistoryName, newType, newUnimportantForLogging);
+ }
+ }
+
public void noteStopWakelockFromSource(WorkSource ws, int pid, String name, int type) {
enforceCallingPermission();
synchronized (mStats) {
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
index e1ccf46..df06bae 100644
--- a/services/core/java/com/android/server/power/Notifier.java
+++ b/services/core/java/com/android/server/power/Notifier.java
@@ -158,6 +158,39 @@ final class Notifier {
}
/**
+ * Called when a wake lock is changing.
+ */
+ public void onWakeLockChanging(int flags, String tag, String packageName,
+ int ownerUid, int ownerPid, WorkSource workSource, String historyTag,
+ int newFlags, String newTag, String newPackageName, int newOwnerUid,
+ int newOwnerPid, WorkSource newWorkSource, String newHistoryTag) {
+
+ final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
+ final int newMonitorType = getBatteryStatsWakeLockMonitorType(newFlags);
+ boolean unimportantForLogging = (flags&PowerManager.UNIMPORTANT_FOR_LOGGING) != 0
+ && ownerUid == Process.SYSTEM_UID;
+ if (workSource != null && newWorkSource != null) {
+ if (DEBUG) {
+ Slog.d(TAG, "onWakeLockChanging: flags=" + newFlags + ", tag=\"" + newTag
+ + "\", packageName=" + newPackageName
+ + ", ownerUid=" + newOwnerUid + ", ownerPid=" + newOwnerPid
+ + ", workSource=" + newWorkSource);
+ }
+ try {
+ mBatteryStats.noteChangeWakelockFromSource(workSource, ownerPid, tag, monitorType,
+ newWorkSource, newOwnerPid, newTag, newHistoryTag,
+ newMonitorType, unimportantForLogging);
+ } catch (RemoteException ex) {
+ // Ignore
+ }
+ } else {
+ onWakeLockReleased(flags, tag, packageName, ownerUid, ownerPid, workSource);
+ onWakeLockAcquired(newFlags, newTag, newPackageName, newOwnerUid, newOwnerPid,
+ newWorkSource, newHistoryTag);
+ }
+ }
+
+ /**
* Called when a wake lock is released.
*/
public void onWakeLockReleased(int flags, String tag, String packageName,
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index e7bbf1c..40ebe8d 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -646,9 +646,9 @@ public final class PowerManagerService extends com.android.server.SystemService
wakeLock = mWakeLocks.get(index);
if (!wakeLock.hasSameProperties(flags, tag, ws, uid, pid)) {
// Update existing wake lock. This shouldn't happen but is harmless.
- notifyWakeLockReleasedLocked(wakeLock);
+ notifyWakeLockChangingLocked(wakeLock, flags, tag, packageName,
+ uid, pid, ws, historyTag);
wakeLock.updateProperties(flags, tag, packageName, ws, historyTag, uid, pid);
- notifyWakeLockAcquiredLocked(wakeLock);
}
} else {
wakeLock = new WakeLock(lock, flags, tag, packageName, ws, historyTag, uid, pid);
@@ -765,9 +765,10 @@ public final class PowerManagerService extends com.android.server.SystemService
}
if (!wakeLock.hasSameWorkSource(ws)) {
- notifyWakeLockReleasedLocked(wakeLock);
+ notifyWakeLockChangingLocked(wakeLock, wakeLock.mFlags, wakeLock.mTag,
+ wakeLock.mPackageName, wakeLock.mOwnerUid, wakeLock.mOwnerPid,
+ ws, wakeLock.mHistoryTag);
wakeLock.updateWorkSource(ws);
- notifyWakeLockAcquiredLocked(wakeLock);
}
}
}
@@ -791,6 +792,15 @@ public final class PowerManagerService extends com.android.server.SystemService
}
}
+ private void notifyWakeLockChangingLocked(WakeLock wakeLock, int flags, String tag,
+ String packageName, int uid, int pid, WorkSource ws, String historyTag) {
+ if (mSystemReady && wakeLock.mNotifiedAcquired) {
+ mNotifier.onWakeLockChanging(wakeLock.mFlags, wakeLock.mTag, wakeLock.mPackageName,
+ wakeLock.mOwnerUid, wakeLock.mOwnerPid, wakeLock.mWorkSource,
+ wakeLock.mHistoryTag, flags, tag, packageName, uid, pid, ws, historyTag);
+ }
+ }
+
private void notifyWakeLockReleasedLocked(WakeLock wakeLock) {
if (mSystemReady && wakeLock.mNotifiedAcquired) {
wakeLock.mNotifiedAcquired = false;