summaryrefslogtreecommitdiffstats
path: root/services/core/java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2014-03-11 22:59:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-03-11 22:59:21 +0000
commit5c719495724987a405e29b1623dfe613e9a4cdf5 (patch)
tree63541d2aa82f0e2149a05b51754fed301fcb08a4 /services/core/java
parent3484dff61d0bc91a26f7663dc94917394dda505d (diff)
parente5167ca61e2c5607aad9041b44158581bc61b4d8 (diff)
downloadframeworks_base-5c719495724987a405e29b1623dfe613e9a4cdf5.zip
frameworks_base-5c719495724987a405e29b1623dfe613e9a4cdf5.tar.gz
frameworks_base-5c719495724987a405e29b1623dfe613e9a4cdf5.tar.bz2
Merge "Reduce wake lock noise in battery history."
Diffstat (limited to 'services/core/java')
-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;