From c644d2b9685d4d7ce14766b3521655d39394ba3d Mon Sep 17 00:00:00 2001 From: Vania Januar Date: Fri, 23 Dec 2022 10:18:10 +0000 Subject: Unsuppress USI low battery notifications when new stylus used. This handles an edge case where a stylus with a different vendor/product ID is used after a previous stylus has received a low battery notification, and that notification has been dismissed. Unsuppressing the notification means that if the new stylus's battery is also low, a new notification will be sent. Note that this means if a stylus has the same vendor/product ID as the previous one, there is no way to differentiate them. Bug: 262689155 Test: atest StylusUsiPowerStartableTest Change-Id: Ia8a661a131e241216ecf9aaff89e36cb40860f91 --- .../com/android/systemui/stylus/StylusUsiPowerStartable.kt | 11 +++++++++++ .../android/systemui/stylus/StylusUsiPowerStartableTest.kt | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerStartable.kt b/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerStartable.kt index 5a8850a9f89b..dde2a80b05f7 100644 --- a/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerStartable.kt +++ b/packages/SystemUI/src/com/android/systemui/stylus/StylusUsiPowerStartable.kt @@ -39,6 +39,17 @@ constructor( private val featureFlags: FeatureFlags, ) : CoreStartable, StylusManager.StylusCallback, StylusManager.StylusBatteryCallback { + override fun onStylusAdded(deviceId: Int) { + // On some devices, the addition of a new internal stylus indicates the use of a + // USI stylus with a different vendor/product ID. We would therefore like to reset + // the battery notification suppression, in case the user has dismissed a low battery + // notification of the previous stylus. + val device = inputManager.getInputDevice(deviceId) ?: return + if (!device.isExternal) { + stylusUsiPowerUi.updateSuppression(false) + } + } + override fun onStylusBluetoothConnected(deviceId: Int, btAddress: String) { stylusUsiPowerUi.refresh() } 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 1cccd65c8dbc..cc6be5e09fbc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerStartableTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/stylus/StylusUsiPowerStartableTest.kt @@ -91,6 +91,20 @@ class StylusUsiPowerStartableTest : SysuiTestCase() { verify(stylusUsiPowerUi, times(1)).init() } + @Test + fun onStylusAdded_internal_updatesNotificationSuppression() { + startable.onStylusAdded(STYLUS_DEVICE_ID) + + verify(stylusUsiPowerUi, times(1)).updateSuppression(false) + } + + @Test + fun onStylusAdded_external_noop() { + startable.onStylusAdded(EXTERNAL_DEVICE_ID) + + verifyZeroInteractions(stylusUsiPowerUi) + } + @Test fun onStylusBluetoothConnected_refreshesNotification() { startable.onStylusBluetoothConnected(STYLUS_DEVICE_ID, "ANY") -- cgit v1.2.3-59-g8ed1b