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

This commit is contained in:
YK Hung
2024-06-07 10:55:26 +00:00
committed by Android (Google) Code Review
5 changed files with 33 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -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(

View File

@@ -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(

View File

@@ -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

View File

@@ -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();