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

Commit 4f54ce8e authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

Stop using DesktopModeStatus in Shell Crash Handler

Bug: 395863348
Test: atest WMShellUnitTests
Flag: EXEMPT (refactor)
Change-Id: I0a605152b96f89d91a8df5f95865b87426a6dff1
parent 0fac36e0
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -17,22 +17,21 @@
package com.android.wm.shell.crashhandling

import android.app.WindowConfiguration
import android.content.Context
import android.view.Display.DEFAULT_DISPLAY
import android.window.DesktopExperienceFlags
import android.window.WindowContainerTransaction
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.HomeIntentProvider
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.DesktopState
import com.android.wm.shell.sysui.ShellInit

/** [ShellCrashHandler] for shell to use when it's being initialized. Currently it only restores
 *  the home task to top.
 **/
class ShellCrashHandler(
    private val context: Context,
    private val shellTaskOrganizer: ShellTaskOrganizer,
    private val homeIntentProvider: HomeIntentProvider,
    private val desktopState: DesktopState,
    shellInit: ShellInit,
) {
    init {
@@ -45,7 +44,7 @@ class ShellCrashHandler(

    private fun handleCrashIfNeeded() {
        // For now only handle crashes when desktop mode is enabled on the device.
        if (DesktopModeStatus.canEnterDesktopMode(context) &&
        if (desktopState.canEnterDesktopMode &&
            !DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            var freeformTaskExists = false
            // If there are running tasks at init, WMShell has crashed but WMCore is still alive.
+3 −2
Original line number Diff line number Diff line
@@ -1706,11 +1706,12 @@ public abstract class WMShellModule {
    @WMSingleton
    @Provides
    static ShellCrashHandler provideShellCrashHandler(
            Context context,
            ShellTaskOrganizer shellTaskOrganizer,
            HomeIntentProvider homeIntentProvider,
            DesktopState desktopState,
            ShellInit shellInit) {
        return new ShellCrashHandler(context, shellTaskOrganizer, homeIntentProvider, shellInit);
        return new ShellCrashHandler(shellTaskOrganizer, homeIntentProvider, desktopState,
                shellInit);
    }

    @WMSingleton
+4 −4
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.HomeIntentProvider
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.FakeDesktopState
import com.android.wm.shell.sysui.ShellInit
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
@@ -53,13 +53,13 @@ class ShellCrashHandlerTest : ShellTestCase() {
    @Rule
    val extendedMockitoRule =
        ExtendedMockitoRule.Builder(this)
            .mockStatic(DesktopModeStatus::class.java)
            .mockStatic(PendingIntent::class.java)
            .build()!!

    private val testExecutor = mock<ShellExecutor>()
    private val context = mock<Context>()
    private val shellTaskOrganizer = mock<ShellTaskOrganizer>()
    private val desktopState = FakeDesktopState()

    private lateinit var homeIntentProvider: HomeIntentProvider
    private lateinit var crashHandler: ShellCrashHandler
@@ -68,13 +68,13 @@ class ShellCrashHandlerTest : ShellTestCase() {

    @Before
    fun setup() {
        whenever(DesktopModeStatus.canEnterDesktopMode(any())).thenReturn(true)
        desktopState.canEnterDesktopMode = true
        whenever(PendingIntent.getActivity(any(), any(), any(), any(), any())).thenReturn(mock())

        shellInit = spy(ShellInit(testExecutor))

        homeIntentProvider = HomeIntentProvider(context)
        crashHandler = ShellCrashHandler(context, shellTaskOrganizer, homeIntentProvider, shellInit)
        crashHandler = ShellCrashHandler(shellTaskOrganizer, homeIntentProvider, desktopState, shellInit)
    }

    @Test