summaryrefslogtreecommitdiff
path: root/services/java/com/android/server/power/PowerManagerService.java
diff options
context:
space:
mode:
authorSascha Prueter <saschap@google.com>2013-01-11 10:53:49 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2013-01-11 10:53:49 -0800
commitb70d9df780b50f2aab2ff006e5cbfbd1a43ba332 (patch)
tree89ab898ac8ccc2be4887f8f939050bae5b7c6799 /services/java/com/android/server/power/PowerManagerService.java
parent1d6a7bd97340eab85920b37c3c83ee66fbebfed1 (diff)
parent1ec3c2ccedde5cd8ff6e94c9b1566a913d5e8db0 (diff)
am 1ec3c2cc: am 28608bbb: am d692ea6d: am b5e4835e: Merge "Improve heuristics for detecting wireless chargers." into jb-mr1.1-dev
* commit '1ec3c2ccedde5cd8ff6e94c9b1566a913d5e8db0': Improve heuristics for detecting wireless chargers.
Diffstat (limited to 'services/java/com/android/server/power/PowerManagerService.java')
-rw-r--r--services/java/com/android/server/power/PowerManagerService.java71
1 files changed, 33 insertions, 38 deletions
diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java
index ec82290344fb..2652739343e0 100644
--- a/services/java/com/android/server/power/PowerManagerService.java
+++ b/services/java/com/android/server/power/PowerManagerService.java
@@ -35,6 +35,8 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.ContentObserver;
+import android.hardware.SensorManager;
+import android.hardware.SystemSensorManager;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Binder;
@@ -153,11 +155,6 @@ public final class PowerManagerService extends IPowerManager.Stub
// Otherwise the user won't get much screen on time before dimming occurs.
private static final float MAXIMUM_SCREEN_DIM_RATIO = 0.2f;
- // Upper bound on the battery charge percentage in order to consider turning
- // the screen on when the device starts charging wirelessly.
- // See point of use for more details.
- private static final int WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT = 95;
-
// The name of the boot animation service in init.rc.
private static final String BOOT_ANIMATION_SERVICE = "bootanim";
@@ -179,6 +176,7 @@ public final class PowerManagerService extends IPowerManager.Stub
private WindowManagerPolicy mPolicy;
private Notifier mNotifier;
private DisplayPowerController mDisplayPowerController;
+ private WirelessChargerDetector mWirelessChargerDetector;
private SettingsObserver mSettingsObserver;
private DreamManagerService mDreamManager;
private LightsService.Light mAttentionLight;
@@ -434,6 +432,8 @@ public final class PowerManagerService extends IPowerManager.Stub
mScreenBrightnessSettingMaximum = pm.getMaximumScreenBrightnessSetting();
mScreenBrightnessSettingDefault = pm.getDefaultScreenBrightnessSetting();
+ SensorManager sensorManager = new SystemSensorManager(mHandler.getLooper());
+
// The notifier runs on the system server's main looper so as not to interfere
// with the animations and other critical functions of the power manager.
mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats,
@@ -441,11 +441,14 @@ public final class PowerManagerService extends IPowerManager.Stub
mScreenOnBlocker, mPolicy);
// The display power controller runs on the power manager service's
- // own handler thread.
+ // own handler thread to ensure timely operation.
mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(),
- mContext, mNotifier, mLightsService, twilight, mDisplayManagerService,
- mDisplayBlanker, mDisplayPowerControllerCallbacks, mHandler);
+ mContext, mNotifier, mLightsService, twilight, sensorManager,
+ mDisplayManagerService, mDisplayBlanker,
+ mDisplayPowerControllerCallbacks, mHandler);
+ mWirelessChargerDetector = new WirelessChargerDetector(sensorManager,
+ createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"));
mSettingsObserver = new SettingsObserver(mHandler);
mAttentionLight = mLightsService.getLight(LightsService.LIGHT_ID_ATTENTION);
@@ -1164,65 +1167,51 @@ public final class PowerManagerService extends IPowerManager.Stub
if (wasPowered != mIsPowered || oldPlugType != mPlugType) {
mDirty |= DIRTY_IS_POWERED;
+ // Update wireless dock detection state.
+ final boolean dockedOnWirelessCharger = mWirelessChargerDetector.update(
+ mIsPowered, mPlugType, mBatteryLevel);
+
// Treat plugging and unplugging the devices as a user activity.
// Users find it disconcerting when they plug or unplug the device
// and it shuts off right away.
// Some devices also wake the device when plugged or unplugged because
// they don't have a charging LED.
final long now = SystemClock.uptimeMillis();
- if (shouldWakeUpWhenPluggedOrUnpluggedLocked(wasPowered, oldPlugType)) {
+ if (shouldWakeUpWhenPluggedOrUnpluggedLocked(wasPowered, oldPlugType,
+ dockedOnWirelessCharger)) {
wakeUpNoUpdateLocked(now);
}
userActivityNoUpdateLocked(
now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
// Tell the notifier whether wireless charging has started so that
- // it can provide feedback to the user. Refer to
- // shouldWakeUpWhenPluggedOrUnpluggedLocked for justification of the
- // heuristics used here.
- if (!wasPowered && mIsPowered
- && mPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS
- && mBatteryLevel < WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT) {
+ // it can provide feedback to the user.
+ if (dockedOnWirelessCharger) {
mNotifier.onWirelessChargingStarted();
}
}
}
}
- private boolean shouldWakeUpWhenPluggedOrUnpluggedLocked(boolean wasPowered, int oldPlugType) {
+ private boolean shouldWakeUpWhenPluggedOrUnpluggedLocked(
+ boolean wasPowered, int oldPlugType, boolean dockedOnWirelessCharger) {
// Don't wake when powered unless configured to do so.
if (!mWakeUpWhenPluggedOrUnpluggedConfig) {
return false;
}
- // FIXME: Need more accurate detection of wireless chargers.
- //
- // We are unable to accurately detect whether the device is resting on the
- // charger unless it is actually receiving power. This causes us some grief
- // because the device might not appear to be plugged into the wireless charger
- // unless it actually charging.
- //
- // To avoid spuriously waking the screen, we apply a special policy to
- // wireless chargers.
- //
- // 1. Don't wake the device when unplugged from wireless charger because
- // it might be that the device is still resting on the wireless charger
- // but is not receiving power anymore because the battery is full.
- //
- // 2. Don't wake the device when plugged into a wireless charger if the
- // battery already appears to be mostly full. This situation may indicate
- // that the device was resting on the charger the whole time and simply
- // wasn't receiving power because the battery was full. We can't tell
- // whether the device was just placed on the charger or whether it has
- // been there for half of the night slowly discharging until it hit
- // the point where it needed to start charging again.
+ // Don't wake when undocked from wireless charger.
+ // See WirelessChargerDetector for justification.
if (wasPowered && !mIsPowered
&& oldPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
return false;
}
+
+ // Don't wake when docked on wireless charger unless we are certain of it.
+ // See WirelessChargerDetector for justification.
if (!wasPowered && mIsPowered
&& mPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS
- && mBatteryLevel >= WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT) {
+ && !dockedOnWirelessCharger) {
return false;
}
@@ -2209,6 +2198,7 @@ public final class PowerManagerService extends IPowerManager.Stub
pw.println("POWER MANAGER (dumpsys power)\n");
final DisplayPowerController dpc;
+ final WirelessChargerDetector wcd;
synchronized (mLock) {
pw.println("Power Manager State:");
pw.println(" mDirty=0x" + Integer.toHexString(mDirty));
@@ -2291,11 +2281,16 @@ public final class PowerManagerService extends IPowerManager.Stub
pw.println("Display Blanker: " + mDisplayBlanker);
dpc = mDisplayPowerController;
+ wcd = mWirelessChargerDetector;
}
if (dpc != null) {
dpc.dump(pw);
}
+
+ if (wcd != null) {
+ wcd.dump(pw);
+ }
}
private SuspendBlocker createSuspendBlockerLocked(String name) {