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

Commit d72d8b37 authored by Kazuki Takise's avatar Kazuki Takise Committed by Android (Google) Code Review
Browse files

Merge changes Iabff024e,I42365b36 into main

* changes:
  Use background thread instead of main thread for FocusedDisplayRepository
  Add clarification comment to TaskInfo#isFocused
parents 98e0bab7 92a023f7
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -275,7 +275,10 @@ public class TaskInfo {
    public int parentTaskId;

    /**
     * Whether this task is focused.
     * Whether this task is focused on the display. This means the task receives input events that
     * target the display.
     * CAUTION: This can be true for multiple tasks especially when multiple displays are connected
     * in the system.
     * @hide
     */
    public boolean isFocused;
+5 −6
Original line number Diff line number Diff line
@@ -19,8 +19,7 @@ package com.android.systemui.display.data.repository
import android.annotation.MainThread
import android.view.Display.DEFAULT_DISPLAY
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.FocusedDisplayRepoLog
@@ -43,15 +42,15 @@ import kotlinx.coroutines.flow.stateIn
class FocusedDisplayRepository
@Inject
constructor(
    @Application val scope: CoroutineScope,
    @Main private val mainExecutor: Executor,
    @Background val backgroundScope: CoroutineScope,
    @Background private val backgroundExecutor: Executor,
    transitions: ShellTransitions,
    @FocusedDisplayRepoLog logBuffer: LogBuffer,
) {
    val focusedTask: Flow<Int> =
        conflatedCallbackFlow {
                val listener = FocusTransitionListener { displayId -> trySend(displayId) }
                transitions.setFocusTransitionListener(listener, mainExecutor)
                transitions.setFocusTransitionListener(listener, backgroundExecutor)
                awaitClose { transitions.unsetFocusTransitionListener(listener) }
            }
            .onEach {
@@ -65,5 +64,5 @@ constructor(

    /** Provides the currently focused display. */
    val focusedDisplayId: StateFlow<Int>
        get() = focusedTask.stateIn(scope, SharingStarted.Eagerly, DEFAULT_DISPLAY)
        get() = focusedTask.stateIn(backgroundScope, SharingStarted.Eagerly, DEFAULT_DISPLAY)
}