Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06ee9cdb authored by YK Hung's avatar YK Hung Committed by Android (Google) Code Review
Browse files

Merge "Allow wireless charging label to customize content descriptions" into main

parents b6e94698 6dc8193d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -97,6 +97,9 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
            final CharSequence wirelessChargingLabel =
                    mBatterySettingsFeatureProvider.getWirelessChargingLabel(mContext, info);
            if (wirelessChargingLabel != null) {
                mBatteryUsageProgressBarPref.setBottomSummaryContentDescription(
                        mBatterySettingsFeatureProvider
                                .getWirelessChargingContentDescription(mContext, info));
                return wirelessChargingLabel;
            }
        }
+5 −0
Original line number Diff line number Diff line
@@ -49,6 +49,11 @@ public interface BatterySettingsFeatureProvider {
    @Nullable
    CharSequence getWirelessChargingLabel(@NonNull Context context, @NonNull BatteryInfo info);

    /** Return a content description for the bottom summary during wireless charging. */
    @Nullable
    CharSequence getWirelessChargingContentDescription(
            @NonNull Context context, @NonNull BatteryInfo info);

    /** Return a charging remaining time label for wireless charging. */
    @Nullable
    CharSequence getWirelessChargingRemainingLabel(
+7 −0
Original line number Diff line number Diff line
@@ -61,6 +61,13 @@ public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatur
        return null;
    }

    @Nullable
    @Override
    public CharSequence getWirelessChargingContentDescription(
            @NonNull Context context, @NonNull BatteryInfo info) {
        return null;
    }

    @Nullable
    @Override
    public CharSequence getWirelessChargingRemainingLabel(
+12 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ 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;
@@ -278,6 +279,7 @@ public class BatteryHeaderPreferenceControllerTest {
    @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",
@@ -288,14 +290,19 @@ public class BatteryHeaderPreferenceControllerTest {
        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",
@@ -308,10 +315,13 @@ public class BatteryHeaderPreferenceControllerTest {
        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",
@@ -324,6 +334,8 @@ public class BatteryHeaderPreferenceControllerTest {
        mController.updateBatteryStatus(/* label= */ null, batteryInfo);

        verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
        verify(mBatteryUsageProgressBarPref, never())
                .setBottomSummaryContentDescription(contentDescription);
    }

    @Test
+6 −0
Original line number Diff line number Diff line
@@ -76,6 +76,12 @@ public class BatterySettingsFeatureProviderImplTest {
        assertThat(mImpl.getWirelessChargingLabel(mContext, new BatteryInfo())).isNull();
    }

    @Test
    public void getWirelessChargingContentDescription_returnNull() {
        assertThat(mImpl.getWirelessChargingContentDescription(mContext, new BatteryInfo()))
                .isNull();
    }

    @Test
    public void getWirelessChargingRemainingLabel_returnNull() {
        assertThat(mImpl.getWirelessChargingRemainingLabel(mContext, 1000L, 1000L)).isNull();