From be92318d566502630f1d8a85b1c0bde8d84350ae Mon Sep 17 00:00:00 2001 From: Vania Januar Date: Wed, 3 May 2023 14:08:43 +0100 Subject: [PATCH] Do not dismiss USI notification when stylus is bluetooth connected. Test: StylusUsiPowerUiTest, StylusUsiPowerStartableTest Bug: 280444475 Change-Id: I8642c1b98c1e6f5d67ccdd7c956963afe2145672 --- .../systemui/stylus/StylusUsiPowerStartable.kt | 8 -------- .../android/systemui/stylus/StylusUsiPowerUI.kt | 7 ++++++- .../stylus/StylusUsiPowerStartableTest.kt | 14 -------------- .../systemui/stylus/StylusUsiPowerUiTest.kt | 15 ++++----------- 4 files changed, 10 insertions(+), 34 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerStartable.kt b/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerStartable.kt index 3667392b515e0..c1b86ab77ab86 100644 --- a/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerStartable.kt +++ b/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerStartable.kt @@ -50,14 +50,6 @@ constructor( } } - override fun onStylusBluetoothConnected(deviceId: Int, btAddress: String) { - stylusUsiPowerUi.refresh() - } - - override fun onStylusBluetoothDisconnected(deviceId: Int, btAddress: String) { - stylusUsiPowerUi.refresh() - } - override fun onStylusUsiBatteryStateChanged( deviceId: Int, eventTimeMillis: Long, diff --git a/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerUI.kt b/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerUI.kt index 21b0efadb8d5b..dd261ba742e5a 100644 --- a/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerUI.kt +++ b/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerUI.kt @@ -94,12 +94,17 @@ constructor( return@refreshNotification } + // Only hide notification in two cases: battery has been recharged above the + // threshold, or user has dismissed or clicked notification ("suppression"). + if (suppressed || !batteryBelowThreshold) { + hideNotification() + } + if (!batteryBelowThreshold) { // Reset suppression when stylus battery is recharged, so that the next time // it reaches a low battery, the notification will show again. suppressed = false } - hideNotification() } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerStartableTest.kt b/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerStartableTest.kt index 3db0ecc4e8df7..a5e52a469f973 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerStartableTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerStartableTest.kt @@ -112,20 +112,6 @@ class StylusUsiPowerStartableTest : SysuiTestCase() { verifyZeroInteractions(stylusUsiPowerUi) } - @Test - fun onStylusBluetoothConnected_refreshesNotification() { - startable.onStylusBluetoothConnected(STYLUS_DEVICE_ID, "ANY") - - verify(stylusUsiPowerUi, times(1)).refresh() - } - - @Test - fun onStylusBluetoothDisconnected_refreshesNotification() { - startable.onStylusBluetoothDisconnected(STYLUS_DEVICE_ID, "ANY") - - verify(stylusUsiPowerUi, times(1)).refresh() - } - @Test fun onStylusUsiBatteryStateChanged_batteryPresentValidCapacity_refreshesNotification() { val batteryState = FixedCapacityBatteryState(0.1f) diff --git a/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerUiTest.kt b/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerUiTest.kt index 572aca9c0f426..90821bdef0bef 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerUiTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerUiTest.kt @@ -45,6 +45,7 @@ import org.junit.runner.RunWith import org.mockito.ArgumentCaptor import org.mockito.Captor import org.mockito.Mock +import org.mockito.Mockito.clearInvocations import org.mockito.Mockito.doNothing import org.mockito.Mockito.inOrder import org.mockito.Mockito.never @@ -194,22 +195,14 @@ class StylusUsiPowerUiTest : SysuiTestCase() { } @Test - fun refresh_hasConnectedBluetoothStylus_cancelsNotification() { - whenever(inputManager.inputDeviceIds).thenReturn(intArrayOf(0)) - - stylusUsiPowerUi.refresh() - - verify(notificationManager).cancel(R.string.stylus_battery_low_percentage) - } - - @Test - fun refresh_hasConnectedBluetoothStylus_existingNotification_cancelsNotification() { + fun refresh_hasConnectedBluetoothStylus_existingNotification_doesNothing() { stylusUsiPowerUi.updateBatteryState(0, FixedCapacityBatteryState(0.1f)) whenever(inputManager.inputDeviceIds).thenReturn(intArrayOf(0)) + clearInvocations(notificationManager) stylusUsiPowerUi.refresh() - verify(notificationManager).cancel(R.string.stylus_battery_low_percentage) + verifyNoMoreInteractions(notificationManager) } @Test