Fix double-detach DualTimer bug
DualTimer attempted to detach its subTimer twice when reset(true) was
called, once explicitly and once via a call to the main timer. This
fixes that problem by getting rid of the explicit detach in reset.
Bug: 37208694
Test: runtest -x
frameworks/base/core/tests/coretests/src/com/android/internal/os/BatteryStatsTests.java
and manually looked for "Removed unknown observer" error in logcat.
Change-Id: Ic5ff7d799d46236a74ab0825e108bef40bac0360
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 916241c..fe38605 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -2071,15 +2071,16 @@
@Override
public boolean reset(boolean detachIfReset) {
boolean active = false;
+ // Do not detach the subTimer explicitly since that'll be done by DualTimer.detach().
+ active |= !mSubTimer.reset(false);
active |= !super.reset(detachIfReset);
- active |= !mSubTimer.reset(detachIfReset);
return !active;
}
@Override
public void detach() {
- super.detach();
mSubTimer.detach();
+ super.detach();
}
@Override