Fix inconsistent connected without charging state in the Settings

Make the "connected, not charging" state condition is the same between
Settings main page (in the TopLevelBatteryPreferenceController), and
sub- battery settings page (in the BatteryHeaderPreferenceController).

https://source.corp.google.com/h/googleplex-android/platform/superproject/main/+/main:packages/apps/Settings/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java;l=116-119

Fix: 285204150
Test: make RunSettingsRoboTests -j40

Change-Id: I9b09d521ca71b18e180c779f1a048d1ea4ba161a
This commit is contained in:
ykhung
2023-07-27 15:08:29 +08:00
committed by YK Hung
parent 98df5bcde2
commit 0610d2b682
2 changed files with 17 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.os.BatteryManager;
import android.util.Log; import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -139,7 +140,10 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
if (Utils.containsIncompatibleChargers(mContext, TAG)) { if (Utils.containsIncompatibleChargers(mContext, TAG)) {
return mContext.getString(R.string.battery_info_status_not_charging); return mContext.getString(R.string.battery_info_status_not_charging);
} }
if (!info.discharging && info.chargeLabel != null) { if (info.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
// Present status only if no remaining time or status anomalous
return info.statusLabel;
} else if (!info.discharging && info.chargeLabel != null) {
return info.chargeLabel; return info.chargeLabel;
} else if (info.remainingLabel == null) { } else if (info.remainingLabel == null) {
return info.batteryPercentString; return info.batteryPercentString;

View File

@@ -31,6 +31,7 @@ import android.content.Intent;
import android.hardware.usb.UsbManager; import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort; import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPortStatus; import android.hardware.usb.UsbPortStatus;
import android.os.BatteryManager;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -145,6 +146,17 @@ public class TopLevelBatteryPreferenceControllerTest {
.isEqualTo(mContext.getString(R.string.battery_info_status_not_charging)); .isEqualTo(mContext.getString(R.string.battery_info_status_not_charging));
} }
@Test
public void getDashboardLabel_notChargingState_returnsCorrectLabel() {
mController.mPreference = new Preference(mContext);
BatteryInfo info = new BatteryInfo();
info.batteryStatus = BatteryManager.BATTERY_STATUS_NOT_CHARGING;
info.statusLabel = "expected returned label";
assertThat(mController.getDashboardLabel(mContext, info, true))
.isEqualTo(info.statusLabel);
}
@Test @Test
public void getSummary_batteryNotPresent_shouldShowWarningMessage() { public void getSummary_batteryNotPresent_shouldShowWarningMessage() {
mController.mIsBatteryPresent = false; mController.mIsBatteryPresent = false;