Loading core/java/com/android/internal/os/BatteryStatsImpl.java +8 −5 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import android.util.TimeUtils; import android.util.Xml; import android.view.Display; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.net.NetworkStatsFactory; import com.android.internal.util.ArrayUtils; import com.android.internal.util.FastPrintWriter; Loading Loading @@ -1092,7 +1093,7 @@ public class BatteryStatsImpl extends BatteryStats { public void writeToParcel(Parcel out, long elapsedRealtimeUs) { if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); out.writeInt(mCount); out.writeInt(computeCurrentCountLocked()); out.writeInt(mLoadedCount); out.writeInt(mUnpluggedCount); out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); Loading @@ -1109,7 +1110,7 @@ public class BatteryStatsImpl extends BatteryStats { + " old mUnpluggedCount=" + mUnpluggedCount); } mUnpluggedTime = computeRunTimeLocked(baseRealtime); mUnpluggedCount = mCount; mUnpluggedCount = computeCurrentCountLocked(); if (DEBUG && mType < 0) { Log.v(TAG, "unplug #" + mType + ": new mUnpluggedTime=" + mUnpluggedTime Loading Loading @@ -1192,7 +1193,7 @@ public class BatteryStatsImpl extends BatteryStats { public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); out.writeLong(runTime); out.writeInt(mCount); out.writeInt(computeCurrentCountLocked()); } public void readSummaryFromParcelLocked(Parcel in) { Loading Loading @@ -1249,7 +1250,8 @@ public class BatteryStatsImpl extends BatteryStats { */ int mUpdateVersion; SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { @VisibleForTesting public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { super(clocks, 0, timeBase, in); mCurrentReportedCount = in.readInt(); mUnpluggedReportedCount = in.readInt(); Loading @@ -1259,7 +1261,8 @@ public class BatteryStatsImpl extends BatteryStats { mTimeBaseRunning = timeBase.isRunning(); } SamplingTimer(Clocks clocks, TimeBase timeBase, boolean trackReportedValues) { @VisibleForTesting public SamplingTimer(Clocks clocks, TimeBase timeBase, boolean trackReportedValues) { super(clocks, 0, timeBase); mTrackingReportedValues = trackReportedValues; mTimeBaseRunning = timeBase.isRunning(); Loading core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.android.internal.os; import android.os.BatteryStats; import android.os.Parcel; import android.support.test.filters.SmallTest; import junit.framework.TestCase; public class BatteryStatsSamplingTimerTest extends TestCase { @SmallTest public void testSampleTimerSummaryParceling() throws Exception { final MockClocks clocks = new MockClocks(); clocks.realtime = 0; clocks.uptime = 0; final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); BatteryStatsImpl.SamplingTimer timer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase, true); // Start running on battery. timeBase.setRunning(true, clocks.uptimeMillis(), clocks.elapsedRealtime()); // The first update on battery consumes the values as a way of starting cleanly. timer.addCurrentReportedTotalTime(10); timer.addCurrentReportedCount(1); timer.addCurrentReportedTotalTime(10); timer.addCurrentReportedCount(1); clocks.realtime = 20; clocks.uptime = 20; assertEquals(10, timer.getTotalTimeLocked(clocks.elapsedRealtime(), BatteryStats.STATS_SINCE_CHARGED)); assertEquals(1, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); // Grab a summary parcel while on battery. final Parcel onBatterySummaryParcel = Parcel.obtain(); timer.writeSummaryFromParcelLocked(onBatterySummaryParcel, clocks.elapsedRealtime() * 1000); onBatterySummaryParcel.setDataPosition(0); // Stop running on battery. timeBase.setRunning(false, clocks.uptimeMillis(), clocks.elapsedRealtime()); assertEquals(10, timer.getTotalTimeLocked(clocks.elapsedRealtime(), BatteryStats.STATS_SINCE_CHARGED)); assertEquals(1, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); // Grab a summary parcel while not on battery. final Parcel offBatterySummaryParcel = Parcel.obtain(); timer.writeSummaryFromParcelLocked(offBatterySummaryParcel, clocks.elapsedRealtime() * 1000); offBatterySummaryParcel.setDataPosition(0); // Read the on battery summary from the parcel. BatteryStatsImpl.SamplingTimer unparceledTimer = new BatteryStatsImpl.SamplingTimer( clocks, timeBase, true); unparceledTimer.readSummaryFromParcelLocked(onBatterySummaryParcel); assertEquals(10, unparceledTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED)); assertEquals(1, unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); // Read the off battery summary from the parcel. unparceledTimer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase, true); unparceledTimer.readSummaryFromParcelLocked(offBatterySummaryParcel); assertEquals(10, unparceledTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED)); assertEquals(1, unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); } } core/tests/coretests/src/com/android/internal/os/BatteryStatsServTest.java +1 −8 Original line number Diff line number Diff line Loading @@ -16,20 +16,13 @@ package com.android.internal.os; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import android.os.BatteryStats; import android.os.Parcel; import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; import android.support.test.filters.SmallTest; import junit.framework.Assert; import junit.framework.TestCase; import com.android.internal.os.BatteryStatsImpl; /** * Provides test cases for android.os.BatteryStats. */ Loading core/tests/coretests/src/com/android/internal/os/BatteryStatsTests.java +1 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ BatteryStatsSamplingTimerTest.class, BatteryStatsServTest.class, BatteryStatsTimeBaseTest.class, BatteryStatsTimerTest.class, Loading core/tests/coretests/src/com/android/internal/os/BatteryStatsTimeBaseTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -18,11 +18,10 @@ package com.android.internal.os; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import android.os.BatteryStats; import android.os.Parcel; import android.test.suitebuilder.annotation.SmallTest; import android.support.test.filters.SmallTest; import android.util.Log; import junit.framework.Assert; Loading Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +8 −5 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import android.util.TimeUtils; import android.util.Xml; import android.view.Display; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.net.NetworkStatsFactory; import com.android.internal.util.ArrayUtils; import com.android.internal.util.FastPrintWriter; Loading Loading @@ -1092,7 +1093,7 @@ public class BatteryStatsImpl extends BatteryStats { public void writeToParcel(Parcel out, long elapsedRealtimeUs) { if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); out.writeInt(mCount); out.writeInt(computeCurrentCountLocked()); out.writeInt(mLoadedCount); out.writeInt(mUnpluggedCount); out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); Loading @@ -1109,7 +1110,7 @@ public class BatteryStatsImpl extends BatteryStats { + " old mUnpluggedCount=" + mUnpluggedCount); } mUnpluggedTime = computeRunTimeLocked(baseRealtime); mUnpluggedCount = mCount; mUnpluggedCount = computeCurrentCountLocked(); if (DEBUG && mType < 0) { Log.v(TAG, "unplug #" + mType + ": new mUnpluggedTime=" + mUnpluggedTime Loading Loading @@ -1192,7 +1193,7 @@ public class BatteryStatsImpl extends BatteryStats { public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); out.writeLong(runTime); out.writeInt(mCount); out.writeInt(computeCurrentCountLocked()); } public void readSummaryFromParcelLocked(Parcel in) { Loading Loading @@ -1249,7 +1250,8 @@ public class BatteryStatsImpl extends BatteryStats { */ int mUpdateVersion; SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { @VisibleForTesting public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { super(clocks, 0, timeBase, in); mCurrentReportedCount = in.readInt(); mUnpluggedReportedCount = in.readInt(); Loading @@ -1259,7 +1261,8 @@ public class BatteryStatsImpl extends BatteryStats { mTimeBaseRunning = timeBase.isRunning(); } SamplingTimer(Clocks clocks, TimeBase timeBase, boolean trackReportedValues) { @VisibleForTesting public SamplingTimer(Clocks clocks, TimeBase timeBase, boolean trackReportedValues) { super(clocks, 0, timeBase); mTrackingReportedValues = trackReportedValues; mTimeBaseRunning = timeBase.isRunning(); Loading
core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.android.internal.os; import android.os.BatteryStats; import android.os.Parcel; import android.support.test.filters.SmallTest; import junit.framework.TestCase; public class BatteryStatsSamplingTimerTest extends TestCase { @SmallTest public void testSampleTimerSummaryParceling() throws Exception { final MockClocks clocks = new MockClocks(); clocks.realtime = 0; clocks.uptime = 0; final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); BatteryStatsImpl.SamplingTimer timer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase, true); // Start running on battery. timeBase.setRunning(true, clocks.uptimeMillis(), clocks.elapsedRealtime()); // The first update on battery consumes the values as a way of starting cleanly. timer.addCurrentReportedTotalTime(10); timer.addCurrentReportedCount(1); timer.addCurrentReportedTotalTime(10); timer.addCurrentReportedCount(1); clocks.realtime = 20; clocks.uptime = 20; assertEquals(10, timer.getTotalTimeLocked(clocks.elapsedRealtime(), BatteryStats.STATS_SINCE_CHARGED)); assertEquals(1, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); // Grab a summary parcel while on battery. final Parcel onBatterySummaryParcel = Parcel.obtain(); timer.writeSummaryFromParcelLocked(onBatterySummaryParcel, clocks.elapsedRealtime() * 1000); onBatterySummaryParcel.setDataPosition(0); // Stop running on battery. timeBase.setRunning(false, clocks.uptimeMillis(), clocks.elapsedRealtime()); assertEquals(10, timer.getTotalTimeLocked(clocks.elapsedRealtime(), BatteryStats.STATS_SINCE_CHARGED)); assertEquals(1, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); // Grab a summary parcel while not on battery. final Parcel offBatterySummaryParcel = Parcel.obtain(); timer.writeSummaryFromParcelLocked(offBatterySummaryParcel, clocks.elapsedRealtime() * 1000); offBatterySummaryParcel.setDataPosition(0); // Read the on battery summary from the parcel. BatteryStatsImpl.SamplingTimer unparceledTimer = new BatteryStatsImpl.SamplingTimer( clocks, timeBase, true); unparceledTimer.readSummaryFromParcelLocked(onBatterySummaryParcel); assertEquals(10, unparceledTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED)); assertEquals(1, unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); // Read the off battery summary from the parcel. unparceledTimer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase, true); unparceledTimer.readSummaryFromParcelLocked(offBatterySummaryParcel); assertEquals(10, unparceledTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED)); assertEquals(1, unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); } }
core/tests/coretests/src/com/android/internal/os/BatteryStatsServTest.java +1 −8 Original line number Diff line number Diff line Loading @@ -16,20 +16,13 @@ package com.android.internal.os; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import android.os.BatteryStats; import android.os.Parcel; import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; import android.support.test.filters.SmallTest; import junit.framework.Assert; import junit.framework.TestCase; import com.android.internal.os.BatteryStatsImpl; /** * Provides test cases for android.os.BatteryStats. */ Loading
core/tests/coretests/src/com/android/internal/os/BatteryStatsTests.java +1 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ BatteryStatsSamplingTimerTest.class, BatteryStatsServTest.class, BatteryStatsTimeBaseTest.class, BatteryStatsTimerTest.class, Loading
core/tests/coretests/src/com/android/internal/os/BatteryStatsTimeBaseTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -18,11 +18,10 @@ package com.android.internal.os; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import android.os.BatteryStats; import android.os.Parcel; import android.test.suitebuilder.annotation.SmallTest; import android.support.test.filters.SmallTest; import android.util.Log; import junit.framework.Assert; Loading