Update BatteryUtils to update system battery estimate cache

To try and ensure SysUI and Settings don't show different battery
estimates we have settings always push the estimate to the system
cache which will cause the status bar to update as well.

Test: manually trigger battery broadcasts and observe
Bug: 124030091
Change-Id: I07a17ecf2a42c3022673ad2aca438f8d6e81b41f
This commit is contained in:
Salvador Martinez
2019-04-23 16:55:21 -07:00
parent f3365e911d
commit 415f35b670
3 changed files with 31 additions and 2 deletions

View File

@@ -20,9 +20,14 @@ import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpd
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.BatteryStats;
import android.os.Bundle;
import android.os.Handler;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.text.format.Formatter;
import android.view.Menu;
import android.view.MenuInflater;
@@ -102,6 +107,13 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
BatteryTipPreferenceController mBatteryTipPreferenceController;
private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
private final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange, Uri uri) {
restartBatteryInfoLoader();
}
};
@VisibleForTesting
LoaderManager.LoaderCallbacks<BatteryInfo> mBatteryInfoLoaderCallbacks =
new LoaderManager.LoaderCallbacks<BatteryInfo>() {
@@ -189,6 +201,21 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
}
};
@Override
public void onStop() {
getContentResolver().unregisterContentObserver(mSettingsObserver);
super.onStop();
}
@Override
public void onResume() {
super.onResume();
getContentResolver().registerContentObserver(
Global.getUriFor(Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME),
false,
mSettingsObserver);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);