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

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

Merge "Track USI session with bluetooth stylus position." into udc-dev am:...

Merge "Track USI session with bluetooth stylus position." into udc-dev am: 4a3b5e4b am: efc2f2c0

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



Change-Id: Ia6565efadb22f407fb74d24371e83c4e5f64c807
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 675ce236 efc2f2c0
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -261,22 +261,26 @@ constructor(
    private fun trackAndLogUsiSession(deviceId: Int, batteryStateValid: Boolean) {
        // TODO(b/268618918) handle cases where an invalid battery callback from a previous stylus
        //  is sent after the actual valid callback
        val hasBtConnection = if (inputDeviceBtSessionIdMap.isEmpty()) 0 else 1

        if (batteryStateValid && usiSessionId == null) {
            logDebug { "USI battery newly present, entering new USI session: $deviceId" }
            usiSessionId = instanceIdSequence.newInstanceId()
            uiEventLogger.logWithInstanceId(
            uiEventLogger.logWithInstanceIdAndPosition(
                StylusUiEvent.USI_STYLUS_BATTERY_PRESENCE_FIRST_DETECTED,
                0,
                null,
                usiSessionId
                usiSessionId,
                hasBtConnection,
            )
        } else if (!batteryStateValid && usiSessionId != null) {
            logDebug { "USI battery newly absent, exiting USI session: $deviceId" }
            uiEventLogger.logWithInstanceId(
            uiEventLogger.logWithInstanceIdAndPosition(
                StylusUiEvent.USI_STYLUS_BATTERY_PRESENCE_REMOVED,
                0,
                null,
                usiSessionId
                usiSessionId,
                hasBtConnection,
            )
            usiSessionId = null
        }
+26 −6
Original line number Diff line number Diff line
@@ -507,11 +507,29 @@ class StylusManagerTest : SysuiTestCase() {
        stylusManager.onBatteryStateChanged(STYLUS_DEVICE_ID, 1, batteryState)

        verify(uiEventLogger, times(1))
            .logWithInstanceId(
            .logWithInstanceIdAndPosition(
                StylusUiEvent.USI_STYLUS_BATTERY_PRESENCE_FIRST_DETECTED,
                0,
                null,
                InstanceId.fakeInstanceId(instanceIdSequenceFake.lastInstanceId)
                InstanceId.fakeInstanceId(instanceIdSequenceFake.lastInstanceId),
                0,
            )
    }

    @Test
    fun onBatteryStateChanged_batteryPresent_btStylusPresent_logsSessionStart() {
        whenever(batteryState.isPresent).thenReturn(true)
        stylusManager.onInputDeviceAdded(BT_STYLUS_DEVICE_ID)

        stylusManager.onBatteryStateChanged(STYLUS_DEVICE_ID, 1, batteryState)

        verify(uiEventLogger, times(1))
            .logWithInstanceIdAndPosition(
                StylusUiEvent.USI_STYLUS_BATTERY_PRESENCE_FIRST_DETECTED,
                0,
                null,
                InstanceId.fakeInstanceId(instanceIdSequenceFake.lastInstanceId),
                1,
            )
    }

@@ -545,19 +563,21 @@ class StylusManagerTest : SysuiTestCase() {
        stylusManager.onBatteryStateChanged(STYLUS_DEVICE_ID, 1, batteryState)

        verify(uiEventLogger, times(1))
            .logWithInstanceId(
            .logWithInstanceIdAndPosition(
                StylusUiEvent.USI_STYLUS_BATTERY_PRESENCE_FIRST_DETECTED,
                0,
                null,
                instanceId
                instanceId,
                0
            )

        verify(uiEventLogger, times(1))
            .logWithInstanceId(
            .logWithInstanceIdAndPosition(
                StylusUiEvent.USI_STYLUS_BATTERY_PRESENCE_REMOVED,
                0,
                null,
                instanceId
                instanceId,
                0
            )
    }