Merge "Play ripple on pluggedIn event instead of charge event." into sc-dev

This commit is contained in:
Shan Huang
2021-04-29 14:10:14 +00:00
committed by Android (Google) Code Review
4 changed files with 24 additions and 10 deletions

View File

@@ -57,7 +57,7 @@ class WiredChargingRippleController @Inject constructor(
private val windowManager: WindowManager,
private val systemClock: SystemClock
) {
private var charging: Boolean? = null
private var pluggedIn: Boolean? = null
private val rippleEnabled: Boolean = featureFlags.isChargingRippleEnabled &&
!SystemProperties.getBoolean("persist.debug.suppress-charging-ripple", false)
private var normalizedPortPosX: Float = context.resources.getFloat(
@@ -86,18 +86,17 @@ class WiredChargingRippleController @Inject constructor(
val batteryStateChangeCallback = object : BatteryController.BatteryStateChangeCallback {
override fun onBatteryLevelChanged(
level: Int,
pluggedIn: Boolean,
nowCharging: Boolean
nowPluggedIn: Boolean,
charging: Boolean
) {
// Suppresses the ripple when it's disabled, or when the state change comes
// from wireless charging.
if (!rippleEnabled || batteryController.isWirelessCharging) {
if (!rippleEnabled || batteryController.isPluggedInWireless) {
return
}
val wasCharging = charging
charging = nowCharging
// Only triggers when the keyguard is active and the device is just plugged in.
if ((wasCharging == null || !wasCharging) && nowCharging) {
val wasPluggedIn = pluggedIn
pluggedIn = nowPluggedIn
if ((wasPluggedIn == null || !wasPluggedIn) && nowPluggedIn) {
startRippleWithDebounce()
}
}

View File

@@ -42,6 +42,13 @@ public interface BatteryController extends DemoMode, Dumpable,
*/
boolean isPluggedIn();
/**
* Returns {@code true} if the device is currently plugged in via wireless charger.
*/
default boolean isPluggedInWireless() {
return false;
}
/**
* Returns {@code true} if the device is currently in power save mode.
*/

View File

@@ -72,6 +72,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
protected int mLevel;
protected boolean mPluggedIn;
private boolean mPluggedInWireless;
protected boolean mCharging;
private boolean mStateUnknown = false;
private boolean mCharged;
@@ -175,6 +176,8 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
* intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
/ intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100));
mPluggedIn = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
mPluggedInWireless = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0)
== BatteryManager.BATTERY_PLUGGED_WIRELESS;
final int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
BatteryManager.BATTERY_STATUS_UNKNOWN);
@@ -259,6 +262,11 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
return mWirelessCharging;
}
@Override
public boolean isPluggedInWireless() {
return mPluggedInWireless;
}
@Override
public void getEstimatedTimeRemainingString(EstimateFetchCompletion completion) {
// Need to fetch or refresh the estimate, but it may involve binder calls so offload the

View File

@@ -71,8 +71,8 @@ class WiredChargingRippleControllerTest : SysuiTestCase() {
// Verify ripple added to window manager.
captor.value.onBatteryLevelChanged(
0 /* unusedBatteryLevel */,
false /* plugged in */,
true /* charging */)
true /* plugged in */,
false /* charging */)
val attachListenerCaptor =
ArgumentCaptor.forClass(View.OnAttachStateChangeListener::class.java)
verify(rippleView).addOnAttachStateChangeListener(attachListenerCaptor.capture())