From 38ea102635b090c3696a52b822d69c909047b178 Mon Sep 17 00:00:00 2001 From: Shan Huang Date: Thu, 29 Apr 2021 12:01:45 +0800 Subject: [PATCH] Play ripple on pluggedIn event instead of charge event. Also differentiate between wireless charging and pluggedIn state in BatteryController. Bug: 184912336 Test: Manual. SystemUITests. Change-Id: Icbaf8f5b43adaa40b70ebdef200658c932dad19b --- .../charging/WiredChargingRippleController.kt | 15 +++++++-------- .../statusbar/policy/BatteryController.java | 7 +++++++ .../statusbar/policy/BatteryControllerImpl.java | 8 ++++++++ .../charging/WiredChargingRippleControllerTest.kt | 4 ++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/charging/WiredChargingRippleController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/charging/WiredChargingRippleController.kt index 761a1d6801bf9..91415f2788a48 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/charging/WiredChargingRippleController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/charging/WiredChargingRippleController.kt @@ -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() } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java index 6ae5e904e4c7d..95a7316f7a587 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java @@ -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. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java index 288eb3df3225b..9e2c478fbd695 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java @@ -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 diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/charging/WiredChargingRippleControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/charging/WiredChargingRippleControllerTest.kt index 4e404ae94bd94..03744b78e8d5c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/charging/WiredChargingRippleControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/charging/WiredChargingRippleControllerTest.kt @@ -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())