Loading core/java/android/os/BatteryStats.java +0 −4 Original line number Original line Diff line number Diff line Loading @@ -346,10 +346,6 @@ public abstract class BatteryStats implements Parcelable { public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); public abstract void noteAudioTurnedOnLocked(long elapsedRealtime); public abstract void noteAudioTurnedOffLocked(long elapsedRealtime); public abstract void noteVideoTurnedOnLocked(long elapsedRealtime); public abstract void noteVideoTurnedOffLocked(long elapsedRealtime); public abstract void noteActivityResumedLocked(long elapsedRealtime); public abstract void noteActivityResumedLocked(long elapsedRealtime); public abstract void noteActivityPausedLocked(long elapsedRealtime); public abstract void noteActivityPausedLocked(long elapsedRealtime); public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); Loading core/java/com/android/internal/app/IBatteryStats.aidl +2 −0 Original line number Original line Diff line number Diff line Loading @@ -31,6 +31,8 @@ interface IBatteryStats { void noteStopVideo(int uid); void noteStopVideo(int uid); void noteStartAudio(int uid); void noteStartAudio(int uid); void noteStopAudio(int uid); void noteStopAudio(int uid); void noteResetVideo(); void noteResetAudio(); // Remaining methods are only used in Java. // Remaining methods are only used in Java. byte[] getStatistics(); byte[] getStatistics(); Loading core/java/com/android/internal/os/BatteryStatsImpl.java +83 −47 Original line number Original line Diff line number Diff line Loading @@ -172,6 +172,8 @@ public final class BatteryStatsImpl extends BatteryStats { final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<StopwatchTimer>(); final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<StopwatchTimer>(); final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<ArrayList<StopwatchTimer>>(); new SparseArray<ArrayList<StopwatchTimer>>(); final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<StopwatchTimer>(); final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<StopwatchTimer>(); // Last partial timers we use for distributing CPU usage. // Last partial timers we use for distributing CPU usage. final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<StopwatchTimer>(); final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<StopwatchTimer>(); Loading Loading @@ -256,10 +258,10 @@ public final class BatteryStatsImpl extends BatteryStats { boolean mPhoneOn; boolean mPhoneOn; StopwatchTimer mPhoneOnTimer; StopwatchTimer mPhoneOnTimer; boolean mAudioOn; int mAudioOnNesting; StopwatchTimer mAudioOnTimer; StopwatchTimer mAudioOnTimer; boolean mVideoOn; int mVideoOnNesting; StopwatchTimer mVideoOnTimer; StopwatchTimer mVideoOnTimer; boolean mFlashlightOn; boolean mFlashlightOn; Loading Loading @@ -1472,6 +1474,13 @@ public final class BatteryStatsImpl extends BatteryStats { } } } } void stopAllRunningLocked(long elapsedRealtimeMs) { if (mNesting > 0) { mNesting = 1; stopRunningLocked(elapsedRealtimeMs); } } // Update the total time for all other running Timers with the same type as this Timer // Update the total time for all other running Timers with the same type as this Timer // due to a change in timer count // due to a change in timer count private static long refreshTimersLocked(long batteryRealtime, private static long refreshTimersLocked(long batteryRealtime, Loading Loading @@ -3187,27 +3196,29 @@ public final class BatteryStatsImpl extends BatteryStats { uid = mapUid(uid); uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long uptime = SystemClock.uptimeMillis(); if (!mAudioOn) { if (mAudioOnNesting == 0) { mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " + Integer.toHexString(mHistoryCur.states)); + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); addHistoryRecordLocked(elapsedRealtime, uptime); mAudioOn = true; mAudioOnTimer.startRunningLocked(elapsedRealtime); mAudioOnTimer.startRunningLocked(elapsedRealtime); } } mAudioOnNesting++; getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); } } public void noteAudioOffLocked(int uid) { public void noteAudioOffLocked(int uid) { if (mAudioOnNesting == 0) { return; } uid = mapUid(uid); uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long uptime = SystemClock.uptimeMillis(); if (mAudioOn) { if (--mAudioOnNesting == 0) { mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " + Integer.toHexString(mHistoryCur.states)); + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); addHistoryRecordLocked(elapsedRealtime, uptime); mAudioOn = false; mAudioOnTimer.stopRunningLocked(elapsedRealtime); mAudioOnTimer.stopRunningLocked(elapsedRealtime); } } getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); Loading @@ -3217,32 +3228,68 @@ public final class BatteryStatsImpl extends BatteryStats { uid = mapUid(uid); uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long uptime = SystemClock.uptimeMillis(); if (!mVideoOn) { if (mVideoOnNesting == 0) { mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " + Integer.toHexString(mHistoryCur.states)); + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); addHistoryRecordLocked(elapsedRealtime, uptime); mVideoOn = true; mVideoOnTimer.startRunningLocked(elapsedRealtime); mVideoOnTimer.startRunningLocked(elapsedRealtime); } } mVideoOnNesting++; getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); } } public void noteVideoOffLocked(int uid) { public void noteVideoOffLocked(int uid) { if (mVideoOnNesting == 0) { return; } uid = mapUid(uid); uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long uptime = SystemClock.uptimeMillis(); if (mVideoOn) { if (--mVideoOnNesting == 0) { mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " + Integer.toHexString(mHistoryCur.states)); + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); addHistoryRecordLocked(elapsedRealtime, uptime); mVideoOn = false; mVideoOnTimer.stopRunningLocked(elapsedRealtime); mVideoOnTimer.stopRunningLocked(elapsedRealtime); } } getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); } } public void noteResetAudioLocked() { if (mAudioOnNesting > 0) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); mAudioOnNesting = 0; mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); for (int i=0; i<mUidStats.size(); i++) { BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); uid.noteResetAudioLocked(elapsedRealtime); } } } public void noteResetVideoLocked() { if (mVideoOnNesting > 0) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); mAudioOnNesting = 0; mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); for (int i=0; i<mUidStats.size(); i++) { BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); uid.noteResetVideoLocked(elapsedRealtime); } } } public void noteActivityResumedLocked(int uid) { public void noteActivityResumedLocked(int uid) { uid = mapUid(uid); uid = mapUid(uid); getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); Loading Loading @@ -3855,10 +3902,7 @@ public final class BatteryStatsImpl extends BatteryStats { boolean mWifiMulticastEnabled; boolean mWifiMulticastEnabled; StopwatchTimer mWifiMulticastTimer; StopwatchTimer mWifiMulticastTimer; boolean mAudioTurnedOn; StopwatchTimer mAudioTurnedOnTimer; StopwatchTimer mAudioTurnedOnTimer; boolean mVideoTurnedOn; StopwatchTimer mVideoTurnedOnTimer; StopwatchTimer mVideoTurnedOnTimer; StopwatchTimer mForegroundActivityTimer; StopwatchTimer mForegroundActivityTimer; Loading Loading @@ -4073,53 +4117,49 @@ public final class BatteryStatsImpl extends BatteryStats { public StopwatchTimer createAudioTurnedOnTimerLocked() { public StopwatchTimer createAudioTurnedOnTimerLocked() { if (mAudioTurnedOnTimer == null) { if (mAudioTurnedOnTimer == null) { mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, null, mOnBatteryTimeBase); mAudioTurnedOnTimers, mOnBatteryTimeBase); } } return mAudioTurnedOnTimer; return mAudioTurnedOnTimer; } } @Override public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { if (!mAudioTurnedOn) { mAudioTurnedOn = true; createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); } } } @Override public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { if (mAudioTurnedOn) { mAudioTurnedOn = false; if (mAudioTurnedOnTimer != null) { if (mAudioTurnedOnTimer != null) { mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); } } } } public void noteResetAudioLocked(long elapsedRealtimeMs) { if (mAudioTurnedOnTimer != null) { mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); } } } public StopwatchTimer createVideoTurnedOnTimerLocked() { public StopwatchTimer createVideoTurnedOnTimerLocked() { if (mVideoTurnedOnTimer == null) { if (mVideoTurnedOnTimer == null) { mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, null, mOnBatteryTimeBase); mVideoTurnedOnTimers, mOnBatteryTimeBase); } } return mVideoTurnedOnTimer; return mVideoTurnedOnTimer; } } @Override public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { if (!mVideoTurnedOn) { mVideoTurnedOn = true; createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); } } } @Override public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { if (mVideoTurnedOn) { mVideoTurnedOn = false; if (mVideoTurnedOnTimer != null) { if (mVideoTurnedOnTimer != null) { mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); } } } } public void noteResetVideoLocked(long elapsedRealtimeMs) { if (mVideoTurnedOnTimer != null) { mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); } } } public StopwatchTimer createForegroundActivityTimerLocked() { public StopwatchTimer createForegroundActivityTimerLocked() { Loading Loading @@ -4416,11 +4456,9 @@ public final class BatteryStatsImpl extends BatteryStats { } } if (mAudioTurnedOnTimer != null) { if (mAudioTurnedOnTimer != null) { active |= !mAudioTurnedOnTimer.reset(false); active |= !mAudioTurnedOnTimer.reset(false); active |= mAudioTurnedOn; } } if (mVideoTurnedOnTimer != null) { if (mVideoTurnedOnTimer != null) { active |= !mVideoTurnedOnTimer.reset(false); active |= !mVideoTurnedOnTimer.reset(false); active |= mVideoTurnedOn; } } if (mForegroundActivityTimer != null) { if (mForegroundActivityTimer != null) { active |= !mForegroundActivityTimer.reset(false); active |= !mForegroundActivityTimer.reset(false); Loading Loading @@ -4803,17 +4841,15 @@ public final class BatteryStatsImpl extends BatteryStats { } else { } else { mWifiMulticastTimer = null; mWifiMulticastTimer = null; } } mAudioTurnedOn = false; if (in.readInt() != 0) { if (in.readInt() != 0) { mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, null, mOnBatteryTimeBase, in); mAudioTurnedOnTimers, mOnBatteryTimeBase, in); } else { } else { mAudioTurnedOnTimer = null; mAudioTurnedOnTimer = null; } } mVideoTurnedOn = false; if (in.readInt() != 0) { if (in.readInt() != 0) { mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, null, mOnBatteryTimeBase, in); mVideoTurnedOnTimers, mOnBatteryTimeBase, in); } else { } else { mVideoTurnedOnTimer = null; mVideoTurnedOnTimer = null; } } Loading Loading @@ -7554,11 +7590,9 @@ public final class BatteryStatsImpl extends BatteryStats { if (in.readInt() != 0) { if (in.readInt() != 0) { u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); } } u.mAudioTurnedOn = false; if (in.readInt() != 0) { if (in.readInt() != 0) { u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); } } u.mVideoTurnedOn = false; if (in.readInt() != 0) { if (in.readInt() != 0) { u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); } } Loading Loading @@ -8071,9 +8105,9 @@ public final class BatteryStatsImpl extends BatteryStats { mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, null, mOnBatteryTimeBase, in); null, mOnBatteryTimeBase, in); } } mAudioOn = false; mAudioOnNesting = 0; mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); mVideoOn = false; mVideoOnNesting = 0; mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); mFlashlightOn = false; mFlashlightOn = false; mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); Loading Loading @@ -8125,6 +8159,8 @@ public final class BatteryStatsImpl extends BatteryStats { mWifiScanTimers.clear(); mWifiScanTimers.clear(); mWifiBatchedScanTimers.clear(); mWifiBatchedScanTimers.clear(); mWifiMulticastTimers.clear(); mWifiMulticastTimers.clear(); mAudioTurnedOnTimers.clear(); mVideoTurnedOnTimers.clear(); sNumSpeedSteps = in.readInt(); sNumSpeedSteps = in.readInt(); Loading services/core/java/com/android/server/am/BatteryStatsService.java +14 −0 Original line number Original line Diff line number Diff line Loading @@ -413,6 +413,20 @@ public final class BatteryStatsService extends IBatteryStats.Stub } } } } public void noteResetAudio() { enforceCallingPermission(); synchronized (mStats) { mStats.noteResetAudioLocked(); } } public void noteResetVideo() { enforceCallingPermission(); synchronized (mStats) { mStats.noteResetVideoLocked(); } } public void noteFlashlightOn() { public void noteFlashlightOn() { enforceCallingPermission(); enforceCallingPermission(); synchronized (mStats) { synchronized (mStats) { Loading Loading
core/java/android/os/BatteryStats.java +0 −4 Original line number Original line Diff line number Diff line Loading @@ -346,10 +346,6 @@ public abstract class BatteryStats implements Parcelable { public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); public abstract void noteAudioTurnedOnLocked(long elapsedRealtime); public abstract void noteAudioTurnedOffLocked(long elapsedRealtime); public abstract void noteVideoTurnedOnLocked(long elapsedRealtime); public abstract void noteVideoTurnedOffLocked(long elapsedRealtime); public abstract void noteActivityResumedLocked(long elapsedRealtime); public abstract void noteActivityResumedLocked(long elapsedRealtime); public abstract void noteActivityPausedLocked(long elapsedRealtime); public abstract void noteActivityPausedLocked(long elapsedRealtime); public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); Loading
core/java/com/android/internal/app/IBatteryStats.aidl +2 −0 Original line number Original line Diff line number Diff line Loading @@ -31,6 +31,8 @@ interface IBatteryStats { void noteStopVideo(int uid); void noteStopVideo(int uid); void noteStartAudio(int uid); void noteStartAudio(int uid); void noteStopAudio(int uid); void noteStopAudio(int uid); void noteResetVideo(); void noteResetAudio(); // Remaining methods are only used in Java. // Remaining methods are only used in Java. byte[] getStatistics(); byte[] getStatistics(); Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +83 −47 Original line number Original line Diff line number Diff line Loading @@ -172,6 +172,8 @@ public final class BatteryStatsImpl extends BatteryStats { final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<StopwatchTimer>(); final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<StopwatchTimer>(); final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<ArrayList<StopwatchTimer>>(); new SparseArray<ArrayList<StopwatchTimer>>(); final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<StopwatchTimer>(); final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<StopwatchTimer>(); // Last partial timers we use for distributing CPU usage. // Last partial timers we use for distributing CPU usage. final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<StopwatchTimer>(); final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<StopwatchTimer>(); Loading Loading @@ -256,10 +258,10 @@ public final class BatteryStatsImpl extends BatteryStats { boolean mPhoneOn; boolean mPhoneOn; StopwatchTimer mPhoneOnTimer; StopwatchTimer mPhoneOnTimer; boolean mAudioOn; int mAudioOnNesting; StopwatchTimer mAudioOnTimer; StopwatchTimer mAudioOnTimer; boolean mVideoOn; int mVideoOnNesting; StopwatchTimer mVideoOnTimer; StopwatchTimer mVideoOnTimer; boolean mFlashlightOn; boolean mFlashlightOn; Loading Loading @@ -1472,6 +1474,13 @@ public final class BatteryStatsImpl extends BatteryStats { } } } } void stopAllRunningLocked(long elapsedRealtimeMs) { if (mNesting > 0) { mNesting = 1; stopRunningLocked(elapsedRealtimeMs); } } // Update the total time for all other running Timers with the same type as this Timer // Update the total time for all other running Timers with the same type as this Timer // due to a change in timer count // due to a change in timer count private static long refreshTimersLocked(long batteryRealtime, private static long refreshTimersLocked(long batteryRealtime, Loading Loading @@ -3187,27 +3196,29 @@ public final class BatteryStatsImpl extends BatteryStats { uid = mapUid(uid); uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long uptime = SystemClock.uptimeMillis(); if (!mAudioOn) { if (mAudioOnNesting == 0) { mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " + Integer.toHexString(mHistoryCur.states)); + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); addHistoryRecordLocked(elapsedRealtime, uptime); mAudioOn = true; mAudioOnTimer.startRunningLocked(elapsedRealtime); mAudioOnTimer.startRunningLocked(elapsedRealtime); } } mAudioOnNesting++; getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); } } public void noteAudioOffLocked(int uid) { public void noteAudioOffLocked(int uid) { if (mAudioOnNesting == 0) { return; } uid = mapUid(uid); uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long uptime = SystemClock.uptimeMillis(); if (mAudioOn) { if (--mAudioOnNesting == 0) { mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " + Integer.toHexString(mHistoryCur.states)); + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); addHistoryRecordLocked(elapsedRealtime, uptime); mAudioOn = false; mAudioOnTimer.stopRunningLocked(elapsedRealtime); mAudioOnTimer.stopRunningLocked(elapsedRealtime); } } getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); Loading @@ -3217,32 +3228,68 @@ public final class BatteryStatsImpl extends BatteryStats { uid = mapUid(uid); uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long uptime = SystemClock.uptimeMillis(); if (!mVideoOn) { if (mVideoOnNesting == 0) { mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " + Integer.toHexString(mHistoryCur.states)); + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); addHistoryRecordLocked(elapsedRealtime, uptime); mVideoOn = true; mVideoOnTimer.startRunningLocked(elapsedRealtime); mVideoOnTimer.startRunningLocked(elapsedRealtime); } } mVideoOnNesting++; getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); } } public void noteVideoOffLocked(int uid) { public void noteVideoOffLocked(int uid) { if (mVideoOnNesting == 0) { return; } uid = mapUid(uid); uid = mapUid(uid); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long uptime = SystemClock.uptimeMillis(); if (mVideoOn) { if (--mVideoOnNesting == 0) { mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " + Integer.toHexString(mHistoryCur.states)); + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); addHistoryRecordLocked(elapsedRealtime, uptime); mVideoOn = false; mVideoOnTimer.stopRunningLocked(elapsedRealtime); mVideoOnTimer.stopRunningLocked(elapsedRealtime); } } getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); } } public void noteResetAudioLocked() { if (mAudioOnNesting > 0) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); mAudioOnNesting = 0; mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); for (int i=0; i<mUidStats.size(); i++) { BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); uid.noteResetAudioLocked(elapsedRealtime); } } } public void noteResetVideoLocked() { if (mVideoOnNesting > 0) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); mAudioOnNesting = 0; mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); for (int i=0; i<mUidStats.size(); i++) { BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); uid.noteResetVideoLocked(elapsedRealtime); } } } public void noteActivityResumedLocked(int uid) { public void noteActivityResumedLocked(int uid) { uid = mapUid(uid); uid = mapUid(uid); getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); getUidStatsLocked(uid).noteActivityResumedLocked(SystemClock.elapsedRealtime()); Loading Loading @@ -3855,10 +3902,7 @@ public final class BatteryStatsImpl extends BatteryStats { boolean mWifiMulticastEnabled; boolean mWifiMulticastEnabled; StopwatchTimer mWifiMulticastTimer; StopwatchTimer mWifiMulticastTimer; boolean mAudioTurnedOn; StopwatchTimer mAudioTurnedOnTimer; StopwatchTimer mAudioTurnedOnTimer; boolean mVideoTurnedOn; StopwatchTimer mVideoTurnedOnTimer; StopwatchTimer mVideoTurnedOnTimer; StopwatchTimer mForegroundActivityTimer; StopwatchTimer mForegroundActivityTimer; Loading Loading @@ -4073,53 +4117,49 @@ public final class BatteryStatsImpl extends BatteryStats { public StopwatchTimer createAudioTurnedOnTimerLocked() { public StopwatchTimer createAudioTurnedOnTimerLocked() { if (mAudioTurnedOnTimer == null) { if (mAudioTurnedOnTimer == null) { mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, null, mOnBatteryTimeBase); mAudioTurnedOnTimers, mOnBatteryTimeBase); } } return mAudioTurnedOnTimer; return mAudioTurnedOnTimer; } } @Override public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { if (!mAudioTurnedOn) { mAudioTurnedOn = true; createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); } } } @Override public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { if (mAudioTurnedOn) { mAudioTurnedOn = false; if (mAudioTurnedOnTimer != null) { if (mAudioTurnedOnTimer != null) { mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); } } } } public void noteResetAudioLocked(long elapsedRealtimeMs) { if (mAudioTurnedOnTimer != null) { mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); } } } public StopwatchTimer createVideoTurnedOnTimerLocked() { public StopwatchTimer createVideoTurnedOnTimerLocked() { if (mVideoTurnedOnTimer == null) { if (mVideoTurnedOnTimer == null) { mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, null, mOnBatteryTimeBase); mVideoTurnedOnTimers, mOnBatteryTimeBase); } } return mVideoTurnedOnTimer; return mVideoTurnedOnTimer; } } @Override public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { if (!mVideoTurnedOn) { mVideoTurnedOn = true; createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); } } } @Override public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { if (mVideoTurnedOn) { mVideoTurnedOn = false; if (mVideoTurnedOnTimer != null) { if (mVideoTurnedOnTimer != null) { mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); } } } } public void noteResetVideoLocked(long elapsedRealtimeMs) { if (mVideoTurnedOnTimer != null) { mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); } } } public StopwatchTimer createForegroundActivityTimerLocked() { public StopwatchTimer createForegroundActivityTimerLocked() { Loading Loading @@ -4416,11 +4456,9 @@ public final class BatteryStatsImpl extends BatteryStats { } } if (mAudioTurnedOnTimer != null) { if (mAudioTurnedOnTimer != null) { active |= !mAudioTurnedOnTimer.reset(false); active |= !mAudioTurnedOnTimer.reset(false); active |= mAudioTurnedOn; } } if (mVideoTurnedOnTimer != null) { if (mVideoTurnedOnTimer != null) { active |= !mVideoTurnedOnTimer.reset(false); active |= !mVideoTurnedOnTimer.reset(false); active |= mVideoTurnedOn; } } if (mForegroundActivityTimer != null) { if (mForegroundActivityTimer != null) { active |= !mForegroundActivityTimer.reset(false); active |= !mForegroundActivityTimer.reset(false); Loading Loading @@ -4803,17 +4841,15 @@ public final class BatteryStatsImpl extends BatteryStats { } else { } else { mWifiMulticastTimer = null; mWifiMulticastTimer = null; } } mAudioTurnedOn = false; if (in.readInt() != 0) { if (in.readInt() != 0) { mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, mAudioTurnedOnTimer = new StopwatchTimer(Uid.this, AUDIO_TURNED_ON, null, mOnBatteryTimeBase, in); mAudioTurnedOnTimers, mOnBatteryTimeBase, in); } else { } else { mAudioTurnedOnTimer = null; mAudioTurnedOnTimer = null; } } mVideoTurnedOn = false; if (in.readInt() != 0) { if (in.readInt() != 0) { mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, mVideoTurnedOnTimer = new StopwatchTimer(Uid.this, VIDEO_TURNED_ON, null, mOnBatteryTimeBase, in); mVideoTurnedOnTimers, mOnBatteryTimeBase, in); } else { } else { mVideoTurnedOnTimer = null; mVideoTurnedOnTimer = null; } } Loading Loading @@ -7554,11 +7590,9 @@ public final class BatteryStatsImpl extends BatteryStats { if (in.readInt() != 0) { if (in.readInt() != 0) { u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); } } u.mAudioTurnedOn = false; if (in.readInt() != 0) { if (in.readInt() != 0) { u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); } } u.mVideoTurnedOn = false; if (in.readInt() != 0) { if (in.readInt() != 0) { u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); } } Loading Loading @@ -8071,9 +8105,9 @@ public final class BatteryStatsImpl extends BatteryStats { mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i, null, mOnBatteryTimeBase, in); null, mOnBatteryTimeBase, in); } } mAudioOn = false; mAudioOnNesting = 0; mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); mAudioOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase); mVideoOn = false; mVideoOnNesting = 0; mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); mVideoOnTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase); mFlashlightOn = false; mFlashlightOn = false; mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); mFlashlightOnTimer = new StopwatchTimer(null, -9, null, mOnBatteryTimeBase, in); Loading Loading @@ -8125,6 +8159,8 @@ public final class BatteryStatsImpl extends BatteryStats { mWifiScanTimers.clear(); mWifiScanTimers.clear(); mWifiBatchedScanTimers.clear(); mWifiBatchedScanTimers.clear(); mWifiMulticastTimers.clear(); mWifiMulticastTimers.clear(); mAudioTurnedOnTimers.clear(); mVideoTurnedOnTimers.clear(); sNumSpeedSteps = in.readInt(); sNumSpeedSteps = in.readInt(); Loading
services/core/java/com/android/server/am/BatteryStatsService.java +14 −0 Original line number Original line Diff line number Diff line Loading @@ -413,6 +413,20 @@ public final class BatteryStatsService extends IBatteryStats.Stub } } } } public void noteResetAudio() { enforceCallingPermission(); synchronized (mStats) { mStats.noteResetAudioLocked(); } } public void noteResetVideo() { enforceCallingPermission(); synchronized (mStats) { mStats.noteResetVideoLocked(); } } public void noteFlashlightOn() { public void noteFlashlightOn() { enforceCallingPermission(); enforceCallingPermission(); synchronized (mStats) { synchronized (mStats) { Loading