Loading src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java +18 −4 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.utils.ThreadUtils; import java.util.HashMap; Loading @@ -38,8 +39,9 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle @VisibleForTesting protected boolean mIsBatteryPresent = true; @VisibleForTesting Preference mPreference; private final BatteryBroadcastReceiver mBatteryBroadcastReceiver; private Preference mPreference; private BatteryInfo mBatteryInfo; private BatterySettingsFeatureProvider mBatterySettingsFeatureProvider; private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider; Loading Loading @@ -140,14 +142,26 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle } if (batteryStatusUpdate) { if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) { mBatteryStatusLabel = null; // will generateLabel() } setSummaryAsync(info); } return (mBatteryStatusLabel == null) ? generateLabel(info) : mBatteryStatusLabel; } private void setSummaryAsync(BatteryInfo info) { ThreadUtils.postOnBackgroundThread(() -> { final boolean triggerBatteryStatusUpdate = mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info); ThreadUtils.postOnMainThread(() -> { if (!triggerBatteryStatusUpdate) { mBatteryStatusLabel = null; // will generateLabel() } mPreference.setSummary( (mBatteryStatusLabel == null) ? generateLabel(info) : mBatteryStatusLabel); }); }); } private CharSequence generateLabel(BatteryInfo info) { if (!info.discharging && info.chargeLabel != null) { return info.chargeLabel; Loading tests/robotests/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceControllerTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -156,6 +156,7 @@ public class TopLevelBatteryPreferenceControllerTest { @Test public void getDashboardLabel_returnsCorrectLabel() { mController.mPreference = new Preference(mContext); BatteryInfo info = new BatteryInfo(); info.batteryPercentString = "3%"; assertThat(mController.getDashboardLabel(mContext, info, true)) Loading Loading
src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java +18 −4 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.utils.ThreadUtils; import java.util.HashMap; Loading @@ -38,8 +39,9 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle @VisibleForTesting protected boolean mIsBatteryPresent = true; @VisibleForTesting Preference mPreference; private final BatteryBroadcastReceiver mBatteryBroadcastReceiver; private Preference mPreference; private BatteryInfo mBatteryInfo; private BatterySettingsFeatureProvider mBatterySettingsFeatureProvider; private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider; Loading Loading @@ -140,14 +142,26 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle } if (batteryStatusUpdate) { if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) { mBatteryStatusLabel = null; // will generateLabel() } setSummaryAsync(info); } return (mBatteryStatusLabel == null) ? generateLabel(info) : mBatteryStatusLabel; } private void setSummaryAsync(BatteryInfo info) { ThreadUtils.postOnBackgroundThread(() -> { final boolean triggerBatteryStatusUpdate = mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info); ThreadUtils.postOnMainThread(() -> { if (!triggerBatteryStatusUpdate) { mBatteryStatusLabel = null; // will generateLabel() } mPreference.setSummary( (mBatteryStatusLabel == null) ? generateLabel(info) : mBatteryStatusLabel); }); }); } private CharSequence generateLabel(BatteryInfo info) { if (!info.discharging && info.chargeLabel != null) { return info.chargeLabel; Loading
tests/robotests/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceControllerTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -156,6 +156,7 @@ public class TopLevelBatteryPreferenceControllerTest { @Test public void getDashboardLabel_returnsCorrectLabel() { mController.mPreference = new Preference(mContext); BatteryInfo info = new BatteryInfo(); info.batteryPercentString = "3%"; assertThat(mController.getDashboardLabel(mContext, info, true)) Loading