Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fd918e8e authored by Vania Januar's avatar Vania Januar Committed by Automerger Merge Worker
Browse files

Merge "Always update the InputDevice ID in the USI low battery notification"...

Merge "Always update the InputDevice ID in the USI low battery notification" into udc-qpr-dev am: a621f8cc am: 4c2c55e7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23917243



Change-Id: I52e643d625c575e64556ffdd8c37da78149b57c9
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 9a15719f 4c2c55e7
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -64,9 +64,9 @@ constructor(
    // These values must only be accessed on the handler.
    private var batteryCapacity = 1.0f
    private var suppressed = false
    private var inputDeviceId: Int? = null
    private var instanceId: InstanceId? = null

    @VisibleForTesting var inputDeviceId: Int? = null
      private set
    @VisibleForTesting var instanceIdSequence = InstanceIdSequence(1 shl 13)

    fun init() {
@@ -110,10 +110,10 @@ constructor(

    fun updateBatteryState(deviceId: Int, batteryState: BatteryState) {
        handler.post updateBattery@{
            inputDeviceId = deviceId
            if (batteryState.capacity == batteryCapacity || batteryState.capacity <= 0f)
                return@updateBattery

            inputDeviceId = deviceId
            batteryCapacity = batteryState.capacity
            debugLog {
                "Updating notification battery state to $batteryCapacity " +
+10 −0
Original line number Diff line number Diff line
@@ -125,6 +125,16 @@ class StylusUsiPowerUiTest : SysuiTestCase() {
        verifyNoMoreInteractions(notificationManager)
    }

    @Test
    fun updateBatteryState_capacitySame_inputDeviceChanges_updatesInputDeviceId() {
        stylusUsiPowerUi.updateBatteryState(0, FixedCapacityBatteryState(0.1f))
        stylusUsiPowerUi.updateBatteryState(1, FixedCapacityBatteryState(0.1f))

        assertThat(stylusUsiPowerUi.inputDeviceId).isEqualTo(1)
        verify(notificationManager, times(1))
            .notify(eq(R.string.stylus_battery_low_percentage), any())
    }

    @Test
    fun updateBatteryState_existingNotification_capacityAboveThreshold_cancelsNotification() {
        stylusUsiPowerUi.updateBatteryState(0, FixedCapacityBatteryState(0.1f))