Merge "Fix double ripple when the device is docked." into tm-qpr-dev
This commit is contained in:
@@ -61,7 +61,7 @@ class WiredChargingRippleController @Inject constructor(
|
|||||||
private val systemClock: SystemClock,
|
private val systemClock: SystemClock,
|
||||||
private val uiEventLogger: UiEventLogger
|
private val uiEventLogger: UiEventLogger
|
||||||
) {
|
) {
|
||||||
private var pluggedIn: Boolean? = null
|
private var pluggedIn: Boolean = false
|
||||||
private val rippleEnabled: Boolean = featureFlags.isEnabled(Flags.CHARGING_RIPPLE) &&
|
private val rippleEnabled: Boolean = featureFlags.isEnabled(Flags.CHARGING_RIPPLE) &&
|
||||||
!SystemProperties.getBoolean("persist.debug.suppress-charging-ripple", false)
|
!SystemProperties.getBoolean("persist.debug.suppress-charging-ripple", false)
|
||||||
private var normalizedPortPosX: Float = context.resources.getFloat(
|
private var normalizedPortPosX: Float = context.resources.getFloat(
|
||||||
@@ -99,15 +99,17 @@ class WiredChargingRippleController @Inject constructor(
|
|||||||
nowPluggedIn: Boolean,
|
nowPluggedIn: Boolean,
|
||||||
charging: Boolean
|
charging: Boolean
|
||||||
) {
|
) {
|
||||||
// Suppresses the ripple when the state change comes from wireless charging.
|
// Suppresses the ripple when the state change comes from wireless charging or
|
||||||
if (batteryController.isPluggedInWireless) {
|
// its dock.
|
||||||
|
if (batteryController.isPluggedInWireless ||
|
||||||
|
batteryController.isChargingSourceDock) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val wasPluggedIn = pluggedIn
|
|
||||||
pluggedIn = nowPluggedIn
|
if (!pluggedIn && nowPluggedIn) {
|
||||||
if ((wasPluggedIn == null || !wasPluggedIn) && nowPluggedIn) {
|
|
||||||
startRippleWithDebounce()
|
startRippleWithDebounce()
|
||||||
}
|
}
|
||||||
|
pluggedIn = nowPluggedIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
batteryController.addCallback(batteryStateChangeCallback)
|
batteryController.addCallback(batteryStateChangeCallback)
|
||||||
|
|||||||
@@ -118,6 +118,17 @@ public interface BatteryController extends DemoMode, Dumpable,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if the charging source is
|
||||||
|
* {@link android.os.BatteryManager#BATTERY_PLUGGED_DOCK}.
|
||||||
|
*
|
||||||
|
* <P>Note that charging from dock is not considered as wireless charging. In other words,
|
||||||
|
* {@link BatteryController#isWirelessCharging()} and this are mutually exclusive.
|
||||||
|
*/
|
||||||
|
default boolean isChargingSourceDock() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A listener that will be notified whenever a change in battery level or power save mode has
|
* A listener that will be notified whenever a change in battery level or power save mode has
|
||||||
* occurred.
|
* occurred.
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
|||||||
|
|
||||||
protected int mLevel;
|
protected int mLevel;
|
||||||
protected boolean mPluggedIn;
|
protected boolean mPluggedIn;
|
||||||
private boolean mPluggedInWireless;
|
private int mPluggedChargingSource;
|
||||||
protected boolean mCharging;
|
protected boolean mCharging;
|
||||||
private boolean mStateUnknown = false;
|
private boolean mStateUnknown = false;
|
||||||
private boolean mCharged;
|
private boolean mCharged;
|
||||||
@@ -195,10 +195,8 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
|||||||
mLevel = (int)(100f
|
mLevel = (int)(100f
|
||||||
* intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
|
* intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
|
||||||
/ intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100));
|
/ intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100));
|
||||||
mPluggedIn = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
|
mPluggedChargingSource = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
|
||||||
mPluggedInWireless = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0)
|
mPluggedIn = mPluggedChargingSource != 0;
|
||||||
== BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
|
||||||
|
|
||||||
final int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
|
final int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
|
||||||
BatteryManager.BATTERY_STATUS_UNKNOWN);
|
BatteryManager.BATTERY_STATUS_UNKNOWN);
|
||||||
mCharged = status == BatteryManager.BATTERY_STATUS_FULL;
|
mCharged = status == BatteryManager.BATTERY_STATUS_FULL;
|
||||||
@@ -284,7 +282,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPluggedInWireless() {
|
public boolean isPluggedInWireless() {
|
||||||
return mPluggedInWireless;
|
return mPluggedChargingSource == BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -441,4 +439,9 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
|
|||||||
registerReceiver();
|
registerReceiver();
|
||||||
updatePowerSave();
|
updatePowerSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChargingSourceDock() {
|
||||||
|
return mPluggedChargingSource == BatteryManager.BATTERY_PLUGGED_DOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ class WiredChargingRippleControllerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
// Verify ripple added to window manager.
|
// Verify ripple added to window manager.
|
||||||
captor.value.onBatteryLevelChanged(
|
captor.value.onBatteryLevelChanged(
|
||||||
0 /* unusedBatteryLevel */,
|
/* unusedBatteryLevel= */ 0,
|
||||||
true /* plugged in */,
|
/* plugged in= */ true,
|
||||||
false /* charging */)
|
/* charging= */ false)
|
||||||
val attachListenerCaptor =
|
val attachListenerCaptor =
|
||||||
ArgumentCaptor.forClass(View.OnAttachStateChangeListener::class.java)
|
ArgumentCaptor.forClass(View.OnAttachStateChangeListener::class.java)
|
||||||
verify(rippleView).addOnAttachStateChangeListener(attachListenerCaptor.capture())
|
verify(rippleView).addOnAttachStateChangeListener(attachListenerCaptor.capture())
|
||||||
@@ -144,4 +144,22 @@ class WiredChargingRippleControllerTest : SysuiTestCase() {
|
|||||||
// Verify that ripple is triggered.
|
// Verify that ripple is triggered.
|
||||||
verify(rippleView).addOnAttachStateChangeListener(ArgumentMatchers.any())
|
verify(rippleView).addOnAttachStateChangeListener(ArgumentMatchers.any())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testRipple_whenDocked_doesNotPlayRipple() {
|
||||||
|
`when`(batteryController.isChargingSourceDock).thenReturn(true)
|
||||||
|
val captor = ArgumentCaptor
|
||||||
|
.forClass(BatteryController.BatteryStateChangeCallback::class.java)
|
||||||
|
verify(batteryController).addCallback(captor.capture())
|
||||||
|
|
||||||
|
captor.value.onBatteryLevelChanged(
|
||||||
|
/* unusedBatteryLevel= */ 0,
|
||||||
|
/* plugged in= */ true,
|
||||||
|
/* charging= */ false)
|
||||||
|
|
||||||
|
val attachListenerCaptor =
|
||||||
|
ArgumentCaptor.forClass(View.OnAttachStateChangeListener::class.java)
|
||||||
|
verify(rippleView, never()).addOnAttachStateChangeListener(attachListenerCaptor.capture())
|
||||||
|
verify(windowManager, never()).addView(eq(rippleView), any<WindowManager.LayoutParams>())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerSaveState;
|
import android.os.PowerSaveState;
|
||||||
@@ -196,4 +197,26 @@ public class BatteryControllerTest extends SysuiTestCase {
|
|||||||
TestableLooper.get(this).processAllMessages();
|
TestableLooper.get(this).processAllMessages();
|
||||||
// Should not throw an exception
|
// Should not throw an exception
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void batteryStateChanged_withChargingSourceDock_isChargingSourceDockTrue() {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_CHARGING);
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_PLUGGED, BatteryManager.BATTERY_PLUGGED_DOCK);
|
||||||
|
|
||||||
|
mBatteryController.onReceive(getContext(), intent);
|
||||||
|
|
||||||
|
Assert.assertTrue(mBatteryController.isChargingSourceDock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void batteryStateChanged_withChargingSourceNotDock_isChargingSourceDockFalse() {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_DISCHARGING);
|
||||||
|
intent.putExtra(BatteryManager.EXTRA_PLUGGED, BatteryManager.BATTERY_PLUGGED_WIRELESS);
|
||||||
|
|
||||||
|
mBatteryController.onReceive(getContext(), intent);
|
||||||
|
|
||||||
|
Assert.assertFalse(mBatteryController.isChargingSourceDock());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user