@@ -1078,41 +1078,51 @@ private void updateIsPoweredLocked(int dirty) {
10781078 }
10791079
10801080 private boolean shouldWakeUpWhenPluggedOrUnpluggedLocked (boolean wasPowered , int oldPlugType ) {
1081- if (mWakeUpWhenPluggedOrUnpluggedConfig ) {
1082- // FIXME: Need more accurate detection of wireless chargers.
1083- //
1084- // We are unable to accurately detect whether the device is resting on the
1085- // charger unless it is actually receiving power. This causes us some grief
1086- // because the device might not appear to be plugged into the wireless charger
1087- // unless it actually charging.
1088- //
1089- // To avoid spuriously waking the screen, we apply a special policy to
1090- // wireless chargers.
1091- //
1092- // 1. Don't wake the device when unplugged from wireless charger because
1093- // it might be that the device is still resting on the wireless charger
1094- // but is not receiving power anymore because the battery is full.
1095- //
1096- // 2. Don't wake the device when plugged into a wireless charger if the
1097- // battery already appears to be mostly full. This situation may indicate
1098- // that the device was resting on the charger the whole time and simply
1099- // wasn't receiving power because the battery was full. We can't tell
1100- // whether the device was just placed on the charger or whether it has
1101- // been there for half of the night slowly discharging until it hit
1102- // the point where it needed to start charging again.
1103- if (wasPowered && !mIsPowered
1104- && oldPlugType == BatteryManager .BATTERY_PLUGGED_WIRELESS ) {
1105- return false ;
1106- }
1107- if (!wasPowered && mIsPowered
1108- && mPlugType == BatteryManager .BATTERY_PLUGGED_WIRELESS
1109- && mBatteryService .getBatteryLevel () >=
1110- WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT ) {
1111- return false ;
1112- }
1113- return true ;
1081+ // Don't wake when powered unless configured to do so.
1082+ if (!mWakeUpWhenPluggedOrUnpluggedConfig ) {
1083+ return false ;
11141084 }
1115- return false ;
1085+
1086+ // FIXME: Need more accurate detection of wireless chargers.
1087+ //
1088+ // We are unable to accurately detect whether the device is resting on the
1089+ // charger unless it is actually receiving power. This causes us some grief
1090+ // because the device might not appear to be plugged into the wireless charger
1091+ // unless it actually charging.
1092+ //
1093+ // To avoid spuriously waking the screen, we apply a special policy to
1094+ // wireless chargers.
1095+ //
1096+ // 1. Don't wake the device when unplugged from wireless charger because
1097+ // it might be that the device is still resting on the wireless charger
1098+ // but is not receiving power anymore because the battery is full.
1099+ //
1100+ // 2. Don't wake the device when plugged into a wireless charger if the
1101+ // battery already appears to be mostly full. This situation may indicate
1102+ // that the device was resting on the charger the whole time and simply
1103+ // wasn't receiving power because the battery was full. We can't tell
1104+ // whether the device was just placed on the charger or whether it has
1105+ // been there for half of the night slowly discharging until it hit
1106+ // the point where it needed to start charging again.
1107+ if (wasPowered && !mIsPowered
1108+ && oldPlugType == BatteryManager .BATTERY_PLUGGED_WIRELESS ) {
1109+ return false ;
1110+ }
1111+ if (!wasPowered && mIsPowered
1112+ && mPlugType == BatteryManager .BATTERY_PLUGGED_WIRELESS
1113+ && mBatteryService .getBatteryLevel () >=
1114+ WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT ) {
1115+ return false ;
1116+ }
1117+
1118+ // If already dreaming and becoming powered, then don't wake.
1119+ if (mIsPowered && (mWakefulness == WAKEFULNESS_NAPPING
1120+ || mWakefulness == WAKEFULNESS_DREAMING )) {
1121+ return false ;
1122+ }
1123+
1124+ // Otherwise wake up!
1125+ return true ;
11161126 }
11171127
11181128 /**
0 commit comments