Add one more param to isChargingOptimizationMode() for flexibility
Adds a new param about the charging policy to see if it's currently under CHARGING_POLICY_ADAPTIVE_LONGLIFE for more flexibility to check whether the charging optimization mode is enabled. Bug: 391270019 Flag: EXEMPT bugfix Test: atest SettingsRoboTests Change-Id: Ie773d9a2a13d1a37ac9fd5940f10a100eccf77ca
This commit is contained in:
@@ -86,7 +86,8 @@ public class BatteryHeaderTextPreferenceController extends BasePreferenceControl
|
|||||||
com.android.settingslib.R.string.battery_info_status_charging_on_hold);
|
com.android.settingslib.R.string.battery_info_status_charging_on_hold);
|
||||||
}
|
}
|
||||||
if (info.remainingLabel != null
|
if (info.remainingLabel != null
|
||||||
&& mBatterySettingsFeatureProvider.isChargingOptimizationMode(mContext)) {
|
&& mBatterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
|
mContext, info.isLongLife)) {
|
||||||
return info.remainingLabel;
|
return info.remainingLabel;
|
||||||
}
|
}
|
||||||
if (info.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
|
if (info.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
|
||||||
@@ -97,8 +98,8 @@ public class BatteryHeaderTextPreferenceController extends BasePreferenceControl
|
|||||||
mBatterySettingsFeatureProvider.getWirelessChargingLabel(mContext, info);
|
mBatterySettingsFeatureProvider.getWirelessChargingLabel(mContext, info);
|
||||||
if (mBatteryHeaderTextPreference != null && wirelessChargingLabel != null) {
|
if (mBatteryHeaderTextPreference != null && wirelessChargingLabel != null) {
|
||||||
mBatteryHeaderTextPreference.setContentDescription(
|
mBatteryHeaderTextPreference.setContentDescription(
|
||||||
mBatterySettingsFeatureProvider
|
mBatterySettingsFeatureProvider.getWirelessChargingContentDescription(
|
||||||
.getWirelessChargingContentDescription(mContext, info));
|
mContext, info));
|
||||||
return wirelessChargingLabel;
|
return wirelessChargingLabel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -404,7 +404,7 @@ public class BatteryInfo {
|
|||||||
}
|
}
|
||||||
final BatterySettingsFeatureProvider featureProvider =
|
final BatterySettingsFeatureProvider featureProvider =
|
||||||
FeatureFactory.getFeatureFactory().getBatterySettingsFeatureProvider();
|
FeatureFactory.getFeatureFactory().getBatterySettingsFeatureProvider();
|
||||||
if (featureProvider.isChargingOptimizationMode(context)) {
|
if (featureProvider.isChargingOptimizationMode(context, info.isLongLife)) {
|
||||||
final CharSequence chargeLabel =
|
final CharSequence chargeLabel =
|
||||||
featureProvider.getChargingOptimizationChargeLabel(
|
featureProvider.getChargingOptimizationChargeLabel(
|
||||||
context,
|
context,
|
||||||
@@ -567,10 +567,11 @@ public class BatteryInfo {
|
|||||||
|
|
||||||
private static boolean isPluggedIn(Context context, boolean isCharging, int chargingPolicy) {
|
private static boolean isPluggedIn(Context context, boolean isCharging, int chargingPolicy) {
|
||||||
return isCharging
|
return isCharging
|
||||||
|| (chargingPolicy == BatteryManager.CHARGING_POLICY_ADAPTIVE_LONGLIFE
|
|| FeatureFactory.getFeatureFactory()
|
||||||
&& FeatureFactory.getFeatureFactory()
|
|
||||||
.getBatterySettingsFeatureProvider()
|
.getBatterySettingsFeatureProvider()
|
||||||
.isChargingOptimizationMode(context));
|
.isChargingOptimizationMode(
|
||||||
|
context,
|
||||||
|
chargingPolicy == BatteryManager.CHARGING_POLICY_ADAPTIVE_LONGLIFE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface BatteryDataParser {
|
public interface BatteryDataParser {
|
||||||
|
@@ -60,7 +60,7 @@ public interface BatterySettingsFeatureProvider {
|
|||||||
@NonNull Context context, long remainingTimeMs, long currentTimeMs);
|
@NonNull Context context, long remainingTimeMs, long currentTimeMs);
|
||||||
|
|
||||||
/** Return true if it's in the charging optimization mode. */
|
/** Return true if it's in the charging optimization mode. */
|
||||||
boolean isChargingOptimizationMode(@NonNull Context context);
|
boolean isChargingOptimizationMode(@NonNull Context context, boolean isLongLife);
|
||||||
|
|
||||||
/** Return a charging remaining time label for charging optimization mode. */
|
/** Return a charging remaining time label for charging optimization mode. */
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@@ -76,7 +76,7 @@ public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatur
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChargingOptimizationMode(@NonNull Context context) {
|
public boolean isChargingOptimizationMode(@NonNull Context context, boolean isLongLife) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -161,7 +161,8 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
|||||||
}
|
}
|
||||||
final BatterySettingsFeatureProvider featureProvider =
|
final BatterySettingsFeatureProvider featureProvider =
|
||||||
FeatureFactory.getFeatureFactory().getBatterySettingsFeatureProvider();
|
FeatureFactory.getFeatureFactory().getBatterySettingsFeatureProvider();
|
||||||
if (info.chargeLabel != null && featureProvider.isChargingOptimizationMode(mContext)) {
|
if (info.chargeLabel != null
|
||||||
|
&& featureProvider.isChargingOptimizationMode(mContext, info.isLongLife)) {
|
||||||
return info.chargeLabel;
|
return info.chargeLabel;
|
||||||
}
|
}
|
||||||
if (info.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
|
if (info.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
|
||||||
|
@@ -18,6 +18,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.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
@@ -98,9 +99,7 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
|||||||
mBatteryIntent.putExtra(BatteryManager.EXTRA_PLUGGED, 1);
|
mBatteryIntent.putExtra(BatteryManager.EXTRA_PLUGGED, 1);
|
||||||
doReturn(mBatteryIntent).when(mContext).registerReceiver(any(), any());
|
doReturn(mBatteryIntent).when(mContext).registerReceiver(any(), any());
|
||||||
|
|
||||||
doReturn(mBatteryHeaderTextPreference)
|
doReturn(mBatteryHeaderTextPreference).when(mPreferenceScreen).findPreference(PREF_KEY);
|
||||||
.when(mPreferenceScreen)
|
|
||||||
.findPreference(PREF_KEY);
|
|
||||||
|
|
||||||
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
|
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
|
||||||
|
|
||||||
@@ -322,7 +321,8 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
|||||||
/* isFastCharging= */ true,
|
/* isFastCharging= */ true,
|
||||||
/* isChargingStringV2= */ true);
|
/* isChargingStringV2= */ true);
|
||||||
var expectedChargingString = batteryInfo.remainingLabel;
|
var expectedChargingString = batteryInfo.remainingLabel;
|
||||||
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
|
eq(mContext), anyBoolean()))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
|
|
||||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||||
@@ -339,7 +339,8 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
|||||||
/* isFastCharging= */ true,
|
/* isFastCharging= */ true,
|
||||||
/* isChargingStringV2= */ true);
|
/* isChargingStringV2= */ true);
|
||||||
var expectedChargingString = batteryInfo.statusLabel;
|
var expectedChargingString = batteryInfo.statusLabel;
|
||||||
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
|
eq(mContext), anyBoolean()))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
|
|
||||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||||
@@ -356,7 +357,8 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
|||||||
/* isFastCharging= */ true,
|
/* isFastCharging= */ true,
|
||||||
/* isChargingStringV2= */ true);
|
/* isChargingStringV2= */ true);
|
||||||
var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel;
|
var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel;
|
||||||
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
|
eq(mContext), anyBoolean()))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
|
|
||||||
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
|
||||||
@@ -448,7 +450,9 @@ public class BatteryHeaderTextPreferenceControllerTest {
|
|||||||
|
|
||||||
mController.updateHeaderPreference(mBatteryInfo);
|
mController.updateHeaderPreference(mBatteryInfo);
|
||||||
|
|
||||||
verify(mBatteryHeaderTextPreference).setText(mContext.getString(
|
verify(mBatteryHeaderTextPreference)
|
||||||
|
.setText(
|
||||||
|
mContext.getString(
|
||||||
com.android.settingslib.R.string
|
com.android.settingslib.R.string
|
||||||
.battery_info_status_charging_on_hold));
|
.battery_info_status_charging_on_hold));
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.fuelgauge;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.Truth.assertWithMessage;
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
@@ -729,7 +730,8 @@ public class BatteryInfoTest {
|
|||||||
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 65);
|
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 65);
|
||||||
var expectedRemainingLabel = "Expected remaining label";
|
var expectedRemainingLabel = "Expected remaining label";
|
||||||
var expectedChargeLabel = "65% - " + expectedRemainingLabel;
|
var expectedChargeLabel = "65% - " + expectedRemainingLabel;
|
||||||
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
|
eq(mContext), anyBoolean()))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mFeatureFactory.batterySettingsFeatureProvider.getChargingOptimizationRemainingLabel(
|
when(mFeatureFactory.batterySettingsFeatureProvider.getChargingOptimizationRemainingLabel(
|
||||||
eq(mContext), anyInt(), anyInt(), anyLong(), anyLong()))
|
eq(mContext), anyInt(), anyInt(), anyLong(), anyLong()))
|
||||||
@@ -755,7 +757,8 @@ public class BatteryInfoTest {
|
|||||||
Intent batteryIntent =
|
Intent batteryIntent =
|
||||||
createIntentForGetBatteryInfoTest(
|
createIntentForGetBatteryInfoTest(
|
||||||
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 65);
|
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 65);
|
||||||
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
|
eq(mContext), anyBoolean()))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
var expectedStatusLabel = "Charging";
|
var expectedStatusLabel = "Charging";
|
||||||
var expectedRemainingLabel = "2 hr, 10 min left until full";
|
var expectedRemainingLabel = "2 hr, 10 min left until full";
|
||||||
@@ -777,7 +780,8 @@ public class BatteryInfoTest {
|
|||||||
Intent batteryIntent =
|
Intent batteryIntent =
|
||||||
createIntentForGetBatteryInfoTest(
|
createIntentForGetBatteryInfoTest(
|
||||||
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 65);
|
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 65);
|
||||||
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
|
eq(mContext), anyBoolean()))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
var expectedStatusLabel = "Charging";
|
var expectedStatusLabel = "Charging";
|
||||||
var expectedRemainingLabel = "Fully charged by";
|
var expectedRemainingLabel = "Fully charged by";
|
||||||
@@ -827,7 +831,7 @@ public class BatteryInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBatteryInfo_plugTypeNoneWithLonglifeAndChargeOptimization_chargingString() {
|
public void getBatteryInfo_plugTypeNoneIsChargeOptimization_chargingString() {
|
||||||
prepareTestGetBatteryInfoEnvironment(
|
prepareTestGetBatteryInfoEnvironment(
|
||||||
/* remainingTimeMs= */ Duration.ofMinutes(130).toMillis(),
|
/* remainingTimeMs= */ Duration.ofMinutes(130).toMillis(),
|
||||||
/* chargingStringV2Enabled= */ false);
|
/* chargingStringV2Enabled= */ false);
|
||||||
@@ -840,7 +844,8 @@ public class BatteryInfoTest {
|
|||||||
/* isLonglife= */ true);
|
/* isLonglife= */ true);
|
||||||
var expectedRemainingLabel = "Expected remaining label";
|
var expectedRemainingLabel = "Expected remaining label";
|
||||||
var expectedChargeLabel = "85% - " + expectedRemainingLabel;
|
var expectedChargeLabel = "85% - " + expectedRemainingLabel;
|
||||||
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
|
eq(mContext), anyBoolean()))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mFeatureFactory.batterySettingsFeatureProvider.getChargingOptimizationRemainingLabel(
|
when(mFeatureFactory.batterySettingsFeatureProvider.getChargingOptimizationRemainingLabel(
|
||||||
eq(mContext), anyInt(), anyInt(), anyLong(), anyLong()))
|
eq(mContext), anyInt(), anyInt(), anyLong(), anyLong()))
|
||||||
@@ -859,34 +864,7 @@ public class BatteryInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBatteryInfo_plugTypeNoneNotChargeOptimizationLonglife_dischargingString() {
|
public void getBatteryInfo_plugTypeNoneNotChargeOptimization_dischargingString() {
|
||||||
prepareTestGetBatteryInfoEnvironment(
|
|
||||||
/* remainingTimeMs= */ Duration.ofMinutes(130).toMillis(),
|
|
||||||
/* chargingStringV2Enabled= */ false);
|
|
||||||
Intent batteryIntent =
|
|
||||||
createIntentForGetBatteryInfoTest(
|
|
||||||
ChargingType.NONE,
|
|
||||||
ChargingSpeed.REGULAR,
|
|
||||||
/* batteryLevel= */ 85,
|
|
||||||
BatteryManager.BATTERY_STATUS_DISCHARGING,
|
|
||||||
/* isLonglife= */ true);
|
|
||||||
var expectedRemainingLabel =
|
|
||||||
PowerUtil.getBatteryRemainingShortStringFormatted(
|
|
||||||
mContext, PowerUtil.convertUsToMs(1000L));
|
|
||||||
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
|
||||||
.thenReturn(false);
|
|
||||||
var expectedStatusLabel = "Not charging";
|
|
||||||
|
|
||||||
assertGetBatteryInfo(
|
|
||||||
batteryIntent,
|
|
||||||
/* currentTimeMillis= */ UNUSED_TIME_MS,
|
|
||||||
expectedStatusLabel,
|
|
||||||
expectedRemainingLabel,
|
|
||||||
expectedRemainingLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getBatteryInfo_plugTypeNoneChargeOptimizationNotLonglife_dischargingString() {
|
|
||||||
prepareTestGetBatteryInfoEnvironment(
|
prepareTestGetBatteryInfoEnvironment(
|
||||||
/* remainingTimeMs= */ Duration.ofMinutes(130).toMillis(),
|
/* remainingTimeMs= */ Duration.ofMinutes(130).toMillis(),
|
||||||
/* chargingStringV2Enabled= */ false);
|
/* chargingStringV2Enabled= */ false);
|
||||||
@@ -900,8 +878,9 @@ public class BatteryInfoTest {
|
|||||||
var expectedRemainingLabel =
|
var expectedRemainingLabel =
|
||||||
PowerUtil.getBatteryRemainingShortStringFormatted(
|
PowerUtil.getBatteryRemainingShortStringFormatted(
|
||||||
mContext, PowerUtil.convertUsToMs(1000L));
|
mContext, PowerUtil.convertUsToMs(1000L));
|
||||||
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
|
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(
|
||||||
.thenReturn(true);
|
eq(mContext), anyBoolean()))
|
||||||
|
.thenReturn(false);
|
||||||
var expectedStatusLabel = "Not charging";
|
var expectedStatusLabel = "Not charging";
|
||||||
|
|
||||||
assertGetBatteryInfo(
|
assertGetBatteryInfo(
|
||||||
|
@@ -89,7 +89,7 @@ public class BatterySettingsFeatureProviderImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChargingOptimizationMode_default_returnFalse() {
|
public void isChargingOptimizationMode_default_returnFalse() {
|
||||||
assertThat(mImpl.isChargingOptimizationMode(mContext)).isFalse();
|
assertThat(mImpl.isChargingOptimizationMode(mContext, true)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user