Files
app_Settings/src/com/android/settings/fuelgauge/BatteryStatsHelperLoader.java
jackqdyulei 114cf2a1a7 Never store battery stats for cache
In PowerUsageBase, it will store battery stats if it has a configuration
change, which will make BatteryStatsLoaderHelper never get the correct
battery stats because it uses Bundle.EMPTY as the bundle message.

This cl:
1. Remove the store action even though it is configuration change.
2. Always use null to get battery stats
3. Always start a battery status check in register()

Bug: 63658232
Test: RunSettingsRoboTests
Change-Id: Ifbf970c63378ed66dddcdae4d952b7d1fd84216a
2017-07-14 15:36:40 -07:00

59 lines
1.8 KiB
Java

/*
* Copyright (C) 2017 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.settings.fuelgauge;
import android.content.Context;
import android.os.BatteryStats;
import android.os.Bundle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.utils.AsyncLoader;
/**
* Loader to get new {@link BatteryStatsHelper} in the background
*/
public class BatteryStatsHelperLoader extends AsyncLoader<BatteryStatsHelper> {
@VisibleForTesting
UserManager mUserManager;
@VisibleForTesting
BatteryUtils mBatteryUtils;
public BatteryStatsHelperLoader(Context context) {
super(context);
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mBatteryUtils = BatteryUtils.getInstance(context);
}
@Override
public BatteryStatsHelper loadInBackground() {
Context context = getContext();
final BatteryStatsHelper statsHelper = new BatteryStatsHelper(context,
true /* collectBatteryBroadcast */);
mBatteryUtils.initBatteryStatsHelper(statsHelper, null /* bundle */, mUserManager);
return statsHelper;
}
@Override
protected void onDiscardResult(BatteryStatsHelper result) {
}
}