Merge "Fix 3391330: Use BATTERY_STATUS_FULL as "Charged" state [DO NOT MERGE]" into gingerbread
This commit is contained in:
@@ -26,6 +26,7 @@ import static android.os.BatteryManager.BATTERY_STATUS_CHARGING;
|
|||||||
import static android.os.BatteryManager.BATTERY_STATUS_FULL;
|
import static android.os.BatteryManager.BATTERY_STATUS_FULL;
|
||||||
import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
|
import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@@ -70,12 +71,12 @@ public class KeyguardUpdateMonitor {
|
|||||||
|
|
||||||
private boolean mKeyguardBypassEnabled;
|
private boolean mKeyguardBypassEnabled;
|
||||||
|
|
||||||
private boolean mDevicePluggedIn;
|
|
||||||
|
|
||||||
private boolean mDeviceProvisioned;
|
private boolean mDeviceProvisioned;
|
||||||
|
|
||||||
private int mBatteryLevel;
|
private int mBatteryLevel;
|
||||||
|
|
||||||
|
private int mBatteryStatus;
|
||||||
|
|
||||||
private CharSequence mTelephonyPlmn;
|
private CharSequence mTelephonyPlmn;
|
||||||
private CharSequence mTelephonySpn;
|
private CharSequence mTelephonySpn;
|
||||||
|
|
||||||
@@ -203,7 +204,7 @@ public class KeyguardUpdateMonitor {
|
|||||||
|
|
||||||
// take a guess to start
|
// take a guess to start
|
||||||
mSimState = IccCard.State.READY;
|
mSimState = IccCard.State.READY;
|
||||||
mDevicePluggedIn = true;
|
mBatteryStatus = BATTERY_STATUS_FULL;
|
||||||
mBatteryLevel = 100;
|
mBatteryLevel = 100;
|
||||||
|
|
||||||
mTelephonyPlmn = getDefaultPlmn();
|
mTelephonyPlmn = getDefaultPlmn();
|
||||||
@@ -283,13 +284,12 @@ public class KeyguardUpdateMonitor {
|
|||||||
/**
|
/**
|
||||||
* Handle {@link #MSG_BATTERY_UPDATE}
|
* Handle {@link #MSG_BATTERY_UPDATE}
|
||||||
*/
|
*/
|
||||||
private void handleBatteryUpdate(int pluggedInStatus, int batteryLevel) {
|
private void handleBatteryUpdate(int batteryStatus, int batteryLevel) {
|
||||||
if (DEBUG) Log.d(TAG, "handleBatteryUpdate");
|
if (DEBUG) Log.d(TAG, "handleBatteryUpdate");
|
||||||
final boolean pluggedIn = isPluggedIn(pluggedInStatus);
|
if (isBatteryUpdateInteresting(batteryStatus, batteryLevel)) {
|
||||||
|
mBatteryStatus = batteryStatus;
|
||||||
if (isBatteryUpdateInteresting(pluggedIn, batteryLevel)) {
|
|
||||||
mBatteryLevel = batteryLevel;
|
mBatteryLevel = batteryLevel;
|
||||||
mDevicePluggedIn = pluggedIn;
|
final boolean pluggedIn = isPluggedIn(batteryStatus);;
|
||||||
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
for (int i = 0; i < mInfoCallbacks.size(); i++) {
|
||||||
mInfoCallbacks.get(i).onRefreshBatteryInfo(
|
mInfoCallbacks.get(i).onRefreshBatteryInfo(
|
||||||
shouldShowBatteryInfo(), pluggedIn, batteryLevel);
|
shouldShowBatteryInfo(), pluggedIn, batteryLevel);
|
||||||
@@ -336,26 +336,34 @@ public class KeyguardUpdateMonitor {
|
|||||||
return status == BATTERY_STATUS_CHARGING || status == BATTERY_STATUS_FULL;
|
return status == BATTERY_STATUS_CHARGING || status == BATTERY_STATUS_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBatteryUpdateInteresting(boolean pluggedIn, int batteryLevel) {
|
private boolean isBatteryUpdateInteresting(int batteryStatus, int batteryLevel) {
|
||||||
// change in plug is always interesting
|
// change in plug is always interesting
|
||||||
if (mDevicePluggedIn != pluggedIn) {
|
final boolean isPluggedIn = isPluggedIn(batteryStatus);
|
||||||
|
final boolean wasPluggedIn = isPluggedIn(mBatteryStatus);
|
||||||
|
final boolean stateChangedWhilePluggedIn =
|
||||||
|
wasPluggedIn == true && isPluggedIn == true && (mBatteryStatus != batteryStatus);
|
||||||
|
if (wasPluggedIn != isPluggedIn || stateChangedWhilePluggedIn) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// change in battery level while plugged in
|
// change in battery level while plugged in
|
||||||
if (pluggedIn && mBatteryLevel != batteryLevel) {
|
if (isPluggedIn && mBatteryLevel != batteryLevel) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pluggedIn) {
|
if (!isPluggedIn) {
|
||||||
// not plugged in and below threshold
|
// not plugged in and below threshold
|
||||||
if (batteryLevel < LOW_BATTERY_THRESHOLD && batteryLevel != mBatteryLevel) {
|
if (isBatteryLow(batteryLevel) && batteryLevel != mBatteryLevel) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isBatteryLow(int batteryLevel) {
|
||||||
|
return batteryLevel < LOW_BATTERY_THRESHOLD;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param intent The intent with action {@link Telephony.Intents#SPN_STRINGS_UPDATED_ACTION}
|
* @param intent The intent with action {@link Telephony.Intents#SPN_STRINGS_UPDATED_ACTION}
|
||||||
* @return The string to use for the plmn, or null if it should not be shown.
|
* @return The string to use for the plmn, or null if it should not be shown.
|
||||||
@@ -485,7 +493,12 @@ public class KeyguardUpdateMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDevicePluggedIn() {
|
public boolean isDevicePluggedIn() {
|
||||||
return mDevicePluggedIn;
|
return isPluggedIn(mBatteryStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeviceCharged() {
|
||||||
|
return mBatteryStatus == BatteryManager.BATTERY_STATUS_FULL
|
||||||
|
|| mBatteryLevel >= 100; // in case a particular device doesn't flag it
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBatteryLevel() {
|
public int getBatteryLevel() {
|
||||||
@@ -493,7 +506,7 @@ public class KeyguardUpdateMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldShowBatteryInfo() {
|
public boolean shouldShowBatteryInfo() {
|
||||||
return mDevicePluggedIn || mBatteryLevel < LOW_BATTERY_THRESHOLD;
|
return isPluggedIn(mBatteryStatus) || isBatteryLow(mBatteryLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getTelephonyPlmn() {
|
public CharSequence getTelephonyPlmn() {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import android.widget.*;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -417,7 +418,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen, KeyguardUpdateM
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mPluggedIn) {
|
if (mPluggedIn) {
|
||||||
if (mBatteryLevel >= 100) {
|
if (mUpdateMonitor.isDeviceCharged()) {
|
||||||
mCharging = getContext().getString(R.string.lockscreen_charged);
|
mCharging = getContext().getString(R.string.lockscreen_charged);
|
||||||
} else {
|
} else {
|
||||||
mCharging = getContext().getString(R.string.lockscreen_plugged_in, mBatteryLevel);
|
mCharging = getContext().getString(R.string.lockscreen_plugged_in, mBatteryLevel);
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ class PatternUnlockScreen extends LinearLayoutWithDefaultTouchRecepient
|
|||||||
} else if (mShowingBatteryInfo && mNextAlarm == null) {
|
} else if (mShowingBatteryInfo && mNextAlarm == null) {
|
||||||
// battery only
|
// battery only
|
||||||
if (mPluggedIn) {
|
if (mPluggedIn) {
|
||||||
if (mBatteryLevel >= 100) {
|
if (mUpdateMonitor.isDeviceCharged()) {
|
||||||
mStatus1.setText(getContext().getString(R.string.lockscreen_charged));
|
mStatus1.setText(getContext().getString(R.string.lockscreen_charged));
|
||||||
} else {
|
} else {
|
||||||
mStatus1.setText(getContext().getString(R.string.lockscreen_plugged_in, mBatteryLevel));
|
mStatus1.setText(getContext().getString(R.string.lockscreen_plugged_in, mBatteryLevel));
|
||||||
|
|||||||
Reference in New Issue
Block a user