Merge "Punt battery status action when entering Settings main page" into sc-v2-dev am: 99554d3c34
am: d9195b80af
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15938356 Change-Id: I3b030dd9ac65b93500814b62cae4ef48ceb3bc1b
This commit is contained in:
@@ -30,6 +30,7 @@ import com.android.settings.overlay.FeatureFactory;
|
|||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@@ -38,8 +39,9 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected boolean mIsBatteryPresent = true;
|
protected boolean mIsBatteryPresent = true;
|
||||||
|
@VisibleForTesting
|
||||||
|
Preference mPreference;
|
||||||
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
||||||
private Preference mPreference;
|
|
||||||
private BatteryInfo mBatteryInfo;
|
private BatteryInfo mBatteryInfo;
|
||||||
private BatterySettingsFeatureProvider mBatterySettingsFeatureProvider;
|
private BatterySettingsFeatureProvider mBatterySettingsFeatureProvider;
|
||||||
private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
||||||
@@ -140,14 +142,26 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (batteryStatusUpdate) {
|
if (batteryStatusUpdate) {
|
||||||
if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) {
|
setSummaryAsync(info);
|
||||||
mBatteryStatusLabel = null; // will generateLabel()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (mBatteryStatusLabel == null) ? generateLabel(info) : mBatteryStatusLabel;
|
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) {
|
private CharSequence generateLabel(BatteryInfo info) {
|
||||||
if (!info.discharging && info.chargeLabel != null) {
|
if (!info.discharging && info.chargeLabel != null) {
|
||||||
return info.chargeLabel;
|
return info.chargeLabel;
|
||||||
|
@@ -163,6 +163,7 @@ public class TopLevelBatteryPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDashboardLabel_returnsCorrectLabel() {
|
public void getDashboardLabel_returnsCorrectLabel() {
|
||||||
|
mController.mPreference = new Preference(mContext);
|
||||||
BatteryInfo info = new BatteryInfo();
|
BatteryInfo info = new BatteryInfo();
|
||||||
info.batteryPercentString = "3%";
|
info.batteryPercentString = "3%";
|
||||||
assertThat(mController.getDashboardLabel(mContext, info, true))
|
assertThat(mController.getDashboardLabel(mContext, info, true))
|
||||||
|
Reference in New Issue
Block a user