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

Commit bb83d676 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ie40084f4,I0a605152 into main

* changes:
  Stop using DesktopModeStatus in drag and drop
  Stop using DesktopModeStatus in Shell Crash Handler
parents 4ab9c37f 99c6b978
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.
+7 −4
Original line number Diff line number Diff line
@@ -1644,7 +1644,8 @@ public abstract class WMShellModule {
            GlobalDragListener globalDragListener,
            Transitions transitions,
            Lazy<BubbleController> bubbleControllerLazy,
            @ShellMainThread ShellExecutor mainExecutor) {
            @ShellMainThread ShellExecutor mainExecutor,
            DesktopState desktopState) {
        return new DragAndDropController(
                context,
                shellInit,
@@ -1662,7 +1663,8 @@ public abstract class WMShellModule {
                        return bubbleControllerLazy.get();
                    }
                },
                mainExecutor);
                mainExecutor,
                desktopState);
    }

    //
@@ -1706,11 +1708,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
+8 −5
Original line number Diff line number Diff line
@@ -69,20 +69,20 @@ import com.android.wm.shell.common.RemoteCallable;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.annotations.ExternalMainThread;
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
import com.android.wm.shell.shared.desktopmode.DesktopState;
import com.android.wm.shell.splitscreen.SplitScreenController;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;

import dagger.Lazy;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.function.Consumer;
import java.util.function.Function;

import dagger.Lazy;

/**
 * Handles the global drag and drop handling for the Shell.
 */
@@ -103,6 +103,7 @@ public class DragAndDropController implements RemoteCallable<DragAndDropControll
    private final IconProvider mIconProvider;
    private final GlobalDragListener mGlobalDragListener;
    private final Transitions mTransitions;
    private final DesktopState mDesktopState;
    private SplitScreenController mSplitScreen;
    private Lazy<BubbleBarDragListener> mBubbleBarDragController;
    private ShellExecutor mMainExecutor;
@@ -148,7 +149,8 @@ public class DragAndDropController implements RemoteCallable<DragAndDropControll
            GlobalDragListener globalDragListener,
            Transitions transitions,
            Lazy<BubbleBarDragListener> bubbleBarDragController,
            ShellExecutor mainExecutor) {
            ShellExecutor mainExecutor,
            DesktopState desktopState) {
        mContext = context;
        mShellController = shellController;
        mShellCommandHandler = shellCommandHandler;
@@ -160,6 +162,7 @@ public class DragAndDropController implements RemoteCallable<DragAndDropControll
        mTransitions = transitions;
        mBubbleBarDragController = bubbleBarDragController;
        mMainExecutor = mainExecutor;
        mDesktopState = desktopState;
        shellInit.addInitCallback(this::onInit, this);
    }

@@ -347,7 +350,7 @@ public class DragAndDropController implements RemoteCallable<DragAndDropControll
            final ActivityManager.RunningTaskInfo taskInfo = dragSession.runningTaskInfo;
            // Desktop tasks will have their own drag handling.
            final boolean isDesktopDrag = taskInfo != null && taskInfo.isFreeform()
                    && DesktopModeStatus.canEnterDesktopMode(mContext);
                    && mDesktopState.canEnterDesktopMode();
            pd.isHandlingDrag = DragUtils.canHandleDrag(event) && !isDesktopDrag;
            ProtoLog.v(ShellProtoLogGroup.WM_SHELL_DRAG_AND_DROP,
                    "Clip description: handlingDrag=%b itemCount=%d mimeTypes=%s flags=%s",
+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
+6 −3
Original line number Diff line number Diff line
@@ -50,19 +50,20 @@ import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.bubbles.bar.BubbleBarDragListener;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.shared.desktopmode.FakeDesktopState;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;

import dagger.Lazy;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import dagger.Lazy;

/**
 * Tests for the drag and drop controller.
 */
@@ -96,16 +97,18 @@ public class DragAndDropControllerTest extends ShellTestCase {
    private GlobalDragListener mGlobalDragListener;
    @Mock
    private Lazy<BubbleBarDragListener> mBubbleBarDragControllerLazy;
    private FakeDesktopState mDesktopState;

    private DragAndDropController mController;

    @Before
    public void setUp() throws RemoteException {
        mDesktopState = new FakeDesktopState();
        MockitoAnnotations.initMocks(this);
        mController = new DragAndDropController(mContext, mShellInit, mShellController,
                mShellCommandHandler, mShellTaskOrganizer, mDisplayController, mUiEventLogger,
                mIconProvider, mGlobalDragListener, mTransitions, mBubbleBarDragControllerLazy,
                mMainExecutor);
                mMainExecutor, mDesktopState);
        mController.onInit();
    }