diff options
Diffstat (limited to 'services/java/com/android')
9 files changed, 164 insertions, 91 deletions
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java index 90d8c9d..596053d 100644 --- a/services/java/com/android/server/BatteryService.java +++ b/services/java/com/android/server/BatteryService.java @@ -92,6 +92,8 @@ class BatteryService extends Binder { // This should probably be exposed in the API, though it's not critical private static final int BATTERY_PLUGGED_NONE = 0; + private static final int BATTERY_LEVEL_WARNING = 15; + private final Context mContext; private final IBatteryStats mBatteryStats; @@ -260,6 +262,18 @@ class BatteryService extends Binder { intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mContext.sendBroadcast(intent); } + + final boolean plugged = mPlugType != BATTERY_PLUGGED_NONE; + final boolean oldPlugged = mLastPlugType != BATTERY_PLUGGED_NONE; + + /* The ACTION_BATTERY_LOW broadcast is sent in these situations: + * - is just un-plugged (previously was plugged) and battery level is under WARNING, or + * - is not plugged and battery level crosses the WARNING boundary (becomes < 15). + */ + final boolean sendBatteryLow = !plugged + && mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN + && mBatteryLevel < BATTERY_LEVEL_WARNING + && (oldPlugged || mLastBatteryLevel >= BATTERY_LEVEL_WARNING); mLastBatteryStatus = mBatteryStatus; mLastBatteryHealth = mBatteryHealth; @@ -269,8 +283,11 @@ class BatteryService extends Binder { mLastBatteryVoltage = mBatteryVoltage; mLastBatteryTemperature = mBatteryTemperature; mLastBatteryLevelCritical = mBatteryLevelCritical; - + sendIntent(); + if (sendBatteryLow) { + mContext.sendBroadcast(new Intent(Intent.ACTION_BATTERY_LOW)); + } // This needs to be done after sendIntent() so that we get the lastest battery stats. if (logOutlier && dischargeDuration != 0) { diff --git a/services/java/com/android/server/InputDevice.java b/services/java/com/android/server/InputDevice.java index 7b8a2a4..9c1f942 100644 --- a/services/java/com/android/server/InputDevice.java +++ b/services/java/com/android/server/InputDevice.java @@ -63,7 +63,7 @@ public class InputDevice { yMoveScale = my != 0 ? (1.0f/my) : 1.0f; } - MotionEvent generateMotion(InputDevice device, long curTime, + MotionEvent generateMotion(InputDevice device, long curTime, long curTimeNano, boolean isAbs, Display display, int orientation, int metaState) { if (!changed) { @@ -167,7 +167,7 @@ public class InputDevice { if (!isAbs) { x = y = 0; } - return MotionEvent.obtain(downTime, curTime, action, + return MotionEvent.obtainNano(downTime, curTime, curTimeNano, action, scaledX, scaledY, scaledPressure, scaledSize, metaState, xPrecision, yPrecision, device.id, edgeFlags); } else { @@ -181,7 +181,7 @@ public class InputDevice { } return null; } - MotionEvent me = MotionEvent.obtain(downTime, curTime, + MotionEvent me = MotionEvent.obtainNano(downTime, curTime, curTimeNano, MotionEvent.ACTION_MOVE, scaledX, scaledY, scaledPressure, scaledSize, metaState, xPrecision, yPrecision, device.id, edgeFlags); diff --git a/services/java/com/android/server/KeyInputQueue.java b/services/java/com/android/server/KeyInputQueue.java index 411cd6b..78cdf8b 100644 --- a/services/java/com/android/server/KeyInputQueue.java +++ b/services/java/com/android/server/KeyInputQueue.java @@ -18,8 +18,9 @@ package com.android.server; import android.content.Context; import android.content.res.Configuration; -import android.os.SystemClock; +import android.os.LatencyTimer; import android.os.PowerManager; +import android.os.SystemClock; import android.util.Log; import android.util.SparseArray; import android.view.Display; @@ -73,14 +74,17 @@ public abstract class KeyInputQueue { public static final int FILTER_REMOVE = 0; public static final int FILTER_KEEP = 1; public static final int FILTER_ABORT = -1; - + + private static final boolean MEASURE_LATENCY = false; + private LatencyTimer lt; + public interface FilterCallback { int filterEvent(QueuedEvent ev); } static class QueuedEvent { InputDevice inputDevice; - long when; + long whenNano; int flags; // From the raw event int classType; // One of the class constants in InputEvent Object event; @@ -88,7 +92,7 @@ public abstract class KeyInputQueue { void copyFrom(QueuedEvent that) { this.inputDevice = that.inputDevice; - this.when = that.when; + this.whenNano = that.whenNano; this.flags = that.flags; this.classType = that.classType; this.event = that.event; @@ -107,6 +111,10 @@ public abstract class KeyInputQueue { } KeyInputQueue(Context context) { + if (MEASURE_LATENCY) { + lt = new LatencyTimer(100, 1000); + } + PowerManager pm = (PowerManager)context.getSystemService( Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, @@ -241,7 +249,7 @@ public abstract class KeyInputQueue { if (configChanged) { synchronized (mFirst) { - addLocked(di, SystemClock.uptimeMillis(), 0, + addLocked(di, System.nanoTime(), 0, RawInputEvent.CLASS_CONFIGURATION_CHANGED, null); } @@ -256,6 +264,7 @@ public abstract class KeyInputQueue { // timebase as SystemClock.uptimeMillis(). //curTime = gotOne ? ev.when : SystemClock.uptimeMillis(); final long curTime = SystemClock.uptimeMillis(); + final long curTimeNano = System.nanoTime(); //Log.i(TAG, "curTime=" + curTime + ", systemClock=" + SystemClock.uptimeMillis()); final int classes = di.classes; @@ -276,7 +285,7 @@ public abstract class KeyInputQueue { down = false; } int keycode = rotateKeyCodeLocked(ev.keycode); - addLocked(di, curTime, ev.flags, + addLocked(di, curTimeNano, ev.flags, RawInputEvent.CLASS_KEYBOARD, newKeyEvent(di, di.mDownTime, curTime, down, keycode, 0, scancode, @@ -330,7 +339,7 @@ public abstract class KeyInputQueue { } MotionEvent me; - me = di.mAbs.generateMotion(di, curTime, true, + me = di.mAbs.generateMotion(di, curTime, curTimeNano, true, mDisplay, mOrientation, mGlobalMetaState); if (false) Log.v(TAG, "Absolute: x=" + di.mAbs.x + " y=" + di.mAbs.y + " ev=" + me); @@ -338,15 +347,15 @@ public abstract class KeyInputQueue { if (WindowManagerPolicy.WATCH_POINTER) { Log.i(TAG, "Enqueueing: " + me); } - addLocked(di, curTime, ev.flags, + addLocked(di, curTimeNano, ev.flags, RawInputEvent.CLASS_TOUCHSCREEN, me); } - me = di.mRel.generateMotion(di, curTime, false, + me = di.mRel.generateMotion(di, curTime, curTimeNano, false, mDisplay, mOrientation, mGlobalMetaState); if (false) Log.v(TAG, "Relative: x=" + di.mRel.x + " y=" + di.mRel.y + " ev=" + me); if (me != null) { - addLocked(di, curTime, ev.flags, + addLocked(di, curTimeNano, ev.flags, RawInputEvent.CLASS_TRACKBALL, me); } } @@ -530,7 +539,7 @@ public abstract class KeyInputQueue { } } - private QueuedEvent obtainLocked(InputDevice device, long when, + private QueuedEvent obtainLocked(InputDevice device, long whenNano, int flags, int classType, Object event) { QueuedEvent ev; if (mCacheCount == 0) { @@ -542,7 +551,7 @@ public abstract class KeyInputQueue { mCacheCount--; } ev.inputDevice = device; - ev.when = when; + ev.whenNano = whenNano; ev.flags = flags; ev.classType = classType; ev.event = event; @@ -561,13 +570,13 @@ public abstract class KeyInputQueue { } } - private void addLocked(InputDevice device, long when, int flags, + private void addLocked(InputDevice device, long whenNano, int flags, int classType, Object event) { boolean poke = mFirst.next == mLast; - QueuedEvent ev = obtainLocked(device, when, flags, classType, event); + QueuedEvent ev = obtainLocked(device, whenNano, flags, classType, event); QueuedEvent p = mLast.prev; - while (p != mFirst && ev.when < p.when) { + while (p != mFirst && ev.whenNano < p.whenNano) { p = p.prev; } @@ -578,8 +587,15 @@ public abstract class KeyInputQueue { ev.inQueue = true; if (poke) { + long time; + if (MEASURE_LATENCY) { + time = System.nanoTime(); + } mFirst.notify(); mWakeLock.acquire(); + if (MEASURE_LATENCY) { + lt.sample("1 addLocked-queued event ", System.nanoTime() - time); + } } } diff --git a/services/java/com/android/server/MasterClearReceiver.java b/services/java/com/android/server/MasterClearReceiver.java index 5a42e76..3c366da 100644 --- a/services/java/com/android/server/MasterClearReceiver.java +++ b/services/java/com/android/server/MasterClearReceiver.java @@ -30,8 +30,8 @@ public class MasterClearReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals("android.intent.action.GTALK_DATA_MESSAGE_RECEIVED")) { - if (!intent.getBooleanExtra("from_trusted_server", false)) { + if (intent.getAction().equals(Intent.ACTION_REMOTE_INTENT)) { + if (!intent.getBooleanExtra("android.intent.extra.from_trusted_server", false)) { Log.w(TAG, "Ignoring master clear request -- not from trusted server."); return; } diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java index 04e0253..a1866be 100644 --- a/services/java/com/android/server/PackageManagerService.java +++ b/services/java/com/android/server/PackageManagerService.java @@ -1643,6 +1643,9 @@ class PackageManagerService extends IPackageManager.Stub { } } + /** + * @deprecated + */ public void querySyncProviders(List outNames, List outInfo) { synchronized (mPackages) { Iterator<Map.Entry<String, PackageParser.Provider>> i diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index f6c1525..c82b49a 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -32,12 +32,7 @@ import android.content.pm.IPackageManager; import android.database.ContentObserver; import android.database.Cursor; import android.media.AudioService; -import android.os.IBinder; -import android.os.Looper; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.os.SystemClock; -import android.os.SystemProperties; +import android.os.*; import android.provider.Contacts.People; import android.provider.Settings; import android.server.BluetoothA2dpService; @@ -45,6 +40,7 @@ import android.server.BluetoothDeviceService; import android.server.search.SearchManagerService; import android.util.EventLog; import android.util.Log; +import android.accounts.AccountManagerService; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -117,6 +113,14 @@ class ServerThread extends Thread { mContentResolver = context.getContentResolver(); + try { + Log.i(TAG, "Starting Account Manager."); + ServiceManager.addService(Context.ACCOUNT_SERVICE, + new AccountManagerService(context)); + } catch (Throwable e) { + Log.e(TAG, "Failure starting Account Manager", e); + } + Log.i(TAG, "Starting Content Manager."); ContentService.main(context, factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL); diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java index 1528ba3..5bded50 100644 --- a/services/java/com/android/server/WifiService.java +++ b/services/java/com/android/server/WifiService.java @@ -1366,14 +1366,17 @@ public class WifiService extends IWifiManager.Stub { * Set the number of radio frequency channels that are allowed to be used * in the current regulatory domain. This method should be used only * if the correct number of channels cannot be determined automatically - * for some reason. If the operation is successful, the new value is + * for some reason. If the operation is successful, the new value may be * persisted as a Secure setting. * @param numChannels the number of allowed channels. Must be greater than 0 * and less than or equal to 16. + * @param persist {@code true} if the setting should be remembered. * @return {@code true} if the operation succeeds, {@code false} otherwise, e.g., * {@code numChannels} is outside the valid range. */ - public boolean setNumAllowedChannels(int numChannels) { + public boolean setNumAllowedChannels(int numChannels, boolean persist) { + Log.i(TAG, "WifiService trying to setNumAllowed to "+numChannels+ + " with persist set to "+persist); enforceChangePermission(); /* * Validate the argument. We'd like to let the Wi-Fi driver do this, @@ -1392,9 +1395,11 @@ public class WifiService extends IWifiManager.Stub { return false; } - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS, - numChannels); + if (persist) { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS, + numChannels); + } mWifiStateTracker.setNumAllowedChannels(numChannels); return true; } diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java index a04d73a..4561e1a 100644 --- a/services/java/com/android/server/WindowManagerService.java +++ b/services/java/com/android/server/WindowManagerService.java @@ -63,6 +63,7 @@ import android.os.Binder; import android.os.Debug; import android.os.Handler; import android.os.IBinder; +import android.os.LatencyTimer; import android.os.LocalPowerManager; import android.os.Looper; import android.os.Message; @@ -133,7 +134,9 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo static final boolean DEBUG_STARTING_WINDOW = false; static final boolean DEBUG_REORDER = false; static final boolean SHOW_TRANSACTIONS = false; - + static final boolean MEASURE_LATENCY = false; + static private LatencyTimer lt; + static final boolean PROFILE_ORIENTATION = false; static final boolean BLUR = true; static final boolean localLOGV = DEBUG; @@ -495,6 +498,10 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo private WindowManagerService(Context context, PowerManagerService pm, boolean haveInputMethods) { + if (MEASURE_LATENCY) { + lt = new LatencyTimer(100, 1000); + } + mContext = context; mHaveInputMethods = haveInputMethods; mLimitedAlphaCompositing = context.getResources().getBoolean( @@ -3714,7 +3721,7 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo private final void wakeupIfNeeded(WindowState targetWin, int eventType) { long curTime = SystemClock.uptimeMillis(); - if (eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { + if (eventType == TOUCH_EVENT || eventType == LONG_TOUCH_EVENT || eventType == CHEEK_EVENT) { if (mLastTouchEventType == eventType && (curTime - mLastUserActivityCallTime) < MIN_TIME_BETWEEN_USERACTIVITIES) { return; @@ -3774,9 +3781,17 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG, "dispatchPointer " + ev); + if (MEASURE_LATENCY) { + lt.sample("3 Wait for last dispatch ", System.nanoTime() - qev.whenNano); + } + Object targetObj = mKeyWaiter.waitForNextEventTarget(null, qev, ev, true, false); + if (MEASURE_LATENCY) { + lt.sample("3 Last dispatch finished ", System.nanoTime() - qev.whenNano); + } + int action = ev.getAction(); if (action == MotionEvent.ACTION_UP) { @@ -3813,6 +3828,7 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo WindowState target = (WindowState)targetObj; final long eventTime = ev.getEventTime(); + final long eventTimeNano = ev.getEventTimeNano(); //Log.i(TAG, "Sending " + ev + " to " + target); @@ -3831,6 +3847,10 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo } } + if (MEASURE_LATENCY) { + lt.sample("4 in dispatchPointer ", System.nanoTime() - eventTimeNano); + } + if ((target.mAttrs.flags & WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES) != 0) { //target wants to ignore fat touch events @@ -3913,6 +3933,10 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo } } + if (MEASURE_LATENCY) { + lt.sample("5 in dispatchPointer ", System.nanoTime() - eventTimeNano); + } + synchronized(mWindowMap) { if (qev != null && action == MotionEvent.ACTION_MOVE) { mKeyWaiter.bindTargetWindowLocked(target, @@ -3950,7 +3974,16 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo if (DEBUG_INPUT || DEBUG_FOCUS || WindowManagerPolicy.WATCH_POINTER) { Log.v(TAG, "Delivering pointer " + qev + " to " + target); } + + if (MEASURE_LATENCY) { + lt.sample("6 before svr->client ipc ", System.nanoTime() - eventTimeNano); + } + target.mClient.dispatchPointer(ev, eventTime); + + if (MEASURE_LATENCY) { + lt.sample("7 after svr->client ipc ", System.nanoTime() - eventTimeNano); + } return true; } catch (android.os.RemoteException e) { Log.i(TAG, "WINDOW DIED during motion dispatch: " + target); @@ -5071,7 +5104,7 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo } } } - }; + } public boolean detectSafeMode() { mSafeMode = mPolicy.detectSafeMode(); @@ -5136,9 +5169,13 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo if (DEBUG_INPUT && ev != null) Log.v( TAG, "Event: type=" + ev.classType + " data=" + ev.event); + if (MEASURE_LATENCY) { + lt.sample("2 got event ", System.nanoTime() - ev.whenNano); + } + try { if (ev != null) { - curTime = ev.when; + curTime = SystemClock.uptimeMillis(); int eventType; if (ev.classType == RawInputEvent.CLASS_TOUCHSCREEN) { eventType = eventType((MotionEvent)ev.event); @@ -5149,17 +5186,29 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo eventType = LocalPowerManager.OTHER_EVENT; } try { - long now = SystemClock.uptimeMillis(); - - if ((now - mLastBatteryStatsCallTime) + if ((curTime - mLastBatteryStatsCallTime) >= MIN_TIME_BETWEEN_USERACTIVITIES) { - mLastBatteryStatsCallTime = now; + mLastBatteryStatsCallTime = curTime; mBatteryStats.noteInputEvent(); } } catch (RemoteException e) { // Ignore } - mPowerManager.userActivity(curTime, false, eventType, false); + + if (eventType != TOUCH_EVENT + && eventType != LONG_TOUCH_EVENT + && eventType != CHEEK_EVENT) { + mPowerManager.userActivity(curTime, false, + eventType, false); + } else if (mLastTouchEventType != eventType + || (curTime - mLastUserActivityCallTime) + >= MIN_TIME_BETWEEN_USERACTIVITIES) { + mLastUserActivityCallTime = curTime; + mLastTouchEventType = eventType; + mPowerManager.userActivity(curTime, false, + eventType, false); + } + switch (ev.classType) { case RawInputEvent.CLASS_KEYBOARD: KeyEvent ke = (KeyEvent)ev.event; diff --git a/services/java/com/android/server/status/StatusBarPolicy.java b/services/java/com/android/server/status/StatusBarPolicy.java index af94100..76c05d9 100644 --- a/services/java/com/android/server/status/StatusBarPolicy.java +++ b/services/java/com/android/server/status/StatusBarPolicy.java @@ -80,10 +80,7 @@ public class StatusBarPolicy { private static final int EVENT_DATA_ACTIVITY = 3; private static final int EVENT_BATTERY_CLOSE = 4; - // indices into mBatteryThresholds - private static final int BATTERY_THRESHOLD_CLOSE_WARNING = 0; - private static final int BATTERY_THRESHOLD_WARNING = 1; - private static final int BATTERY_THRESHOLD_EMPTY = 2; + private static final int BATTERY_LEVEL_CLOSE_WARNING = 20; private final Context mContext; private final StatusBarService mService; @@ -101,8 +98,6 @@ public class StatusBarPolicy { private boolean mBatteryFirst = true; private boolean mBatteryPlugged; private int mBatteryLevel; - private int mBatteryThreshold = 0; // index into mBatteryThresholds - private int[] mBatteryThresholds = new int[] { 20, 15, -1 }; private AlertDialog mLowBatteryDialog; private TextView mBatteryLevelTextView; private View mBatteryView; @@ -379,6 +374,9 @@ public class StatusBarPolicy { else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { updateBattery(intent); } + else if (action.equals(Intent.ACTION_BATTERY_LOW)) { + onBatteryLow(intent); + } else if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION) || action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION) || action.equals(BluetoothA2dp.SINK_STATE_CHANGED_ACTION)) { @@ -520,6 +518,7 @@ public class StatusBarPolicy { filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); filter.addAction(Intent.ACTION_BATTERY_CHANGED); + filter.addAction(Intent.ACTION_BATTERY_LOW); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_ALARM_CHANGED); filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED); @@ -563,19 +562,6 @@ public class StatusBarPolicy { //mService.setIconVisibility(mSyncFailingIcon, isFailing && !isActive); } - private void pickNextBatteryLevel(int level) { - final int N = mBatteryThresholds.length; - for (int i=0; i<N; i++) { - if (level >= mBatteryThresholds[i]) { - mBatteryThreshold = i; - break; - } - } - if (mBatteryThreshold >= N) { - mBatteryThreshold = N-1; - } - } - private final void updateBattery(Intent intent) { mBatteryData.iconId = intent.getIntExtra("icon-small", 0); mBatteryData.iconLevel = intent.getIntExtra("level", 0); @@ -588,13 +574,10 @@ public class StatusBarPolicy { + " plugged=" + plugged + " mBatteryPlugged=" + mBatteryPlugged + " mBatteryLevel=" + mBatteryLevel - + " mBatteryThreshold=" + mBatteryThreshold + " mBatteryFirst=" + mBatteryFirst); } boolean oldPlugged = mBatteryPlugged; - int oldThreshold = mBatteryThreshold; - pickNextBatteryLevel(level); mBatteryPlugged = plugged; mBatteryLevel = level; @@ -616,35 +599,29 @@ public class StatusBarPolicy { } */ if (false) { - Log.d(TAG, "plugged=" + plugged + " oldPlugged=" + oldPlugged + " level=" + level - + " mBatteryThreshold=" + mBatteryThreshold + " oldThreshold=" + oldThreshold); + Log.d(TAG, "plugged=" + plugged + " oldPlugged=" + oldPlugged + " level=" + level); } - if (!plugged - && ((oldPlugged && level < mBatteryThresholds[BATTERY_THRESHOLD_WARNING]) - || (mBatteryThreshold > oldThreshold - && mBatteryThreshold > BATTERY_THRESHOLD_WARNING))) { - // Broadcast the low battery warning - mContext.sendBroadcast(new Intent(Intent.ACTION_BATTERY_LOW)); - - if (SHOW_LOW_BATTERY_WARNING) { - if (false) { - Log.d(TAG, "mPhoneState=" + mPhoneState - + " mLowBatteryDialog=" + mLowBatteryDialog - + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall); - } - if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) { - showLowBatteryWarning(); - } else { - mBatteryShowLowOnEndCall = true; - } + if (mLowBatteryDialog != null + && mBatteryLevel >= BATTERY_LEVEL_CLOSE_WARNING + && SHOW_LOW_BATTERY_WARNING) { + mLowBatteryDialog.dismiss(); + mBatteryShowLowOnEndCall = false; + } + } + + private void onBatteryLow(Intent intent) { + if (SHOW_LOW_BATTERY_WARNING) { + if (false) { + Log.d(TAG, "mPhoneState=" + mPhoneState + + " mLowBatteryDialog=" + mLowBatteryDialog + + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall); } - } else if (mBatteryThreshold == BATTERY_THRESHOLD_CLOSE_WARNING) { - if (SHOW_LOW_BATTERY_WARNING) { - if (mLowBatteryDialog != null) { - mLowBatteryDialog.dismiss(); - mBatteryShowLowOnEndCall = false; - } + + if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) { + showLowBatteryWarning(); + } else { + mBatteryShowLowOnEndCall = true; } } } @@ -710,9 +687,11 @@ public class StatusBarPolicy { private void showLowBatteryWarning() { closeLastBatteryView(); - int level = mBatteryThresholds[mBatteryThreshold > 1 ? mBatteryThreshold - 1 : 0]; + /* Show exact battery level. + * Add 1 because the text says "less than X%". + */ CharSequence levelText = mContext.getString( - com.android.internal.R.string.battery_low_percent_format, level); + com.android.internal.R.string.battery_low_percent_format, mBatteryLevel + 1); if (mBatteryLevelTextView != null) { mBatteryLevelTextView.setText(levelText); |