summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java10
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java20
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java65
4 files changed, 94 insertions, 6 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java
index f9bb90e9616a..b3205d7563b2 100644
--- a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java
+++ b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java
@@ -16,6 +16,7 @@
package com.android.settingslib.fuelgauge;
+import static android.os.BatteryManager.BATTERY_HEALTH_OVERHEAT;
import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN;
import static android.os.BatteryManager.BATTERY_STATUS_FULL;
import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
@@ -128,6 +129,15 @@ public class BatteryStatus {
}
/**
+ * Whether battery is overheated.
+ *
+ * @return true if battery is overheated
+ */
+ public boolean isOverheated() {
+ return health == BATTERY_HEALTH_OVERHEAT;
+ }
+
+ /**
* Return current chargin speed is fast, slow or normal.
*
* @return the charing speed
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
index 4be1f8e30e97..0fd8fd554c9c 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
@@ -2686,6 +2686,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
return true;
}
+ // change in battery overheat
+ if (current.health != old.health) {
+ return true;
+ }
+
return false;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
index 3765e5a26e8e..5259aa968825 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
@@ -117,6 +117,8 @@ public class KeyguardIndicationController implements StateListener,
private boolean mPowerPluggedIn;
private boolean mPowerPluggedInWired;
private boolean mPowerCharged;
+ private boolean mBatteryOverheated;
+ private boolean mEnableBatteryDefender;
private int mChargingSpeed;
private int mChargingWattage;
private int mBatteryLevel;
@@ -410,7 +412,7 @@ public class KeyguardIndicationController implements StateListener,
} else if (!TextUtils.isEmpty(mAlignmentIndication)) {
mTextView.switchIndication(mAlignmentIndication);
mTextView.setTextColor(mContext.getColor(R.color.misalignment_text_color));
- } else if (mPowerPluggedIn) {
+ } else if (mPowerPluggedIn || mEnableBatteryDefender) {
String indication = computePowerIndication();
if (animate) {
animateText(mTextView, indication);
@@ -430,7 +432,7 @@ public class KeyguardIndicationController implements StateListener,
String trustManagedIndication = getTrustManagedIndication();
String powerIndication = null;
- if (mPowerPluggedIn) {
+ if (mPowerPluggedIn || mEnableBatteryDefender) {
powerIndication = computePowerIndication();
}
@@ -465,7 +467,7 @@ public class KeyguardIndicationController implements StateListener,
mTextView.switchIndication(mAlignmentIndication);
isError = true;
hideIndication = !mBatteryPresent;
- } else if (mPowerPluggedIn) {
+ } else if (mPowerPluggedIn || mEnableBatteryDefender) {
if (DEBUG_CHARGING_SPEED) {
powerIndication += ", " + (mChargingWattage / 1000) + " mW";
}
@@ -545,8 +547,14 @@ public class KeyguardIndicationController implements StateListener,
return mContext.getResources().getString(R.string.keyguard_charged);
}
- final boolean hasChargingTime = mChargingTimeRemaining > 0;
int chargingId;
+ String percentage = NumberFormat.getPercentInstance().format(mBatteryLevel / 100f);
+ if (mBatteryOverheated) {
+ chargingId = R.string.keyguard_plugged_in_charging_limited;
+ return mContext.getResources().getString(chargingId, percentage);
+ }
+
+ final boolean hasChargingTime = mChargingTimeRemaining > 0;
if (mPowerPluggedInWired) {
switch (mChargingSpeed) {
case BatteryStatus.CHARGING_FAST:
@@ -571,8 +579,6 @@ public class KeyguardIndicationController implements StateListener,
: R.string.keyguard_plugged_in_wireless;
}
- String percentage = NumberFormat.getPercentInstance()
- .format(mBatteryLevel / 100f);
if (hasChargingTime) {
String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes(
mContext, mChargingTimeRemaining);
@@ -692,6 +698,8 @@ public class KeyguardIndicationController implements StateListener,
mChargingSpeed = status.getChargingSpeed(mContext);
mBatteryLevel = status.level;
mBatteryPresent = status.present;
+ mBatteryOverheated = status.isOverheated();
+ mEnableBatteryDefender = mBatteryOverheated && status.isPluggedIn();
try {
mChargingTimeRemaining = mPowerPluggedIn
? mBatteryInfo.computeChargeTimeRemaining() : -1;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
index f9b14ba7cd31..91144be7347d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java
@@ -82,6 +82,7 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.text.NumberFormat;
import java.util.Collections;
@SmallTest
@@ -546,4 +547,68 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
pluggedIndication, powerIndication);
assertThat(mTextView.getText()).isEqualTo(pluggedIndication);
}
+
+ @Test
+ public void onRefreshBatteryInfo_chargingWithOverheat_presentChargingLimited() {
+ createController();
+ BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_CHARGING,
+ 80 /* level */, BatteryManager.BATTERY_PLUGGED_AC,
+ BatteryManager.BATTERY_HEALTH_OVERHEAT, 0 /* maxChargingWattage */,
+ true /* present */);
+
+ mController.getKeyguardCallback().onRefreshBatteryInfo(status);
+ mController.setVisible(true);
+
+ String percentage = NumberFormat.getPercentInstance().format(80 / 100f);
+ String pluggedIndication = mContext.getString(
+ R.string.keyguard_plugged_in_charging_limited, percentage);
+ assertThat(mTextView.getText()).isEqualTo(pluggedIndication);
+ }
+
+ @Test
+ public void onRefreshBatteryInfo_pluggedWithOverheat_presentChargingLimited() {
+ createController();
+ BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_DISCHARGING,
+ 80 /* level */, BatteryManager.BATTERY_PLUGGED_AC,
+ BatteryManager.BATTERY_HEALTH_OVERHEAT, 0 /* maxChargingWattage */,
+ true /* present */);
+
+ mController.getKeyguardCallback().onRefreshBatteryInfo(status);
+ mController.setVisible(true);
+
+ String percentage = NumberFormat.getPercentInstance().format(80 / 100f);
+ String pluggedIndication = mContext.getString(
+ R.string.keyguard_plugged_in_charging_limited, percentage);
+ assertThat(mTextView.getText()).isEqualTo(pluggedIndication);
+ }
+
+ @Test
+ public void onRefreshBatteryInfo_fullChargedWithOverheat_presentCharged() {
+ createController();
+ BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_CHARGING,
+ 100 /* level */, BatteryManager.BATTERY_PLUGGED_AC,
+ BatteryManager.BATTERY_HEALTH_OVERHEAT, 0 /* maxChargingWattage */,
+ true /* present */);
+
+ mController.getKeyguardCallback().onRefreshBatteryInfo(status);
+ mController.setVisible(true);
+
+ String chargedIndication = mContext.getString(R.string.keyguard_charged);
+ assertThat(mTextView.getText()).isEqualTo(chargedIndication);
+ }
+
+ @Test
+ public void onRefreshBatteryInfo_dischargingWithOverheat_presentBatteryPercentage() {
+ createController();
+ BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_DISCHARGING,
+ 90 /* level */, 0 /* plugged */, BatteryManager.BATTERY_HEALTH_OVERHEAT,
+ 0 /* maxChargingWattage */, true /* present */);
+
+ mController.getKeyguardCallback().onRefreshBatteryInfo(status);
+ mController.setDozing(true);
+ mController.setVisible(true);
+
+ String percentage = NumberFormat.getPercentInstance().format(90 / 100f);
+ assertThat(mTextView.getText()).isEqualTo(percentage);
+ }
}