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

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

Merge "Refactor wallpaper activity token outside of repo." into main

parents ab639d83 1d94a482
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ import com.android.wm.shell.desktopmode.SpringDragToDesktopTransitionHandler;
import com.android.wm.shell.desktopmode.ToggleResizeDesktopTaskTransitionHandler;
import com.android.wm.shell.desktopmode.WindowDecorCaptionHandleRepository;
import com.android.wm.shell.desktopmode.compatui.SystemModalsTransitionHandler;
import com.android.wm.shell.desktopmode.desktopwallpaperactivity.DesktopWallpaperActivityTokenProvider;
import com.android.wm.shell.desktopmode.education.AppHandleEducationController;
import com.android.wm.shell.desktopmode.education.AppHandleEducationFilter;
import com.android.wm.shell.desktopmode.education.AppToWebEducationController;
@@ -733,7 +734,8 @@ public abstract class WMShellModule {
            FocusTransitionObserver focusTransitionObserver,
            DesktopModeEventLogger desktopModeEventLogger,
            DesktopModeUiEventLogger desktopModeUiEventLogger,
            DesktopTilingDecorViewModel desktopTilingDecorViewModel) {
            DesktopTilingDecorViewModel desktopTilingDecorViewModel,
            DesktopWallpaperActivityTokenProvider desktopWallpaperActivityTokenProvider) {
        return new DesktopTasksController(
                context,
                shellInit,
@@ -764,7 +766,8 @@ public abstract class WMShellModule {
                mainHandler,
                desktopModeEventLogger,
                desktopModeUiEventLogger,
                desktopTilingDecorViewModel);
                desktopTilingDecorViewModel,
                desktopWallpaperActivityTokenProvider);
    }

    @WMSingleton
@@ -1092,6 +1095,7 @@ public abstract class WMShellModule {
            ShellTaskOrganizer shellTaskOrganizer,
            Optional<DesktopMixedTransitionHandler> desktopMixedTransitionHandler,
            Optional<BackAnimationController> backAnimationController,
            DesktopWallpaperActivityTokenProvider desktopWallpaperActivityTokenProvider,
            ShellInit shellInit) {
        return desktopUserRepositories.flatMap(
                repository ->
@@ -1103,6 +1107,7 @@ public abstract class WMShellModule {
                                        shellTaskOrganizer,
                                        desktopMixedTransitionHandler.get(),
                                        backAnimationController.get(),
                                        desktopWallpaperActivityTokenProvider,
                                        shellInit)));
    }

@@ -1306,6 +1311,12 @@ public abstract class WMShellModule {
        return new DesktopModeUiEventLogger(uiEventLogger, packageManager);
    }

    @WMSingleton
    @Provides
    static DesktopWallpaperActivityTokenProvider provideDesktopWallpaperActivityTokenProvider() {
        return new DesktopWallpaperActivityTokenProvider();
    }

    //
    // Drag and drop
    //
+0 −5
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.util.ArraySet
import android.util.SparseArray
import android.view.Display.INVALID_DISPLAY
import android.window.DesktopModeFlags
import android.window.WindowContainerToken
import androidx.core.util.forEach
import androidx.core.util.keyIterator
import androidx.core.util.valueIterator
@@ -90,9 +89,6 @@ class DesktopRepository(
        }
    }

    /* Current wallpaper activity token to remove wallpaper activity when last task is removed. */
    var wallpaperActivityToken: WindowContainerToken? = null

    private val activeTasksListeners = ArraySet<ActiveTasksListener>()
    private val visibleTasksListeners = ArrayMap<VisibleTasksListener, Executor>()

@@ -549,7 +545,6 @@ class DesktopRepository(
                "${innerPrefix}topTransparentFullscreenTaskId=" +
                    "${data.topTransparentFullscreenTaskId}"
            )
            pw.println("${innerPrefix}wallpaperActivityToken=$wallpaperActivityToken")
        }
    }

+4 −4
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler.DragToDes
import com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FREEFORM_ANIMATION_DURATION
import com.android.wm.shell.desktopmode.ExitDesktopTaskTransitionHandler.FULLSCREEN_ANIMATION_DURATION
import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
import com.android.wm.shell.desktopmode.desktopwallpaperactivity.DesktopWallpaperActivityTokenProvider
import com.android.wm.shell.desktopmode.minimize.DesktopWindowLimitRemoteHandler
import com.android.wm.shell.draganddrop.DragAndDropController
import com.android.wm.shell.freeform.FreeformTaskTransitionStarter
@@ -170,6 +171,7 @@ class DesktopTasksController(
    private val desktopModeEventLogger: DesktopModeEventLogger,
    private val desktopModeUiEventLogger: DesktopModeUiEventLogger,
    private val desktopTilingDecorViewModel: DesktopTilingDecorViewModel,
    private val desktopWallpaperActivityTokenProvider: DesktopWallpaperActivityTokenProvider,
) :
    RemoteCallable<DesktopTasksController>,
    Transitions.TransitionHandler,
