diff options
| author | 2014-03-24 20:42:30 +0000 | |
|---|---|---|
| committer | 2014-03-24 20:42:31 +0000 | |
| commit | 43111e897be9f79ababb0ecf99f155695416d956 (patch) | |
| tree | 300af7e364bb12b4e4a34d9bf7356a3489a39cd0 | |
| parent | 48a5dbd3cc5dd8a919983455757dc4c7b82500ab (diff) | |
| parent | 4590e52f3d0558e01322fe4dd55bb612afdfb079 (diff) | |
Merge "Battery stats: wake locks, radio active, cleanup."
9 files changed, 96 insertions, 177 deletions
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index 87beb95479c5..426f21eae3df 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -118,19 +118,14 @@ public abstract class BatteryStats implements Parcelable { public static final int STATS_SINCE_CHARGED = 0; /** - * Include only the last run in the stats. - */ - public static final int STATS_LAST = 1; - - /** * Include only the current run in the stats. */ - public static final int STATS_CURRENT = 2; + public static final int STATS_CURRENT = 1; /** * Include only the run since the last time the device was unplugged in the stats. */ - public static final int STATS_SINCE_UNPLUGGED = 3; + public static final int STATS_SINCE_UNPLUGGED = 2; // NOTE: Update this list if you add/change any stats above. // These characters are supposed to represent "total", "last", "current", diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl index 069285a0509e..d03b0c5ba3e7 100644 --- a/core/java/android/os/IPowerManager.aidl +++ b/core/java/android/os/IPowerManager.aidl @@ -32,7 +32,7 @@ interface IPowerManager void releaseWakeLock(IBinder lock, int flags); void updateWakeLockUids(IBinder lock, in int[] uids); - void updateWakeLockWorkSource(IBinder lock, in WorkSource ws); + void updateWakeLockWorkSource(IBinder lock, in WorkSource ws, String historyTag); boolean isWakeLockLevelSupported(int level); void userActivity(long time, int event, int flags); diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 74ca3bb3874c..a195200177db 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -844,7 +844,7 @@ public final class PowerManager { if (changed && mHeld) { try { - mService.updateWakeLockWorkSource(mToken, mWorkSource); + mService.updateWakeLockWorkSource(mToken, mWorkSource, mHistoryTag); } catch (RemoteException e) { } } diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 1d885338cea3..39636fe6b2c2 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -230,10 +230,8 @@ public final class BatteryStatsImpl extends BatteryStats { long mUptime; long mUptimeStart; - long mLastUptime; long mRealtime; long mRealtimeStart; - long mLastRealtime; int mWakeLockNesting; boolean mWakeLockImportant; @@ -408,9 +406,7 @@ public final class BatteryStatsImpl extends BatteryStats { private final ArrayList<TimeBaseObs> mObservers = new ArrayList<TimeBaseObs>(); private long mUptime; - private long mLastUptime; private long mRealtime; - private long mLastRealtime; private boolean mRunning; @@ -427,14 +423,12 @@ public final class BatteryStatsImpl extends BatteryStats { sb.setLength(0); sb.append(prefix); sb.append("mUptime="); - formatTimeMs(sb, mUptime / 1000); sb.append("mLastUptime="); - formatTimeMs(sb, mLastUptime / 1000); + formatTimeMs(sb, mUptime / 1000); pw.println(sb.toString()); sb.setLength(0); sb.append(prefix); sb.append("mRealtime="); - formatTimeMs(sb, mRealtime / 1000); sb.append("mLastRealtime="); - formatTimeMs(sb, mLastRealtime / 1000); + formatTimeMs(sb, mRealtime / 1000); pw.println(sb.toString()); sb.setLength(0); sb.append(prefix); @@ -489,8 +483,6 @@ public final class BatteryStatsImpl extends BatteryStats { switch (which) { case STATS_SINCE_CHARGED: return mUptime + getUptime(curTime); - case STATS_LAST: - return mLastUptime; case STATS_CURRENT: return getUptime(curTime); case STATS_SINCE_UNPLUGGED: @@ -503,8 +495,6 @@ public final class BatteryStatsImpl extends BatteryStats { switch (which) { case STATS_SINCE_CHARGED: return mRealtime + getRealtime(curTime); - case STATS_LAST: - return mLastRealtime; case STATS_CURRENT: return getRealtime(curTime); case STATS_SINCE_UNPLUGGED: @@ -582,7 +572,6 @@ public final class BatteryStatsImpl extends BatteryStats { public void readFromParcel(Parcel in) { mRunning = false; mUptime = in.readLong(); - mLastUptime = 0; mPastUptime = in.readLong(); mUptimeStart = in.readLong(); mPastRealtime = in.readLong(); @@ -663,16 +652,11 @@ public final class BatteryStatsImpl extends BatteryStats { @Override public int getCountLocked(int which) { - int val; - if (which == STATS_LAST) { - val = mLastCount; - } else { - val = mCount.get(); - if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedCount; - } else if (which != STATS_SINCE_CHARGED) { - val -= mLoadedCount; - } + int val = mCount.get(); + if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedCount; + } else if (which != STATS_SINCE_CHARGED) { + val -= mLoadedCount; } return val; @@ -772,16 +756,11 @@ public final class BatteryStatsImpl extends BatteryStats { } public long getCountLocked(int which) { - long val; - if (which == STATS_LAST) { - val = mLastCount; - } else { - val = mCount; - if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedCount; - } else if (which != STATS_SINCE_CHARGED) { - val -= mLoadedCount; - } + long val = mCount; + if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedCount; + } else if (which != STATS_SINCE_CHARGED) { + val -= mLoadedCount; } return val; @@ -970,16 +949,11 @@ public final class BatteryStatsImpl extends BatteryStats { @Override public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { - long val; - if (which == STATS_LAST) { - val = mLastTime; - } else { - val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); - if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedTime; - } else if (which != STATS_SINCE_CHARGED) { - val -= mLoadedTime; - } + long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); + if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedTime; + } else if (which != STATS_SINCE_CHARGED) { + val -= mLoadedTime; } return val; @@ -987,16 +961,11 @@ public final class BatteryStatsImpl extends BatteryStats { @Override public int getCountLocked(int which) { - int val; - if (which == STATS_LAST) { - val = mLastCount; - } else { - val = computeCurrentCountLocked(); - if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedCount; - } else if (which != STATS_SINCE_CHARGED) { - val -= mLoadedCount; - } + int val = computeCurrentCountLocked(); + if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedCount; + } else if (which != STATS_SINCE_CHARGED) { + val -= mLoadedCount; } return val; @@ -2209,8 +2178,7 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryCur.eventTag = mHistoryCur.localEventTag; mHistoryCur.eventTag.string = name; mHistoryCur.eventTag.uid = uid; - // XXX should be calling addHistoryRecordLocked()? - addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); + addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); } void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { @@ -2797,8 +2765,8 @@ public final class BatteryStatsImpl extends BatteryStats { mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); } else { mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); - mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); updateNetworkActivityLocked(NET_UPDATE_MOBILE, realElapsedRealtimeMs); + mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); } } } @@ -4890,64 +4858,44 @@ public final class BatteryStatsImpl extends BatteryStats { @Override public long getUserTime(int which) { - long val; - if (which == STATS_LAST) { - val = mLastUserTime; - } else { - val = mUserTime; - if (which == STATS_CURRENT) { - val -= mLoadedUserTime; - } else if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedUserTime; - } + long val = mUserTime; + if (which == STATS_CURRENT) { + val -= mLoadedUserTime; + } else if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedUserTime; } return val; } @Override public long getSystemTime(int which) { - long val; - if (which == STATS_LAST) { - val = mLastSystemTime; - } else { - val = mSystemTime; - if (which == STATS_CURRENT) { - val -= mLoadedSystemTime; - } else if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedSystemTime; - } + long val = mSystemTime; + if (which == STATS_CURRENT) { + val -= mLoadedSystemTime; + } else if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedSystemTime; } return val; } @Override public long getForegroundTime(int which) { - long val; - if (which == STATS_LAST) { - val = mLastForegroundTime; - } else { - val = mForegroundTime; - if (which == STATS_CURRENT) { - val -= mLoadedForegroundTime; - } else if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedForegroundTime; - } + long val = mForegroundTime; + if (which == STATS_CURRENT) { + val -= mLoadedForegroundTime; + } else if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedForegroundTime; } return val; } @Override public int getStarts(int which) { - int val; - if (which == STATS_LAST) { - val = mLastStarts; - } else { - val = mStarts; - if (which == STATS_CURRENT) { - val -= mLoadedStarts; - } else if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedStarts; - } + int val = mStarts; + if (which == STATS_CURRENT) { + val -= mLoadedStarts; + } else if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedStarts; } return val; } @@ -5063,16 +5011,11 @@ public final class BatteryStatsImpl extends BatteryStats { @Override public int getWakeups(int which) { - int val; - if (which == STATS_LAST) { - val = mLastWakeups; - } else { - val = mWakeups; - if (which == STATS_CURRENT) { - val -= mLoadedWakeups; - } else if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedWakeups; - } + int val = mWakeups; + if (which == STATS_CURRENT) { + val -= mLoadedWakeups; + } else if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedWakeups; } return val; @@ -5284,51 +5227,33 @@ public final class BatteryStatsImpl extends BatteryStats { @Override public int getLaunches(int which) { - int val; - - if (which == STATS_LAST) { - val = mLastLaunches; - } else { - val = mLaunches; - if (which == STATS_CURRENT) { - val -= mLoadedLaunches; - } else if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedLaunches; - } + int val = mLaunches; + if (which == STATS_CURRENT) { + val -= mLoadedLaunches; + } else if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedLaunches; } - return val; } @Override public long getStartTime(long now, int which) { - long val; - if (which == STATS_LAST) { - val = mLastStartTime; - } else { - val = getStartTimeToNowLocked(now); - if (which == STATS_CURRENT) { - val -= mLoadedStartTime; - } else if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedStartTime; - } + long val = getStartTimeToNowLocked(now); + if (which == STATS_CURRENT) { + val -= mLoadedStartTime; + } else if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedStartTime; } - return val; } @Override public int getStarts(int which) { - int val; - if (which == STATS_LAST) { - val = mLastStarts; - } else { - val = mStarts; - if (which == STATS_CURRENT) { - val -= mLoadedStarts; - } else if (which == STATS_SINCE_UNPLUGGED) { - val -= mUnpluggedStarts; - } + int val = mStarts; + if (which == STATS_CURRENT) { + val -= mLoadedStarts; + } else if (which == STATS_SINCE_UNPLUGGED) { + val -= mUnpluggedStarts; } return val; @@ -5591,8 +5516,6 @@ public final class BatteryStatsImpl extends BatteryStats { long uptime = SystemClock.uptimeMillis() * 1000; long realtime = SystemClock.elapsedRealtime() * 1000; initTimes(uptime, realtime); - mUptimeStart = uptime; - mRealtimeStart = realtime; mDischargeStartLevel = 0; mDischargeUnplugLevel = 0; mDischargeCurrentLevel = 0; @@ -5772,8 +5695,10 @@ public final class BatteryStatsImpl extends BatteryStats { mStartClockTime = System.currentTimeMillis(); mOnBatteryTimeBase.init(uptime, realtime); mOnBatteryScreenOffTimeBase.init(uptime, realtime); - mUptimeStart = uptime; + mRealtime = 0; + mUptime = 0; mRealtimeStart = realtime; + mUptimeStart = uptime; } void initDischarge() { @@ -6256,9 +6181,8 @@ public final class BatteryStatsImpl extends BatteryStats { public long computeUptime(long curTime, int which) { switch (which) { case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); - case STATS_LAST: return mLastUptime; case STATS_CURRENT: return (curTime-mUptimeStart); - case STATS_SINCE_UNPLUGGED: return (curTime- mOnBatteryTimeBase.getUptimeStart()); + case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); } return 0; } @@ -6267,9 +6191,8 @@ public final class BatteryStatsImpl extends BatteryStats { public long computeRealtime(long curTime, int which) { switch (which) { case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); - case STATS_LAST: return mLastRealtime; case STATS_CURRENT: return (curTime-mRealtimeStart); - case STATS_SINCE_UNPLUGGED: return (curTime- mOnBatteryTimeBase.getRealtimeStart()); + case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); } return 0; } @@ -7303,10 +7226,8 @@ public final class BatteryStatsImpl extends BatteryStats { mStartClockTime = in.readLong(); mUptime = in.readLong(); mUptimeStart = in.readLong(); - mLastUptime = 0; mRealtime = in.readLong(); mRealtimeStart = in.readLong(); - mLastRealtime = 0; mOnBattery = in.readInt() != 0; mOnBatteryInternal = false; // we are no longer really running. mOnBatteryTimeBase.readFromParcel(in); diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java index 41ffdc18ef13..168742f0d90d 100644 --- a/services/core/java/com/android/server/AlarmManagerService.java +++ b/services/core/java/com/android/server/AlarmManagerService.java @@ -1348,25 +1348,22 @@ class AlarmManagerService extends SystemService { try { final boolean unimportant = pi == mTimeTickSender; mWakeLock.setUnimportantForLogging(unimportant); + if (first || mLastWakeLockUnimportantForLogging) { + mWakeLock.setHistoryTag(pi.getTag( + type == ELAPSED_REALTIME_WAKEUP || type == RTC_WAKEUP + ? "*walarm*:" : "*alarm*:")); + } else { + mWakeLock.setHistoryTag(null); + } + mLastWakeLockUnimportantForLogging = unimportant; if (ws != null) { - if (first || mLastWakeLockUnimportantForLogging) { - mWakeLock.setHistoryTag(pi.getTag( - type == ELAPSED_REALTIME_WAKEUP || type == RTC_WAKEUP - ? "*walarm*:" : "*alarm*:")); - } else { - mWakeLock.setHistoryTag(null); - } - mLastWakeLockUnimportantForLogging = unimportant; mWakeLock.setWorkSource(ws); return; - } else { - mLastWakeLockUnimportantForLogging = false; } final int uid = ActivityManagerNative.getDefault() .getUidForIntentSender(pi.getTarget()); if (uid >= 0) { - mWakeLock.setHistoryTag(null); mWakeLock.setWorkSource(new WorkSource(uid)); return; } diff --git a/services/core/java/com/android/server/NativeDaemonConnector.java b/services/core/java/com/android/server/NativeDaemonConnector.java index 265b95704bbb..62eb6632eb5a 100644 --- a/services/core/java/com/android/server/NativeDaemonConnector.java +++ b/services/core/java/com/android/server/NativeDaemonConnector.java @@ -110,7 +110,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo } catch (Exception e) { loge("Error handling '" + event + "': " + e); } finally { - if (mCallbacks.onCheckHoldWakeLock(msg.what)) { + if (mCallbacks.onCheckHoldWakeLock(msg.what) && mWakeLock != null) { mWakeLock.release(); } } @@ -171,7 +171,8 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo rawEvent); if (event.isClassUnsolicited()) { // TODO: migrate to sending NativeDaemonEvent instances - if (mCallbacks.onCheckHoldWakeLock(event.getCode())) { + if (mCallbacks.onCheckHoldWakeLock(event.getCode()) + && mWakeLock != null) { mWakeLock.acquire(); releaseWl = true; } diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java index 75c1e8f1ca25..9629bd1d02df 100644 --- a/services/core/java/com/android/server/NetworkManagementService.java +++ b/services/core/java/com/android/server/NetworkManagementService.java @@ -208,7 +208,11 @@ public class NetworkManagementService extends INetworkManagementService.Stub } PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); - PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NETD_TAG); + // Don't need this wake lock, since we now have a time stamp for when + // the network actually went inactive. (It might be nice to still do this, + // but I don't want to do it through the power manager because that pollutes the + // battery stats history with pointless noise.) + PowerManager.WakeLock wl = null; //pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NETD_TAG); mConnector = new NativeDaemonConnector( new NetdCallbackReceiver(), socket, 10, NETD_TAG, 160, wl); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 239e423b469e..5fa908412fde 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -15618,7 +15618,7 @@ public final class ActivityManagerService extends ActivityManagerNative ActivityRecord act = mStackSupervisor.resumedAppLocked(); String pkg; int uid; - if (act != null) { + if (act != null && !act.sleeping) { pkg = act.packageName; uid = act.info.applicationInfo.uid; } else { diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index fab972f7f965..a3883182d599 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -747,7 +747,7 @@ public final class PowerManagerService extends com.android.server.SystemService } } - private void updateWakeLockWorkSourceInternal(IBinder lock, WorkSource ws) { + private void updateWakeLockWorkSourceInternal(IBinder lock, WorkSource ws, String historyTag) { synchronized (mLock) { int index = findWakeLockIndexLocked(lock); if (index < 0) { @@ -767,7 +767,8 @@ public final class PowerManagerService extends com.android.server.SystemService if (!wakeLock.hasSameWorkSource(ws)) { notifyWakeLockChangingLocked(wakeLock, wakeLock.mFlags, wakeLock.mTag, wakeLock.mPackageName, wakeLock.mOwnerUid, wakeLock.mOwnerPid, - ws, wakeLock.mHistoryTag); + ws, historyTag); + wakeLock.mHistoryTag = historyTag; wakeLock.updateWorkSource(ws); } } @@ -2600,11 +2601,11 @@ public final class PowerManagerService extends com.android.server.SystemService ws.add(uids[i]); } } - updateWakeLockWorkSource(lock, ws); + updateWakeLockWorkSource(lock, ws, null); } @Override // Binder call - public void updateWakeLockWorkSource(IBinder lock, WorkSource ws) { + public void updateWakeLockWorkSource(IBinder lock, WorkSource ws, String historyTag) { if (lock == null) { throw new IllegalArgumentException("lock must not be null"); } @@ -2619,7 +2620,7 @@ public final class PowerManagerService extends com.android.server.SystemService final long ident = Binder.clearCallingIdentity(); try { - updateWakeLockWorkSourceInternal(lock, ws); + updateWakeLockWorkSourceInternal(lock, ws, historyTag); } finally { Binder.restoreCallingIdentity(ident); } |