Update battery health state intent (2/3)
- Update the extra from overheated to longlife Bug: 278192441 Test: make SettingsRoboTests Change-Id: I5a906e64effbd9aaf84446c0670249afefdf7da8
This commit is contained in:
@@ -34,24 +34,20 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Use this broadcastReceiver to listen to the battery change, and it will invoke
|
||||
* {@link OnBatteryChangedListener} if any of the following has been changed:
|
||||
*
|
||||
* 1. Battery level(e.g. 100%->99%)
|
||||
* 2. Battery status(e.g. plugged->unplugged)
|
||||
* 3. Battery saver(e.g. off->on)
|
||||
* 4. Battery health(e.g. good->overheat)
|
||||
* Use this broadcastReceiver to listen to the battery change and it will invoke
|
||||
* {@link OnBatteryChangedListener}
|
||||
*/
|
||||
public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "BatteryBroadcastRcvr";
|
||||
/**
|
||||
* Callback when the following has been changed:
|
||||
* Callback if any of the monitored fields has been changed:
|
||||
*
|
||||
* Battery level(e.g. 100%->99%)
|
||||
* Battery status(e.g. plugged->unplugged)
|
||||
* Battery saver(e.g. off->on)
|
||||
* Battery health(e.g. good->overheat)
|
||||
* Battery charging status(e.g. default->long life)
|
||||
*/
|
||||
public interface OnBatteryChangedListener {
|
||||
void onBatteryChanged(@BatteryUpdateType int type);
|
||||
@@ -63,6 +59,7 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
BatteryUpdateType.BATTERY_SAVER,
|
||||
BatteryUpdateType.BATTERY_STATUS,
|
||||
BatteryUpdateType.BATTERY_HEALTH,
|
||||
BatteryUpdateType.CHARGING_STATUS,
|
||||
BatteryUpdateType.BATTERY_NOT_PRESENT})
|
||||
public @interface BatteryUpdateType {
|
||||
int MANUAL = 0;
|
||||
@@ -70,7 +67,8 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
int BATTERY_SAVER = 2;
|
||||
int BATTERY_STATUS = 3;
|
||||
int BATTERY_HEALTH = 4;
|
||||
int BATTERY_NOT_PRESENT = 5;
|
||||
int CHARGING_STATUS = 5;
|
||||
int BATTERY_NOT_PRESENT = 6;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -78,6 +76,8 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
@VisibleForTesting
|
||||
String mBatteryStatus;
|
||||
@VisibleForTesting
|
||||
int mChargingStatus;
|
||||
@VisibleForTesting
|
||||
int mBatteryHealth;
|
||||
private OnBatteryChangedListener mBatteryListener;
|
||||
private Context mContext;
|
||||
@@ -121,21 +121,27 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
final String batteryLevel = Utils.getBatteryPercentage(intent);
|
||||
final String batteryStatus =
|
||||
Utils.getBatteryStatus(mContext, intent, /* compactStatus= */ false);
|
||||
final int chargingStatus = intent.getIntExtra(
|
||||
BatteryManager.EXTRA_CHARGING_STATUS, BatteryManager.CHARGING_POLICY_DEFAULT);
|
||||
final int batteryHealth = intent.getIntExtra(
|
||||
BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN);
|
||||
Log.d(
|
||||
TAG,
|
||||
"Battery changed: level="
|
||||
"Battery changed: level: "
|
||||
+ batteryLevel
|
||||
+ ", status="
|
||||
+ "| status: "
|
||||
+ batteryStatus
|
||||
+ ", health="
|
||||
+ "| chargingStatus: "
|
||||
+ chargingStatus
|
||||
+ "| health: "
|
||||
+ batteryHealth);
|
||||
if (!Utils.isBatteryPresent(intent)) {
|
||||
Log.w(TAG, "Problem reading the battery meter.");
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_NOT_PRESENT);
|
||||
} else if (forceUpdate) {
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.MANUAL);
|
||||
} else if (chargingStatus != mChargingStatus) {
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.CHARGING_STATUS);
|
||||
} else if (batteryHealth != mBatteryHealth) {
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_HEALTH);
|
||||
} else if(!batteryLevel.equals(mBatteryLevel)) {
|
||||
@@ -145,6 +151,7 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
mBatteryLevel = batteryLevel;
|
||||
mBatteryStatus = batteryStatus;
|
||||
mChargingStatus = chargingStatus;
|
||||
mBatteryHealth = batteryHealth;
|
||||
} else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(action)) {
|
||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER);
|
||||
|
@@ -51,7 +51,7 @@ public class BatteryInfo {
|
||||
public int batteryStatus;
|
||||
public int pluggedStatus;
|
||||
public boolean discharging = true;
|
||||
public boolean isOverheated;
|
||||
public boolean isBatteryDefender;
|
||||
public long remainingTimeUs = 0;
|
||||
public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN;
|
||||
public String batteryPercentString;
|
||||
@@ -257,9 +257,9 @@ public class BatteryInfo {
|
||||
info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
|
||||
info.mCharging = info.pluggedStatus != 0;
|
||||
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
|
||||
info.isOverheated = batteryBroadcast.getIntExtra(
|
||||
BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN)
|
||||
== BatteryManager.BATTERY_HEALTH_OVERHEAT;
|
||||
info.isBatteryDefender = batteryBroadcast.getIntExtra(
|
||||
BatteryManager.EXTRA_CHARGING_STATUS, BatteryManager.CHARGING_POLICY_DEFAULT)
|
||||
== BatteryManager.CHARGING_POLICY_ADAPTIVE_LONGLIFE;
|
||||
|
||||
info.statusLabel = Utils.getBatteryStatus(context, batteryBroadcast, isCompactStatus);
|
||||
info.batteryStatus = batteryBroadcast.getIntExtra(
|
||||
@@ -283,7 +283,7 @@ public class BatteryInfo {
|
||||
info.discharging = false;
|
||||
info.suggestionLabel = null;
|
||||
int dockDefenderMode = BatteryUtils.getCurrentDockDefenderMode(context, info);
|
||||
if ((info.isOverheated && status != BatteryManager.BATTERY_STATUS_FULL
|
||||
if ((info.isBatteryDefender && status != BatteryManager.BATTERY_STATUS_FULL
|
||||
&& dockDefenderMode == BatteryUtils.DockDefenderMode.DISABLED)
|
||||
|| dockDefenderMode == BatteryUtils.DockDefenderMode.ACTIVE) {
|
||||
// Battery defender active, battery charging paused
|
||||
|
@@ -18,7 +18,6 @@ package com.android.settings.fuelgauge;
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.InstallSourceInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
@@ -322,10 +321,10 @@ public class BatteryUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if battery is overheated and charging.
|
||||
* Return {@code true} if battery defender is on and charging.
|
||||
*/
|
||||
public static boolean isBatteryDefenderOn(BatteryInfo batteryInfo) {
|
||||
return batteryInfo.isOverheated && !batteryInfo.discharging;
|
||||
return batteryInfo.isBatteryDefender && !batteryInfo.discharging;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -627,11 +626,11 @@ public class BatteryUtils {
|
||||
if (Settings.Global.getInt(context.getContentResolver(),
|
||||
SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0) == 1) {
|
||||
return DockDefenderMode.TEMPORARILY_BYPASSED;
|
||||
} else if (batteryInfo.isOverheated && FeatureFactory.getFactory(context)
|
||||
} else if (batteryInfo.isBatteryDefender && FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.isExtraDefend()) {
|
||||
return DockDefenderMode.ACTIVE;
|
||||
} else if (!batteryInfo.isOverheated) {
|
||||
} else if (!batteryInfo.isBatteryDefender) {
|
||||
return DockDefenderMode.FUTURE_BYPASS;
|
||||
}
|
||||
}
|
||||
|
@@ -37,13 +37,12 @@ public class BatteryDefenderDetector implements BatteryTipDetector {
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
final boolean isBasicBatteryDefend = mBatteryInfo.isOverheated
|
||||
&& !FeatureFactory.getFactory(mContext)
|
||||
.getPowerUsageFeatureProvider(mContext)
|
||||
.isExtraDefend();
|
||||
final int state = isBasicBatteryDefend
|
||||
? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
|
||||
final boolean isPluggedIn = mBatteryInfo.pluggedStatus != 0;
|
||||
return new BatteryDefenderTip(state, isPluggedIn);
|
||||
final boolean isBasicBatteryDefend = mBatteryInfo.isBatteryDefender
|
||||
&& !FeatureFactory.getFactory(mContext).getPowerUsageFeatureProvider(mContext)
|
||||
.isExtraDefend();
|
||||
final int state = isBasicBatteryDefend
|
||||
? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
|
||||
final boolean isPluggedIn = mBatteryInfo.pluggedStatus != 0;
|
||||
return new BatteryDefenderTip(state, isPluggedIn);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user