Update SysUI to use system cache for battery estimates

This should help prevent Settings and SysUI from getting
out of sync with each other.

Test: manual by adjusting battery levels with adb
Bug: 124030091
Change-Id: I8eaba920a10e045c4c983406873de66208c22fb7
This commit is contained in:
Salvador Martinez
2019-04-23 14:55:36 -07:00
parent f49ca51851
commit 7de8929c05
3 changed files with 23 additions and 13 deletions

View File

@@ -36,6 +36,7 @@ import android.graphics.Rect;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.TypedValue;
@@ -319,6 +320,9 @@ public class BatteryMeterView extends LinearLayout implements
mUser = ActivityManager.getCurrentUser();
getContext().getContentResolver().registerContentObserver(
Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, mUser);
getContext().getContentResolver().registerContentObserver(
Settings.Global.getUriFor(Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME),
false, mSettingObserver);
updateShowPercent();
subscribeForTunerUpdates();
mUserTracker.startTracking();
@@ -493,6 +497,11 @@ public class BatteryMeterView extends LinearLayout implements
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
updateShowPercent();
if (TextUtils.equals(uri.getLastPathSegment(),
Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME)) {
// update the text for sure if the estimate in the cache was updated
updatePercentText();
}
}
}
}