Merge original AOSP chart into battery usage with runtime switchable

This patch is merged from ag/14111128 and seperate two different chart
design between isChratGraphEnabled() method, but we drop the options
menu in the both versions to align the new material next design.

Bug: 185187718
Bug: 185187591
Bug: 177406865
Test: make SettingsRoboTests
Test: make SettingsGoogleRoboTests
Change-Id: Ie88df6a94abf5d1652440fe35392b9f47c447537
This commit is contained in:
ykhung
2021-04-17 23:52:28 +08:00
committed by YUKAI HUNG
parent 434ce05cec
commit 33115020ba
4 changed files with 227 additions and 15 deletions

View File

@@ -17,6 +17,8 @@ import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpd
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
@@ -63,13 +65,14 @@ public class PowerUsageAdvanced extends PowerUsageBase {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
refreshFeatureFlag(getContext());
final Context context = getContext();
refreshFeatureFlag(context);
mHistPref = (BatteryHistoryPreference) findPreference(KEY_BATTERY_GRAPH);
// Removes chart graph preference if the chart design is disabled.
if (!mIsChartGraphEnabled) {
removePreference(KEY_BATTERY_GRAPH);
if (mIsChartGraphEnabled) {
setBatteryChartPreferenceController();
} else {
updateHistPrefSummary(context);
}
setBatteryChartPreferenceController();
}
@Override
@@ -128,6 +131,7 @@ public class PowerUsageAdvanced extends PowerUsageBase {
}
updatePreference(mHistPref);
if (mBatteryAppListPreferenceController != null && mBatteryUsageStats != null) {
updateHistPrefSummary(context);
mBatteryAppListPreferenceController.refreshAppListGroup(
mBatteryUsageStats, /* showAllApps */true);
}
@@ -149,6 +153,18 @@ public class PowerUsageAdvanced extends PowerUsageBase {
}
}
private void updateHistPrefSummary(Context context) {
final Intent batteryIntent =
context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
final boolean plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0;
if (mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(context) && !plugged) {
mHistPref.setBottomSummary(
mPowerUsageFeatureProvider.getAdvancedUsageScreenInfoString());
} else {
mHistPref.hideBottomSummary();
}
}
private void refreshFeatureFlag(Context context) {
if (mPowerUsageFeatureProvider == null) {
mPowerUsageFeatureProvider = FeatureFactory.getFactory(context)