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

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

Merge "StylusManager registers bluetooth devices present before start." into udc-dev am: 4680610c

parents b2fcd99d 4680610c
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -353,6 +353,8 @@ constructor(
                    // before CoreStartables run, and will not be removed.
                    // before CoreStartables run, and will not be removed.
                    // In many cases, it reports the battery level of the stylus.
                    // In many cases, it reports the battery level of the stylus.
                    registerBatteryListener(deviceId)
                    registerBatteryListener(deviceId)
                } else if (device.bluetoothAddress != null) {
                    onStylusBluetoothConnected(deviceId, device.bluetoothAddress)
                }
                }
            }
            }
        }
        }
+24 −0
Original line number Original line Diff line number Diff line
@@ -101,9 +101,12 @@ class StylusManagerTest : SysuiTestCase() {
        whenever(stylusDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(true)
        whenever(stylusDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(true)
        whenever(btStylusDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(true)
        whenever(btStylusDevice.supportsSource(InputDevice.SOURCE_STYLUS)).thenReturn(true)


        whenever(btStylusDevice.isExternal).thenReturn(true)

        whenever(stylusDevice.bluetoothAddress).thenReturn(null)
        whenever(stylusDevice.bluetoothAddress).thenReturn(null)
        whenever(btStylusDevice.bluetoothAddress).thenReturn(STYLUS_BT_ADDRESS)
        whenever(btStylusDevice.bluetoothAddress).thenReturn(STYLUS_BT_ADDRESS)


        whenever(btStylusDevice.batteryState).thenReturn(batteryState)
        whenever(stylusDevice.batteryState).thenReturn(batteryState)
        whenever(stylusDevice.batteryState).thenReturn(batteryState)
        whenever(batteryState.capacity).thenReturn(0.5f)
        whenever(batteryState.capacity).thenReturn(0.5f)


@@ -147,6 +150,27 @@ class StylusManagerTest : SysuiTestCase() {
        verify(inputManager, times(1)).registerInputDeviceListener(any(), any())
        verify(inputManager, times(1)).registerInputDeviceListener(any(), any())
    }
    }


    @Test
    fun startListener_hasNotStarted_registersExistingBluetoothDevice() {
        whenever(inputManager.inputDeviceIds).thenReturn(intArrayOf(BT_STYLUS_DEVICE_ID))

        stylusManager =
            StylusManager(
                mContext,
                inputManager,
                bluetoothAdapter,
                handler,
                EXECUTOR,
                featureFlags,
                uiEventLogger
            )

        stylusManager.startListener()

        verify(bluetoothAdapter, times(1))
            .addOnMetadataChangedListener(bluetoothDevice, EXECUTOR, stylusManager)
    }

    @Test
    @Test
    fun startListener_hasStarted_doesNothing() {
    fun startListener_hasStarted_doesNothing() {
        stylusManager.startListener()
        stylusManager.startListener()