Update wireless charging string
Add a capability to provide different strings during wireless charging. Bug: 316239566 Test: robotests Change-Id: Ic7c70ae33ae951dfe931995e5ab0d478222d57c9
This commit is contained in:
@@ -7198,6 +7198,8 @@
|
|||||||
<string name="help_url_dock_defender" translatable="false"></string>
|
<string name="help_url_dock_defender" translatable="false"></string>
|
||||||
<!-- Help URL, Incompatible charging [DO NOT TRANSLATE] -->
|
<!-- Help URL, Incompatible charging [DO NOT TRANSLATE] -->
|
||||||
<string name="help_url_incompatible_charging" translatable="false"></string>
|
<string name="help_url_incompatible_charging" translatable="false"></string>
|
||||||
|
<!-- Help URL, Wireless charging [DO NOT TRANSLATE] -->
|
||||||
|
<string name="help_url_wireless_charging" translatable="false"></string>
|
||||||
<!-- Help URL, Accounts [DO NOT TRANSLATE] -->
|
<!-- Help URL, Accounts [DO NOT TRANSLATE] -->
|
||||||
<string name="help_url_accounts" translatable="false"></string>
|
<string name="help_url_accounts" translatable="false"></string>
|
||||||
<!-- Help URL, Choose lockscreen [DO NOT TRANSLATE] -->
|
<!-- Help URL, Choose lockscreen [DO NOT TRANSLATE] -->
|
||||||
|
@@ -43,14 +43,18 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
|||||||
@VisibleForTesting BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
@VisibleForTesting BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
||||||
@VisibleForTesting UsageProgressBarPreference mBatteryUsageProgressBarPref;
|
@VisibleForTesting UsageProgressBarPreference mBatteryUsageProgressBarPref;
|
||||||
|
|
||||||
private BatteryTip mBatteryTip;
|
|
||||||
private final PowerManager mPowerManager;
|
private final PowerManager mPowerManager;
|
||||||
|
private final BatterySettingsFeatureProvider mBatterySettingsFeatureProvider;
|
||||||
|
|
||||||
|
private BatteryTip mBatteryTip;
|
||||||
|
|
||||||
public BatteryHeaderPreferenceController(Context context, String key) {
|
public BatteryHeaderPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mPowerManager = context.getSystemService(PowerManager.class);
|
mPowerManager = context.getSystemService(PowerManager.class);
|
||||||
mBatteryStatusFeatureProvider =
|
mBatteryStatusFeatureProvider =
|
||||||
FeatureFactory.getFeatureFactory().getBatteryStatusFeatureProvider();
|
FeatureFactory.getFeatureFactory().getBatteryStatusFeatureProvider();
|
||||||
|
mBatterySettingsFeatureProvider =
|
||||||
|
FeatureFactory.getFeatureFactory().getBatterySettingsFeatureProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,6 +78,14 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence generateLabel(BatteryInfo info) {
|
private CharSequence generateLabel(BatteryInfo info) {
|
||||||
|
if (info.pluggedStatus == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
|
||||||
|
final CharSequence wirelessChargingLabel =
|
||||||
|
mBatterySettingsFeatureProvider.getWirelessChargingLabel(mContext, info);
|
||||||
|
if (wirelessChargingLabel != null) {
|
||||||
|
return wirelessChargingLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Utils.containsIncompatibleChargers(mContext, TAG)) {
|
if (Utils.containsIncompatibleChargers(mContext, TAG)) {
|
||||||
return mContext.getString(
|
return mContext.getString(
|
||||||
com.android.settingslib.R.string.battery_info_status_not_charging);
|
com.android.settingslib.R.string.battery_info_status_not_charging);
|
||||||
|
@@ -18,6 +18,9 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
|
|
||||||
@@ -41,4 +44,8 @@ public interface BatterySettingsFeatureProvider {
|
|||||||
List<BatteryTip> batteryTips,
|
List<BatteryTip> batteryTips,
|
||||||
BatteryInfo batteryInfo,
|
BatteryInfo batteryInfo,
|
||||||
BatteryTipPolicy batteryTipPolicy);
|
BatteryTipPolicy batteryTipPolicy);
|
||||||
|
|
||||||
|
/** Return a label for the bottom summary during wireless charging. */
|
||||||
|
@Nullable
|
||||||
|
CharSequence getWirelessChargingLabel(@NonNull Context context, @NonNull BatteryInfo info);
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,9 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||||
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
||||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
@@ -50,4 +53,11 @@ public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatur
|
|||||||
BatteryTipPolicy batteryTipPolicy) {
|
BatteryTipPolicy batteryTipPolicy) {
|
||||||
batteryTips.add(new LowBatteryDetector(context, batteryTipPolicy, batteryInfo).detect());
|
batteryTips.add(new LowBatteryDetector(context, batteryTipPolicy, batteryInfo).detect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public CharSequence getWirelessChargingLabel(
|
||||||
|
@NonNull Context context, @NonNull BatteryInfo info) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ package com.android.settings.fuelgauge;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -40,6 +41,7 @@ import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
|||||||
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
|
||||||
import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip;
|
||||||
import com.android.settings.testutils.BatteryTestUtils;
|
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.ShadowEntityHeaderController;
|
||||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||||
import com.android.settings.widget.EntityHeaderController;
|
import com.android.settings.widget.EntityHeaderController;
|
||||||
@@ -81,6 +83,7 @@ public class BatteryHeaderPreferenceControllerTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ShadowPowerManager mShadowPowerManager;
|
private ShadowPowerManager mShadowPowerManager;
|
||||||
private Intent mBatteryIntent;
|
private Intent mBatteryIntent;
|
||||||
|
private FakeFeatureFactory mFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -103,6 +106,7 @@ public class BatteryHeaderPreferenceControllerTest {
|
|||||||
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
|
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
|
||||||
|
|
||||||
mShadowPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
|
mShadowPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
|
||||||
|
mFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
|
||||||
mController = spy(new BatteryHeaderPreferenceController(mContext, PREF_KEY));
|
mController = spy(new BatteryHeaderPreferenceController(mContext, PREF_KEY));
|
||||||
mController.mBatteryUsageProgressBarPref = mBatteryUsageProgressBarPref;
|
mController.mBatteryUsageProgressBarPref = mBatteryUsageProgressBarPref;
|
||||||
@@ -272,6 +276,56 @@ public class BatteryHeaderPreferenceControllerTest {
|
|||||||
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateBatteryStatus_customizedWirelessChargingLabel_customizedLabel() {
|
||||||
|
var label = "Customized Wireless Charging Label";
|
||||||
|
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);
|
||||||
|
|
||||||
|
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||||
|
|
||||||
|
verify(mBatteryUsageProgressBarPref).setBottomSummary(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateBatteryStatus_noCustomizedWirelessChargingLabel_statusWithRemainingLabel() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateBatteryStatus_noCustomizedWirelessChargingLabel_v1StatusWithRemainingLabel() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
private BatteryInfo arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
private BatteryInfo arrangeUpdateBatteryStatusTestWithRemainingLabel(
|
||||||
String remainingLabel,
|
String remainingLabel,
|
||||||
String statusLabel,
|
String statusLabel,
|
||||||
|
@@ -69,4 +69,8 @@ public class BatterySettingsFeatureProviderImplTest {
|
|||||||
var expectedResult = tips.stream().anyMatch(tip -> tip instanceof LowBatteryTip);
|
var expectedResult = tips.stream().anyMatch(tip -> tip instanceof LowBatteryTip);
|
||||||
assertThat(expectedResult).isTrue();
|
assertThat(expectedResult).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test void getWirelessChargingLabel_returnNull() {
|
||||||
|
assertThat(mImpl.getWirelessChargingLabel(mContext, new BatteryInfo())).isNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user