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

Commit 8de56130 authored by Ben Murdoch's avatar Ben Murdoch
Browse files

Initialise visible_task_count state field of DesktopModeTaskUpdate atom.

Statsd needs an initial value for the state field of this atom,
otherwise metrics that slice by the state will be bucketed in an
UNKNOWN bucket.

To not intefere with any other uses of this atom, we define a new
task_event just to mark the initialisation.

Bug: 370478775
Flag: EXEMPT logging only
Test: Manual + atest DesktopModeLoggerTransitionObserverTest
Change-Id: I9efeef6d8a7264818ec0aac77368cb34fae53fa2
parent 2cc5c243
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -156,6 +156,21 @@ class DesktopModeEventLogger {
        )
    }

    fun logTaskInfoStateInit() {
        logTaskUpdate(
            FrameworkStatsLog.DESKTOP_MODE_SESSION_TASK_UPDATE__TASK_EVENT__TASK_INIT_STATSD,
            /* session_id */ 0,
            TaskUpdate(
                visibleTaskCount = 0,
                instanceId = 0,
                uid = 0,
                taskHeight = 0,
                taskWidth = 0,
                taskX = 0,
                taskY = 0)
        )
    }

    private fun logTaskUpdate(taskEvent: Int, sessionId: Int, taskUpdate: TaskUpdate) {
        FrameworkStatsLog.write(
            DESKTOP_MODE_TASK_UPDATE_ATOM_ID,
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ class DesktopModeLoggerTransitionObserver(
        SystemProperties.set(
            VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY,
            VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY_DEFAULT_VALUE)
        desktopModeEventLogger.logTaskInfoStateInit()
    }

    override fun onTransitionReady(
+31 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.wm.shell.desktopmode

import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import com.android.dx.mockito.inline.extended.ExtendedMockito.verify
@@ -397,6 +396,37 @@ class DesktopModeEventLoggerTest : ShellTestCase() {
        }
    }

    @Test
    fun logTaskInfoStateInit_logsTaskInfoChangedStateInit() {
        desktopModeEventLogger.logTaskInfoStateInit()
        verify {
            FrameworkStatsLog.write(eq(FrameworkStatsLog.DESKTOP_MODE_SESSION_TASK_UPDATE),
                /* task_event */
                eq(FrameworkStatsLog.DESKTOP_MODE_SESSION_TASK_UPDATE__TASK_EVENT__TASK_INIT_STATSD),
                /* instance_id */
                eq(0),
                /* uid */
                eq(0),
                /* task_height */
                eq(0),
                /* task_width */
                eq(0),
                /* task_x */
                eq(0),
                /* task_y */
                eq(0),
                /* session_id */
                eq(0),
                /* minimize_reason */
                eq(UNSET_MINIMIZE_REASON),
                /* unminimize_reason */
                eq(UNSET_UNMINIMIZE_REASON),
                /* visible_task_count */
                eq(0)
            )
        }
    }

    private companion object {
        private const val SESSION_ID = 1
        private const val TASK_ID = 1
+3 −0
Original line number Diff line number Diff line
@@ -115,6 +115,9 @@ class DesktopModeLoggerTransitionObserverTest : ShellTestCase() {
    val initRunnableCaptor = ArgumentCaptor.forClass(Runnable::class.java)
    verify(mockShellInit).addInitCallback(initRunnableCaptor.capture(), same(transitionObserver))
    initRunnableCaptor.value.run()
    // verify this initialisation interaction to leave the desktopmodeEventLogger mock in a
    // consistent state with no outstanding interactions when test cases start executing.
    verify(desktopModeEventLogger).logTaskInfoStateInit()
  }

  @Test