Split battery header text to a separated preference
This is a no-op refactor. This change makes the Catalyst migration of battery level bar easy. Bug: 372774754 Test: manual Flag: EXEMPT bug fix Change-Id: I6e64e6d9b34aeca584f4d4e951c58c3e1b361f9d
This commit is contained in:
@@ -17,31 +17,19 @@ package com.android.settings.fuelgauge;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip;
|
||||
import com.android.settings.testutils.BatteryTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
@@ -56,9 +44,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowPowerManager;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowEntityHeaderController.class, ShadowUtils.class})
|
||||
@@ -67,23 +53,16 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
private static final String PREF_KEY = "battery_header";
|
||||
private static final int BATTERY_LEVEL = 60;
|
||||
private static final int BATTERY_MAX_LEVEL = 100;
|
||||
private static final String TIME_LEFT = "2h30min";
|
||||
private static final String BATTERY_STATUS = "Charging";
|
||||
|
||||
@Mock private PreferenceScreen mPreferenceScreen;
|
||||
@Mock private BatteryInfo mBatteryInfo;
|
||||
@Mock private EntityHeaderController mEntityHeaderController;
|
||||
@Mock private UsageProgressBarPreference mBatteryUsageProgressBarPref;
|
||||
@Mock private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
||||
@Mock private UsbPort mUsbPort;
|
||||
@Mock private UsbManager mUsbManager;
|
||||
@Mock private UsbPortStatus mUsbPortStatus;
|
||||
|
||||
private BatteryHeaderPreferenceController mController;
|
||||
private Context mContext;
|
||||
private ShadowPowerManager mShadowPowerManager;
|
||||
private Intent mBatteryIntent;
|
||||
private FakeFeatureFactory mFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -101,16 +80,12 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
|
||||
doReturn(mBatteryUsageProgressBarPref)
|
||||
.when(mPreferenceScreen)
|
||||
.findPreference(BatteryHeaderPreferenceController.KEY_BATTERY_HEADER);
|
||||
.findPreference(PREF_KEY);
|
||||
|
||||
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
|
||||
|
||||
mShadowPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
|
||||
mFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
mController = spy(new BatteryHeaderPreferenceController(mContext, PREF_KEY));
|
||||
mController.mBatteryUsageProgressBarPref = mBatteryUsageProgressBarPref;
|
||||
mController.mBatteryStatusFeatureProvider = mBatteryStatusFeatureProvider;
|
||||
|
||||
BatteryUtils.setChargingStringV2Enabled(null);
|
||||
}
|
||||
@@ -129,368 +104,6 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_hasRemainingTime_showRemainingLabel() {
|
||||
mBatteryInfo.remainingLabel = TIME_LEFT;
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_updateBatteryInfo() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText());
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_noRemainingTime_showStatusLabel() {
|
||||
mBatteryInfo.remainingLabel = null;
|
||||
mBatteryInfo.statusLabel = BATTERY_STATUS;
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(BATTERY_STATUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_statusAnomalous_showStatusLabel() {
|
||||
mBatteryInfo.remainingLabel = TIME_LEFT;
|
||||
mBatteryInfo.statusLabel = BATTERY_STATUS;
|
||||
mBatteryInfo.batteryStatus = BatteryManager.BATTERY_STATUS_NOT_CHARGING;
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(BATTERY_STATUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_charging_showFullText() {
|
||||
setChargingState(/* isDischarging */ false, /* updatedByStatusFeature */ false);
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
final String expectedResult = BATTERY_STATUS + " • " + TIME_LEFT;
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_powerSaverOn_showPowerSaverOn() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);
|
||||
mShadowPowerManager.setIsPowerSaveMode(true);
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
final String expectedResult = "Battery Saver on • " + TIME_LEFT;
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_triggerBatteryStatusUpdateTrue_updatePercentageAndUsageOnly() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ true);
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText());
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_triggerBatteryStatusUpdateFalse_updateBatteryInfo() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText());
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_nullLabel_updateSummaryOnly() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);
|
||||
|
||||
mController.updateBatteryStatus(null, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_withLabel_showLabelText() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);
|
||||
|
||||
final String label = "Update by battery status • " + TIME_LEFT;
|
||||
mController.updateBatteryStatus(label, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(label);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_chargingString_statusWithRemainingLabel() {
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ "1 hr, 40 min left until full",
|
||||
/* statusLabel= */ "Charging rapidly",
|
||||
/* isFastCharging= */ true,
|
||||
/* isChargingStringV2= */ false);
|
||||
var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel;
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_chargingStringV2FastCharging_statusWithRemainingLabel() {
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ "Full by 1:30 PM",
|
||||
/* statusLabel= */ "Fast Charging",
|
||||
/* isFastCharging= */ true,
|
||||
/* isChargingStringV2= */ true);
|
||||
var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel;
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_chargingStringV2NonFastCharging_remainingLabel() {
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ "Fully charged by 11:10 PM",
|
||||
/* statusLabel= */ "Charging",
|
||||
/* isFastCharging= */ false,
|
||||
/* isChargingStringV2= */ true);
|
||||
var expectedChargingString = batteryInfo.remainingLabel;
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_customizedWirelessChargingLabel_customizedLabel() {
|
||||
var label = "Customized Wireless Charging Label";
|
||||
var contentDescription = "Customized Wireless Charging description";
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ "Full by 1:30 PM",
|
||||
/* statusLabel= */ "Fast Charging",
|
||||
/* isFastCharging= */ true,
|
||||
/* isChargingStringV2= */ true);
|
||||
batteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||
when(mFactory.batterySettingsFeatureProvider.getWirelessChargingLabel(
|
||||
eq(mContext), any(BatteryInfo.class)))
|
||||
.thenReturn(label);
|
||||
when(mFactory.batterySettingsFeatureProvider.getWirelessChargingContentDescription(
|
||||
eq(mContext), any(BatteryInfo.class)))
|
||||
.thenReturn(contentDescription);
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(label);
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummaryContentDescription(contentDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_noCustomizedWirelessChargingLabel_statusWithRemainingLabel() {
|
||||
var contentDescription = "Customized Wireless Charging description";
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ "Full by 1:30 PM",
|
||||
/* statusLabel= */ "Fast Charging",
|
||||
/* isFastCharging= */ true,
|
||||
/* isChargingStringV2= */ true);
|
||||
batteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||
var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel;
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryUsageProgressBarPref, never())
|
||||
.setBottomSummaryContentDescription(contentDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_noCustomizedWirelessChargingLabel_v1StatusWithRemainingLabel() {
|
||||
var contentDescription = "Customized Wireless Charging description";
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ "1 hr, 40 min left until full",
|
||||
/* statusLabel= */ "Charging wirelessly",
|
||||
/* isFastCharging= */ false,
|
||||
/* isChargingStringV2= */ false);
|
||||
batteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||
var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel;
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryUsageProgressBarPref, never())
|
||||
.setBottomSummaryContentDescription(contentDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_chargingOptimizationMode_remainingLabel() {
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ "Expected remaining label",
|
||||
/* statusLabel= */ "Fast Charging",
|
||||
/* isFastCharging= */ true,
|
||||
/* isChargingStringV2= */ true);
|
||||
var expectedChargingString = batteryInfo.remainingLabel;
|
||||
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
||||
.thenReturn(true);
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_chargingOptimizationModeNoRemainingLabel_statusLabel() {
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ null,
|
||||
/* statusLabel= */ "Fast Charging",
|
||||
/* isFastCharging= */ true,
|
||||
/* isChargingStringV2= */ true);
|
||||
var expectedChargingString = batteryInfo.statusLabel;
|
||||
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
||||
.thenReturn(true);
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_notChargingOptimizationMode_statusWithRemainingLabel() {
|
||||
var batteryInfo =
|
||||
arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
/* remainingLabel= */ "Full by 1:30 PM",
|
||||
/* statusLabel= */ "Fast Charging",
|
||||
/* isFastCharging= */ true,
|
||||
/* isChargingStringV2= */ true);
|
||||
var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel;
|
||||
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
||||
.thenReturn(false);
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_dockDefend_chargingOnHold() {
|
||||
var expected = "Charging on hold";
|
||||
mBatteryInfo.isBatteryDefender = false;
|
||||
when(mFactory.powerUsageFeatureProvider.isExtraDefend()).thenReturn(true);
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryStatus_batteryDefender_chargingOnHold() {
|
||||
var expected = "Charging on hold";
|
||||
mBatteryInfo.isBatteryDefender = true;
|
||||
when(mFactory.powerUsageFeatureProvider.isExtraDefend()).thenReturn(false);
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expected);
|
||||
}
|
||||
|
||||
private BatteryInfo arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
String remainingLabel,
|
||||
String statusLabel,
|
||||
boolean isFastCharging,
|
||||
boolean isChargingStringV2) {
|
||||
SystemProperties.set(
|
||||
BatteryUtils.PROPERTY_CHARGING_STRING_V2_KEY, String.valueOf(isChargingStringV2));
|
||||
mBatteryInfo.isBatteryDefender = false;
|
||||
mBatteryInfo.remainingLabel = remainingLabel;
|
||||
mBatteryInfo.statusLabel = statusLabel;
|
||||
mBatteryInfo.discharging = false;
|
||||
mBatteryInfo.isFastCharging = isFastCharging;
|
||||
return mBatteryInfo;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateHeaderByBatteryTips_lowBatteryTip_showLowBattery() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);
|
||||
BatteryTip lowBatteryTip =
|
||||
new LowBatteryTip(BatteryTip.StateType.NEW, /* powerSaveModeOn */ false);
|
||||
|
||||
mController.updateHeaderByBatteryTips(lowBatteryTip, mBatteryInfo);
|
||||
|
||||
final String expectedResult = "Low battery • " + TIME_LEFT;
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateHeaderByBatteryTips_notLowBatteryTip_showRemainingLabel() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);
|
||||
BatteryTip lowBatteryTip = new SmartBatteryTip(BatteryTip.StateType.NEW);
|
||||
|
||||
mController.updateHeaderByBatteryTips(lowBatteryTip, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateHeaderByBatteryTips_noTip_noAction() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ false);
|
||||
|
||||
mController.updateHeaderByBatteryTips(null, mBatteryInfo);
|
||||
|
||||
verifyNoInteractions(mBatteryUsageProgressBarPref);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateHeaderByBatteryTips_noBatteryInfo_noAction() {
|
||||
BatteryTip lowBatteryTip =
|
||||
new LowBatteryTip(BatteryTip.StateType.NEW, /* powerSaveModeOn */ false);
|
||||
|
||||
mController.updateHeaderByBatteryTips(lowBatteryTip, null);
|
||||
|
||||
verifyNoInteractions(mBatteryUsageProgressBarPref);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_isBatteryDefender_showEmptyText() {
|
||||
mBatteryInfo.isBatteryDefender = true;
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref)
|
||||
.setBottomSummary(
|
||||
mContext.getString(
|
||||
com.android.settingslib.R.string
|
||||
.battery_info_status_charging_on_hold));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_incompatibleCharger_showNotChargingState() {
|
||||
BatteryTestUtils.setupIncompatibleEvent(mUsbPort, mUsbManager, mUsbPortStatus);
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref)
|
||||
.setBottomSummary(
|
||||
mContext.getString(
|
||||
com.android.settingslib.R.string.battery_info_status_not_charging));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quickUpdateHeaderPreference_onlyUpdateBatteryLevelAndChargingState() {
|
||||
@@ -516,22 +129,13 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_init_showEmptySpace() {
|
||||
public void displayPreference_init_setEmptyBottomSummary() {
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(" ");
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary("");
|
||||
}
|
||||
|
||||
private CharSequence formatBatteryPercentageText() {
|
||||
return com.android.settings.Utils.formatPercentage(BATTERY_LEVEL);
|
||||
}
|
||||
|
||||
private void setChargingState(boolean isDischarging, boolean updatedByStatusFeature) {
|
||||
mBatteryInfo.remainingLabel = TIME_LEFT;
|
||||
mBatteryInfo.statusLabel = BATTERY_STATUS;
|
||||
mBatteryInfo.discharging = isDischarging;
|
||||
|
||||
when(mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(mController, mBatteryInfo))
|
||||
.thenReturn(updatedByStatusFeature);
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,6 @@ import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.fuelgauge.BatteryUtils;
|
||||
import com.android.settingslib.widget.UsageProgressBarPreference;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -65,22 +64,21 @@ import org.robolectric.shadows.ShadowPowerManager;
|
||||
@Config(shadows = {ShadowEntityHeaderController.class, ShadowUtils.class})
|
||||
public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
private static final String PREF_KEY = "battery_header";
|
||||
private static final String PREF_KEY = "battery_header_text";
|
||||
private static final int BATTERY_LEVEL = 60;
|
||||
private static final int BATTERY_MAX_LEVEL = 100;
|
||||
private static final String TIME_LEFT = "2h30min";
|
||||
private static final String BATTERY_STATUS = "Charging";
|
||||
|
||||
@Mock private PreferenceScreen mPreferenceScreen;
|
||||
@Mock private BatteryInfo mBatteryInfo;
|
||||
@Mock private EntityHeaderController mEntityHeaderController;
|
||||
@Mock private UsageProgressBarPreference mBatteryUsageProgressBarPref;
|
||||
@Mock private BatteryHeaderTextPreference mBatteryHeaderTextPreference;
|
||||
@Mock private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
||||
@Mock private UsbPort mUsbPort;
|
||||
@Mock private UsbManager mUsbManager;
|
||||
@Mock private UsbPortStatus mUsbPortStatus;
|
||||
|
||||
private BatteryHeaderPreferenceController mController;
|
||||
private BatteryHeaderTextPreferenceController mController;
|
||||
private Context mContext;
|
||||
private ShadowPowerManager mShadowPowerManager;
|
||||
private Intent mBatteryIntent;
|
||||
@@ -100,17 +98,17 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
mBatteryIntent.putExtra(BatteryManager.EXTRA_PLUGGED, 1);
|
||||
doReturn(mBatteryIntent).when(mContext).registerReceiver(any(), any());
|
||||
|
||||
doReturn(mBatteryUsageProgressBarPref)
|
||||
doReturn(mBatteryHeaderTextPreference)
|
||||
.when(mPreferenceScreen)
|
||||
.findPreference(BatteryHeaderPreferenceController.KEY_BATTERY_HEADER);
|
||||
.findPreference(PREF_KEY);
|
||||
|
||||
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
|
||||
|
||||
mShadowPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
|
||||
mFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
mController = spy(new BatteryHeaderPreferenceController(mContext, PREF_KEY));
|
||||
mController.mBatteryUsageProgressBarPref = mBatteryUsageProgressBarPref;
|
||||
mController = spy(new BatteryHeaderTextPreferenceController(mContext, PREF_KEY));
|
||||
mController.mBatteryHeaderTextPreference = mBatteryHeaderTextPreference;
|
||||
mController.mBatteryStatusFeatureProvider = mBatteryStatusFeatureProvider;
|
||||
|
||||
BatteryUtils.setChargingStringV2Enabled(null);
|
||||
@@ -122,21 +120,13 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
ShadowUtils.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_displayBatteryLevel() {
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText());
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_hasRemainingTime_showRemainingLabel() {
|
||||
mBatteryInfo.remainingLabel = TIME_LEFT;
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
verify(mBatteryHeaderTextPreference).setText(mBatteryInfo.remainingLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,9 +135,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText());
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
verify(mBatteryHeaderTextPreference).setText(mBatteryInfo.remainingLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,7 +145,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(BATTERY_STATUS);
|
||||
verify(mBatteryHeaderTextPreference).setText(BATTERY_STATUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,7 +156,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(BATTERY_STATUS);
|
||||
verify(mBatteryHeaderTextPreference).setText(BATTERY_STATUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +166,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
final String expectedResult = BATTERY_STATUS + " • " + TIME_LEFT;
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,17 +177,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
final String expectedResult = "Battery Saver on • " + TIME_LEFT;
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePreference_triggerBatteryStatusUpdateTrue_updatePercentageAndUsageOnly() {
|
||||
setChargingState(/* isDischarging */ true, /* updatedByStatusFeature */ true);
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText());
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,9 +186,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText());
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
verify(mBatteryHeaderTextPreference).setText(mBatteryInfo.remainingLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -219,7 +195,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(null, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
verify(mBatteryHeaderTextPreference).setText(mBatteryInfo.remainingLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,7 +205,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
final String label = "Update by battery status • " + TIME_LEFT;
|
||||
mController.updateBatteryStatus(label, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(label);
|
||||
verify(mBatteryHeaderTextPreference).setText(label);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,7 +220,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -259,7 +235,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,7 +250,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -297,8 +273,8 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(label);
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummaryContentDescription(contentDescription);
|
||||
verify(mBatteryHeaderTextPreference).setText(label);
|
||||
verify(mBatteryHeaderTextPreference).setContentDescription(contentDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -315,9 +291,8 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryUsageProgressBarPref, never())
|
||||
.setBottomSummaryContentDescription(contentDescription);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedChargingString);
|
||||
verify(mBatteryHeaderTextPreference, never()).setContentDescription(contentDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -334,9 +309,8 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryUsageProgressBarPref, never())
|
||||
.setBottomSummaryContentDescription(contentDescription);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedChargingString);
|
||||
verify(mBatteryHeaderTextPreference, never()).setContentDescription(contentDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -353,7 +327,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -370,7 +344,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -387,7 +361,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedChargingString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -398,7 +372,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expected);
|
||||
verify(mBatteryHeaderTextPreference).setText(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -409,7 +383,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateBatteryStatus(/* label= */ null, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expected);
|
||||
verify(mBatteryHeaderTextPreference).setText(expected);
|
||||
}
|
||||
|
||||
private BatteryInfo arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||
@@ -436,7 +410,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
mController.updateHeaderByBatteryTips(lowBatteryTip, mBatteryInfo);
|
||||
|
||||
final String expectedResult = "Low battery • " + TIME_LEFT;
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedResult);
|
||||
verify(mBatteryHeaderTextPreference).setText(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -446,7 +420,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderByBatteryTips(lowBatteryTip, mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
|
||||
verify(mBatteryHeaderTextPreference).setText(mBatteryInfo.remainingLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -455,7 +429,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderByBatteryTips(null, mBatteryInfo);
|
||||
|
||||
verifyNoInteractions(mBatteryUsageProgressBarPref);
|
||||
verifyNoInteractions(mBatteryHeaderTextPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -465,7 +439,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderByBatteryTips(lowBatteryTip, null);
|
||||
|
||||
verifyNoInteractions(mBatteryUsageProgressBarPref);
|
||||
verifyNoInteractions(mBatteryHeaderTextPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -474,9 +448,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref)
|
||||
.setBottomSummary(
|
||||
mContext.getString(
|
||||
verify(mBatteryHeaderTextPreference).setText(mContext.getString(
|
||||
com.android.settingslib.R.string
|
||||
.battery_info_status_charging_on_hold));
|
||||
}
|
||||
@@ -487,20 +459,12 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.updateHeaderPreference(mBatteryInfo);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref)
|
||||
.setBottomSummary(
|
||||
verify(mBatteryHeaderTextPreference)
|
||||
.setText(
|
||||
mContext.getString(
|
||||
com.android.settingslib.R.string.battery_info_status_not_charging));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quickUpdateHeaderPreference_onlyUpdateBatteryLevelAndChargingState() {
|
||||
mController.quickUpdateHeaderPreference();
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setUsageSummary(formatBatteryPercentageText());
|
||||
verify(mBatteryUsageProgressBarPref).setPercent(BATTERY_LEVEL, BATTERY_MAX_LEVEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_returnAvailableUnsearchable() {
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
@@ -513,18 +477,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mBatteryUsageProgressBarPref.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_init_showEmptySpace() {
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(" ");
|
||||
}
|
||||
|
||||
private CharSequence formatBatteryPercentageText() {
|
||||
return com.android.settings.Utils.formatPercentage(BATTERY_LEVEL);
|
||||
assertThat(mBatteryHeaderTextPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
private void setChargingState(boolean isDischarging, boolean updatedByStatusFeature) {
|
||||
|
Reference in New Issue
Block a user