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

Commit 34449d5d authored by Omar Elmekkawy's avatar Omar Elmekkawy Committed by Android (Google) Code Review
Browse files

Merge "Fix a crash on desk return on external displays" into main

parents bd62aa65 16f9b978
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1028,7 +1028,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,

    @Override
    public void onDeskActivated(int deskId, int displayId) {
        if (!mDesktopTilingDecorViewModel.onDeskActivated(deskId)) {
        if (mDesktopTilingDecorViewModel.tilingDeskActive(deskId)) {
            return;
        }
        final DesktopRepository repository = mDesktopUserRepositories.getCurrent();
+28 −30
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.app.ActivityManager
import android.app.ActivityManager.RunningTaskInfo
import android.content.Context
import android.graphics.Rect
import android.util.ArraySet
import android.util.SparseArray
import android.window.DisplayAreaInfo
import android.window.WindowContainerTransaction
@@ -80,7 +79,6 @@ class DesktopTilingDecorViewModel(
    @VisibleForTesting
    var tilingHandlerByUserAndDeskId = SparseArray<SparseArray<DesktopTilingWindowDecoration>>()
    var currentUserId: Int = -1
    val disconnectedDisplayDesks = ArraySet<Int>()

    init {
        // TODO(b/374309287): Move this interface implementation to
@@ -200,7 +198,6 @@ class DesktopTilingDecorViewModel(
                if (disconnectedDisplayId == handler.displayId) {
                    handler.resetTilingSession(shouldPersistTilingData = true)
                    desksToRemove.add(desk)
                    disconnectedDisplayDesks.add(desk)
                }
            }
            desksToRemove.forEach { desk -> userHandlerList.remove(desk) }
@@ -279,9 +276,10 @@ class DesktopTilingDecorViewModel(
        tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)?.hideDividerBar()
    }

    /** Removes [deskId] from the previously deactivated desks to mark it's activation. */
    fun onDeskActivated(deskId: Int): Boolean =
        disconnectedDisplayDesks.remove(deskId) || !tilingHandlerByUserAndDeskId.contains(deskId)
    /** Returns whether [deskId] already exists and active or needs initialization. */
    fun tilingDeskActive(deskId: Int): Boolean =
        tilingHandlerByUserAndDeskId[currentUserId]?.contains(deskId) ?: false


    /** Destroys a tiling session for a removed desk. */
    fun onDeskRemoved(deskId: Int) {
+18 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.windowdecor.WindowDecorationWrapper
import com.android.wm.shell.windowdecor.common.WindowDecorTaskResourceLoader
import com.google.common.truth.Truth.assertThat
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainCoroutineDispatcher
import org.junit.Before
@@ -303,6 +304,23 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
        verify(desktopTilingDecoration2, times(1)).resetTilingSession(true)
    }

    @Test
    fun onDeskActivated_ReturnsTrueIfDeskExistsFalseOtherwise() {
        desktopTilingDecorViewModel.onUserChange(1)
        val decorationByDeskId = SparseArray<DesktopTilingWindowDecoration>()
        decorationByDeskId.put(1, desktopTilingDecoration)
        whenever(desktopTilingDecoration.displayId).thenReturn(1)
        desktopTilingDecorViewModel.tilingHandlerByUserAndDeskId.put(1, decorationByDeskId)

        assertEquals(true, desktopTilingDecorViewModel.tilingDeskActive(1))

        desktopTilingDecorViewModel.onDisplayDisconnected(
            disconnectedDisplayId = 1,
        )

        assertEquals(desktopTilingDecorViewModel.tilingDeskActive(1), false)
    }

    @Test
    fun moveTaskToFront_shouldRoute_toCorrectTilingDecoration() {
        val decorationByDisplayId = SparseArray<DesktopTilingWindowDecoration>()