Merge "Show charging speed on Keyguard" into mnc-dr-dev
This commit is contained in:
@@ -101,6 +101,13 @@ public class BatteryManager {
|
|||||||
*/
|
*/
|
||||||
public static final String EXTRA_INVALID_CHARGER = "invalid_charger";
|
public static final String EXTRA_INVALID_CHARGER = "invalid_charger";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
|
||||||
|
* Int value set to the maximum charging current supported by the charger in micro amperes.
|
||||||
|
* {@hide}
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_MAX_CHARGING_CURRENT = "max_charging_current";
|
||||||
|
|
||||||
// values for "status" field in the ACTION_BATTERY_CHANGED Intent
|
// values for "status" field in the ACTION_BATTERY_CHANGED Intent
|
||||||
public static final int BATTERY_STATUS_UNKNOWN = 1;
|
public static final int BATTERY_STATUS_UNKNOWN = 1;
|
||||||
public static final int BATTERY_STATUS_CHARGING = 2;
|
public static final int BATTERY_STATUS_CHARGING = 2;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class BatteryProperties implements Parcelable {
|
|||||||
public boolean chargerAcOnline;
|
public boolean chargerAcOnline;
|
||||||
public boolean chargerUsbOnline;
|
public boolean chargerUsbOnline;
|
||||||
public boolean chargerWirelessOnline;
|
public boolean chargerWirelessOnline;
|
||||||
|
public int maxChargingCurrent;
|
||||||
public int batteryStatus;
|
public int batteryStatus;
|
||||||
public int batteryHealth;
|
public int batteryHealth;
|
||||||
public boolean batteryPresent;
|
public boolean batteryPresent;
|
||||||
@@ -37,6 +38,7 @@ public class BatteryProperties implements Parcelable {
|
|||||||
chargerAcOnline = other.chargerAcOnline;
|
chargerAcOnline = other.chargerAcOnline;
|
||||||
chargerUsbOnline = other.chargerUsbOnline;
|
chargerUsbOnline = other.chargerUsbOnline;
|
||||||
chargerWirelessOnline = other.chargerWirelessOnline;
|
chargerWirelessOnline = other.chargerWirelessOnline;
|
||||||
|
maxChargingCurrent = other.maxChargingCurrent;
|
||||||
batteryStatus = other.batteryStatus;
|
batteryStatus = other.batteryStatus;
|
||||||
batteryHealth = other.batteryHealth;
|
batteryHealth = other.batteryHealth;
|
||||||
batteryPresent = other.batteryPresent;
|
batteryPresent = other.batteryPresent;
|
||||||
@@ -55,6 +57,7 @@ public class BatteryProperties implements Parcelable {
|
|||||||
chargerAcOnline = p.readInt() == 1 ? true : false;
|
chargerAcOnline = p.readInt() == 1 ? true : false;
|
||||||
chargerUsbOnline = p.readInt() == 1 ? true : false;
|
chargerUsbOnline = p.readInt() == 1 ? true : false;
|
||||||
chargerWirelessOnline = p.readInt() == 1 ? true : false;
|
chargerWirelessOnline = p.readInt() == 1 ? true : false;
|
||||||
|
maxChargingCurrent = p.readInt();
|
||||||
batteryStatus = p.readInt();
|
batteryStatus = p.readInt();
|
||||||
batteryHealth = p.readInt();
|
batteryHealth = p.readInt();
|
||||||
batteryPresent = p.readInt() == 1 ? true : false;
|
batteryPresent = p.readInt() == 1 ? true : false;
|
||||||
@@ -68,6 +71,7 @@ public class BatteryProperties implements Parcelable {
|
|||||||
p.writeInt(chargerAcOnline ? 1 : 0);
|
p.writeInt(chargerAcOnline ? 1 : 0);
|
||||||
p.writeInt(chargerUsbOnline ? 1 : 0);
|
p.writeInt(chargerUsbOnline ? 1 : 0);
|
||||||
p.writeInt(chargerWirelessOnline ? 1 : 0);
|
p.writeInt(chargerWirelessOnline ? 1 : 0);
|
||||||
|
p.writeInt(maxChargingCurrent);
|
||||||
p.writeInt(batteryStatus);
|
p.writeInt(batteryStatus);
|
||||||
p.writeInt(batteryHealth);
|
p.writeInt(batteryHealth);
|
||||||
p.writeInt(batteryPresent ? 1 : 0);
|
p.writeInt(batteryPresent ? 1 : 0);
|
||||||
|
|||||||
@@ -22,4 +22,10 @@
|
|||||||
|
|
||||||
<!-- Allow the menu hard key to be disabled in LockScreen on some devices [DO NOT TRANSLATE] -->
|
<!-- Allow the menu hard key to be disabled in LockScreen on some devices [DO NOT TRANSLATE] -->
|
||||||
<bool name="config_disableMenuKeyInLockScreen">false</bool>
|
<bool name="config_disableMenuKeyInLockScreen">false</bool>
|
||||||
|
|
||||||
|
<!-- Threshold in micro amperes below which a charger is rated as "slow" -->
|
||||||
|
<integer name="config_chargingSlowlyThreshold">1000000</integer>
|
||||||
|
|
||||||
|
<!-- Threshold in micro amperes above which a charger is rated as "fast" -->
|
||||||
|
<integer name="config_chargingFastThreshold">1500000</integer>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -56,6 +56,14 @@
|
|||||||
is not fully charged, say that it's charging. -->
|
is not fully charged, say that it's charging. -->
|
||||||
<string name="keyguard_plugged_in">Charging</string>
|
<string name="keyguard_plugged_in">Charging</string>
|
||||||
|
|
||||||
|
<!-- When the lock screen is showing and the phone plugged in, and the battery
|
||||||
|
is not fully charged, and it's plugged into a fast charger, say that it's charging fast. -->
|
||||||
|
<string name="keyguard_plugged_in_charging_fast">Charging rapidly</string>
|
||||||
|
|
||||||
|
<!-- When the lock screen is showing and the phone plugged in, and the battery
|
||||||
|
is not fully charged, and it's plugged into a slow charger, say that it's charging slowly. -->
|
||||||
|
<string name="keyguard_plugged_in_charging_slowly">Charging slowly</string>
|
||||||
|
|
||||||
<!-- When the lock screen is showing and the battery is low, warn user to plug
|
<!-- When the lock screen is showing and the battery is low, warn user to plug
|
||||||
in the phone soon. -->
|
in the phone soon. -->
|
||||||
<string name="keyguard_low_battery">Connect your charger.</string>
|
<string name="keyguard_low_battery">Connect your charger.</string>
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import static android.os.BatteryManager.EXTRA_STATUS;
|
|||||||
import static android.os.BatteryManager.EXTRA_PLUGGED;
|
import static android.os.BatteryManager.EXTRA_PLUGGED;
|
||||||
import static android.os.BatteryManager.EXTRA_LEVEL;
|
import static android.os.BatteryManager.EXTRA_LEVEL;
|
||||||
import static android.os.BatteryManager.EXTRA_HEALTH;
|
import static android.os.BatteryManager.EXTRA_HEALTH;
|
||||||
|
import static android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT;
|
||||||
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
@@ -489,8 +490,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
|||||||
final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0);
|
final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0);
|
||||||
final int level = intent.getIntExtra(EXTRA_LEVEL, 0);
|
final int level = intent.getIntExtra(EXTRA_LEVEL, 0);
|
||||||
final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
|
final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
|
||||||
|
final int maxChargingCurrent = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1);
|
||||||
final Message msg = mHandler.obtainMessage(
|
final Message msg = mHandler.obtainMessage(
|
||||||
MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health));
|
MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health,
|
||||||
|
maxChargingCurrent));
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
} else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
|
} else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
|
||||||
SimData args = SimData.fromIntent(intent);
|
SimData args = SimData.fromIntent(intent);
|
||||||
@@ -641,15 +644,22 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class BatteryStatus {
|
public static class BatteryStatus {
|
||||||
|
public static final int CHARGING_UNKNOWN = -1;
|
||||||
|
public static final int CHARGING_SLOWLY = 0;
|
||||||
|
public static final int CHARGING_REGULAR = 1;
|
||||||
|
public static final int CHARGING_FAST = 2;
|
||||||
|
|
||||||
public final int status;
|
public final int status;
|
||||||
public final int level;
|
public final int level;
|
||||||
public final int plugged;
|
public final int plugged;
|
||||||
public final int health;
|
public final int health;
|
||||||
public BatteryStatus(int status, int level, int plugged, int health) {
|
public final int maxChargingCurrent;
|
||||||
|
public BatteryStatus(int status, int level, int plugged, int health, int maxChargingCurrent) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.plugged = plugged;
|
this.plugged = plugged;
|
||||||
this.health = health;
|
this.health = health;
|
||||||
|
this.maxChargingCurrent = maxChargingCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -680,6 +690,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
|||||||
return level < LOW_BATTERY_THRESHOLD;
|
return level < LOW_BATTERY_THRESHOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int getChargingSpeed(int slowThreshold, int fastThreshold) {
|
||||||
|
return maxChargingCurrent <= 0 ? CHARGING_UNKNOWN :
|
||||||
|
maxChargingCurrent < slowThreshold ? CHARGING_SLOWLY :
|
||||||
|
maxChargingCurrent > fastThreshold ? CHARGING_FAST :
|
||||||
|
CHARGING_REGULAR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeyguardUpdateMonitor getInstance(Context context) {
|
public static KeyguardUpdateMonitor getInstance(Context context) {
|
||||||
@@ -746,7 +762,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Take a guess at initial SIM state, battery status and PLMN until we get an update
|
// Take a guess at initial SIM state, battery status and PLMN until we get an update
|
||||||
mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0);
|
mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0, 0);
|
||||||
|
|
||||||
// Watch for interesting updates
|
// Watch for interesting updates
|
||||||
final IntentFilter filter = new IntentFilter();
|
final IntentFilter filter = new IntentFilter();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
@@ -45,6 +46,7 @@ import android.view.View;
|
|||||||
public class KeyguardIndicationController {
|
public class KeyguardIndicationController {
|
||||||
|
|
||||||
private static final String TAG = "KeyguardIndicationController";
|
private static final String TAG = "KeyguardIndicationController";
|
||||||
|
private static final boolean DEBUG_CHARGING_CURRENT = false;
|
||||||
|
|
||||||
private static final int MSG_HIDE_TRANSIENT = 1;
|
private static final int MSG_HIDE_TRANSIENT = 1;
|
||||||
|
|
||||||
@@ -52,6 +54,9 @@ public class KeyguardIndicationController {
|
|||||||
private final KeyguardIndicationTextView mTextView;
|
private final KeyguardIndicationTextView mTextView;
|
||||||
private final IBatteryStats mBatteryInfo;
|
private final IBatteryStats mBatteryInfo;
|
||||||
|
|
||||||
|
private final int mSlowThreshold;
|
||||||
|
private final int mFastThreshold;
|
||||||
|
|
||||||
private String mRestingIndication;
|
private String mRestingIndication;
|
||||||
private String mTransientIndication;
|
private String mTransientIndication;
|
||||||
private int mTransientTextColor;
|
private int mTransientTextColor;
|
||||||
@@ -59,11 +64,18 @@ public class KeyguardIndicationController {
|
|||||||
|
|
||||||
private boolean mPowerPluggedIn;
|
private boolean mPowerPluggedIn;
|
||||||
private boolean mPowerCharged;
|
private boolean mPowerCharged;
|
||||||
|
private int mChargingSpeed;
|
||||||
|
private int mChargingCurrent;
|
||||||
|
|
||||||
public KeyguardIndicationController(Context context, KeyguardIndicationTextView textView) {
|
public KeyguardIndicationController(Context context, KeyguardIndicationTextView textView) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mTextView = textView;
|
mTextView = textView;
|
||||||
|
|
||||||
|
Resources res = context.getResources();
|
||||||
|
mSlowThreshold = res.getInteger(R.integer.config_chargingSlowlyThreshold);
|
||||||
|
mFastThreshold = res.getInteger(R.integer.config_chargingFastThreshold);
|
||||||
|
|
||||||
|
|
||||||
mBatteryInfo = IBatteryStats.Stub.asInterface(
|
mBatteryInfo = IBatteryStats.Stub.asInterface(
|
||||||
ServiceManager.getService(BatteryStats.SERVICE_NAME));
|
ServiceManager.getService(BatteryStats.SERVICE_NAME));
|
||||||
KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateMonitor);
|
KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateMonitor);
|
||||||
@@ -150,7 +162,11 @@ public class KeyguardIndicationController {
|
|||||||
return mTransientIndication;
|
return mTransientIndication;
|
||||||
}
|
}
|
||||||
if (mPowerPluggedIn) {
|
if (mPowerPluggedIn) {
|
||||||
return computePowerIndication();
|
String indication = computePowerIndication();
|
||||||
|
if (DEBUG_CHARGING_CURRENT) {
|
||||||
|
indication = indication + mChargingCurrent;
|
||||||
|
}
|
||||||
|
return indication;
|
||||||
}
|
}
|
||||||
return mRestingIndication;
|
return mRestingIndication;
|
||||||
}
|
}
|
||||||
@@ -174,7 +190,19 @@ public class KeyguardIndicationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to simple charging label.
|
// Fall back to simple charging label.
|
||||||
return mContext.getResources().getString(R.string.keyguard_plugged_in);
|
int chargingId;
|
||||||
|
switch (mChargingSpeed) {
|
||||||
|
case KeyguardUpdateMonitor.BatteryStatus.CHARGING_FAST:
|
||||||
|
chargingId = R.string.keyguard_plugged_in_charging_fast;
|
||||||
|
break;
|
||||||
|
case KeyguardUpdateMonitor.BatteryStatus.CHARGING_SLOWLY:
|
||||||
|
chargingId = R.string.keyguard_plugged_in_charging_slowly;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
chargingId = R.string.keyguard_plugged_in;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return mContext.getResources().getString(chargingId);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyguardUpdateMonitorCallback mUpdateMonitor = new KeyguardUpdateMonitorCallback() {
|
KeyguardUpdateMonitorCallback mUpdateMonitor = new KeyguardUpdateMonitorCallback() {
|
||||||
@@ -184,6 +212,8 @@ public class KeyguardIndicationController {
|
|||||||
|| status.status == BatteryManager.BATTERY_STATUS_FULL;
|
|| status.status == BatteryManager.BATTERY_STATUS_FULL;
|
||||||
mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull;
|
mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull;
|
||||||
mPowerCharged = status.isCharged();
|
mPowerCharged = status.isCharged();
|
||||||
|
mChargingCurrent = status.maxChargingCurrent;
|
||||||
|
mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold);
|
||||||
updateIndication();
|
updateIndication();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -323,6 +323,7 @@ public final class BatteryService extends SystemService {
|
|||||||
+ "chargerAcOnline=" + mBatteryProps.chargerAcOnline
|
+ "chargerAcOnline=" + mBatteryProps.chargerAcOnline
|
||||||
+ ", chargerUsbOnline=" + mBatteryProps.chargerUsbOnline
|
+ ", chargerUsbOnline=" + mBatteryProps.chargerUsbOnline
|
||||||
+ ", chargerWirelessOnline=" + mBatteryProps.chargerWirelessOnline
|
+ ", chargerWirelessOnline=" + mBatteryProps.chargerWirelessOnline
|
||||||
|
+ ", maxChargingCurrent" + mBatteryProps.maxChargingCurrent
|
||||||
+ ", batteryStatus=" + mBatteryProps.batteryStatus
|
+ ", batteryStatus=" + mBatteryProps.batteryStatus
|
||||||
+ ", batteryHealth=" + mBatteryProps.batteryHealth
|
+ ", batteryHealth=" + mBatteryProps.batteryHealth
|
||||||
+ ", batteryPresent=" + mBatteryProps.batteryPresent
|
+ ", batteryPresent=" + mBatteryProps.batteryPresent
|
||||||
@@ -503,17 +504,21 @@ public final class BatteryService extends SystemService {
|
|||||||
intent.putExtra(BatteryManager.EXTRA_TEMPERATURE, mBatteryProps.batteryTemperature);
|
intent.putExtra(BatteryManager.EXTRA_TEMPERATURE, mBatteryProps.batteryTemperature);
|
||||||
intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mBatteryProps.batteryTechnology);
|
intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mBatteryProps.batteryTechnology);
|
||||||
intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger);
|
intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger);
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_CURRENT, mBatteryProps.maxChargingCurrent);
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED. level:" + mBatteryProps.batteryLevel +
|
Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED. level:" + mBatteryProps.batteryLevel +
|
||||||
", scale:" + BATTERY_SCALE + ", status:" + mBatteryProps.batteryStatus +
|
", scale:" + BATTERY_SCALE + ", status:" + mBatteryProps.batteryStatus +
|
||||||
", health:" + mBatteryProps.batteryHealth + ", present:" + mBatteryProps.batteryPresent +
|
", health:" + mBatteryProps.batteryHealth +
|
||||||
|
", present:" + mBatteryProps.batteryPresent +
|
||||||
", voltage: " + mBatteryProps.batteryVoltage +
|
", voltage: " + mBatteryProps.batteryVoltage +
|
||||||
", temperature: " + mBatteryProps.batteryTemperature +
|
", temperature: " + mBatteryProps.batteryTemperature +
|
||||||
", technology: " + mBatteryProps.batteryTechnology +
|
", technology: " + mBatteryProps.batteryTechnology +
|
||||||
", AC powered:" + mBatteryProps.chargerAcOnline + ", USB powered:" + mBatteryProps.chargerUsbOnline +
|
", AC powered:" + mBatteryProps.chargerAcOnline +
|
||||||
|
", USB powered:" + mBatteryProps.chargerUsbOnline +
|
||||||
", Wireless powered:" + mBatteryProps.chargerWirelessOnline +
|
", Wireless powered:" + mBatteryProps.chargerWirelessOnline +
|
||||||
", icon:" + icon + ", invalid charger:" + mInvalidCharger);
|
", icon:" + icon + ", invalid charger:" + mInvalidCharger +
|
||||||
|
", maxChargingCurrent:" + mBatteryProps.maxChargingCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@@ -618,6 +623,7 @@ public final class BatteryService extends SystemService {
|
|||||||
pw.println(" AC powered: " + mBatteryProps.chargerAcOnline);
|
pw.println(" AC powered: " + mBatteryProps.chargerAcOnline);
|
||||||
pw.println(" USB powered: " + mBatteryProps.chargerUsbOnline);
|
pw.println(" USB powered: " + mBatteryProps.chargerUsbOnline);
|
||||||
pw.println(" Wireless powered: " + mBatteryProps.chargerWirelessOnline);
|
pw.println(" Wireless powered: " + mBatteryProps.chargerWirelessOnline);
|
||||||
|
pw.println(" Max charging current: " + mBatteryProps.maxChargingCurrent);
|
||||||
pw.println(" status: " + mBatteryProps.batteryStatus);
|
pw.println(" status: " + mBatteryProps.batteryStatus);
|
||||||
pw.println(" health: " + mBatteryProps.batteryHealth);
|
pw.println(" health: " + mBatteryProps.batteryHealth);
|
||||||
pw.println(" present: " + mBatteryProps.batteryPresent);
|
pw.println(" present: " + mBatteryProps.batteryPresent);
|
||||||
|
|||||||
Reference in New Issue
Block a user