BatteryStats: Prevent double-detaching Counter
Detaching a Counter from a TimeBase means you can't use it anymore. Only newly constructed Counters are automatically attached to a TimeBase. Bug: 34200689 Test: make FrameworkCoreTests && adb install ... && adb shell am instrument -w -e class com.android.internal.os.BatteryStatsSensorTest com.android.frameworks.coretests Change-Id: I9309000d5625aa6fe61a3c05f135e5828137d8ce
This commit is contained in:
@@ -6027,7 +6027,8 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
* Clear all stats for this uid. Returns true if the uid is completely
|
||||
* inactive so can be dropped.
|
||||
*/
|
||||
boolean reset() {
|
||||
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
|
||||
public boolean reset() {
|
||||
boolean active = false;
|
||||
|
||||
if (mWifiRunningTimer != null) {
|
||||
@@ -6968,7 +6969,10 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
|
||||
boolean reset() {
|
||||
if (mBgCounter != null) {
|
||||
mBgCounter.reset(true);
|
||||
mBgCounter.reset(true /*detachIfReset*/);
|
||||
// If we detach, we must null the mBgCounter reference so that it
|
||||
// can be recreated and attached.
|
||||
mBgCounter = null;
|
||||
}
|
||||
if (mTimer.reset(true)) {
|
||||
mTimer = null;
|
||||
|
||||
Reference in New Issue
Block a user