@@ -1366,7 +1368,7 @@ class DesktopTasksController(
    }

    private fun removeWallpaperActivity(wct: WindowContainerTransaction) {
        taskRepository.wallpaperActivityToken?.let { token ->
        desktopWallpaperActivityTokenProvider.getToken()?.let { token ->
            logV("removeWallpaperActivity")
            wct.removeTask(token)
        }
@@ -1396,10 +1398,8 @@ class DesktopTasksController(
        desktopModeEnterExitTransitionListener?.onExitDesktopModeTransitionStarted(
            FULLSCREEN_ANIMATION_DURATION
        )
        if (taskRepository.wallpaperActivityToken != null) {
        removeWallpaperActivity(wct)
    }
    }

    fun releaseVisualIndicator() {
        val t = SurfaceControl.Transaction()
+10 −6
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.back.BackAnimationController
import com.android.wm.shell.desktopmode.DesktopModeTransitionTypes.isExitDesktopModeTransition
import com.android.wm.shell.desktopmode.desktopwallpaperactivity.DesktopWallpaperActivityTokenProvider
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.shared.TransitionUtil
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
@@ -50,6 +51,7 @@ class DesktopTasksTransitionObserver(
    private val shellTaskOrganizer: ShellTaskOrganizer,
    private val desktopMixedTransitionHandler: DesktopMixedTransitionHandler,
    private val backAnimationController: BackAnimationController,
    private val desktopWallpaperActivityTokenProvider: DesktopWallpaperActivityTokenProvider,
    shellInit: ShellInit,
) : Transitions.TransitionObserver {

@@ -212,7 +214,7 @@ class DesktopTasksTransitionObserver(
                desktopRepository.getVisibleTaskCount(taskInfo.displayId) == 0 &&
                    change.mode == TRANSIT_CLOSE &&
                    taskInfo.windowingMode == WINDOWING_MODE_FREEFORM &&
                    desktopRepository.wallpaperActivityToken != null
                    desktopWallpaperActivityTokenProvider.getToken() != null
            ) {
                transitionToCloseWallpaper = transition
                currentProfileId = taskInfo.userId
@@ -232,8 +234,7 @@ class DesktopTasksTransitionObserver(
        // TODO: b/332682201 Update repository state
        if (transitionToCloseWallpaper == transition) {
            // TODO: b/362469671 - Handle merging the animation when desktop is also closing.
            val desktopRepository = desktopUserRepositories.getProfile(currentProfileId)
            desktopRepository.wallpaperActivityToken?.let { wallpaperActivityToken ->
            desktopWallpaperActivityTokenProvider.getToken()?.let { wallpaperActivityToken ->
                transitions.startTransition(
                    TRANSIT_CLOSE,
                    WindowContainerTransaction().removeTask(wallpaperActivityToken),
@@ -251,10 +252,12 @@ class DesktopTasksTransitionObserver(
        info.changes.forEach { change ->
            change.taskInfo?.let { taskInfo ->
                if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) {
                    val desktopRepository = desktopUserRepositories.getProfile(taskInfo.userId)
                    when (change.mode) {
                        WindowManager.TRANSIT_OPEN -> {
                            desktopRepository.wallpaperActivityToken = taskInfo.token
                            desktopWallpaperActivityTokenProvider.setToken(
                                taskInfo.token,
                                taskInfo.displayId,
                            )
                            // After the task for the wallpaper is created, set it non-trimmable.
                            // This is important to prevent recents from trimming and removing the
                            // task.
@@ -263,7 +266,8 @@ class DesktopTasksTransitionObserver(
                                    .setTaskTrimmableFromRecents(taskInfo.token, false)
                            )
                        }
                        TRANSIT_CLOSE -> desktopRepository.wallpaperActivityToken = null
                        TRANSIT_CLOSE ->
                            desktopWallpaperActivityTokenProvider.removeToken(taskInfo.displayId)
                        else -> {}
                    }
                }
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.desktopmode.desktopwallpaperactivity

import android.util.SparseArray
import android.view.Display.DEFAULT_DISPLAY
import android.window.WindowContainerToken

/** Provides per display window container tokens for [DesktopWallpaperActivity]. */
class DesktopWallpaperActivityTokenProvider {

    private val wallpaperActivityTokenByDisplayId = SparseArray<WindowContainerToken>()

    fun setToken(token: WindowContainerToken, displayId: Int = DEFAULT_DISPLAY) {
        wallpaperActivityTokenByDisplayId[displayId] = token
    }

    fun getToken(displayId: Int = DEFAULT_DISPLAY): WindowContainerToken? {
        return wallpaperActivityTokenByDisplayId[displayId]
    }

    fun removeToken(displayId: Int = DEFAULT_DISPLAY) {
        wallpaperActivityTokenByDisplayId.delete(displayId)
    }
}
Loading