• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.quickstep
18 
19 import android.view.View
20 import com.android.internal.jank.Cuj
21 import com.android.launcher3.AbstractFloatingViewHelper
22 import com.android.launcher3.R
23 import com.android.launcher3.logging.StatsLogManager.LauncherEvent
24 import com.android.launcher3.popup.SystemShortcut
25 import com.android.quickstep.views.RecentsView
26 import com.android.quickstep.views.RecentsViewContainer
27 import com.android.quickstep.views.TaskContainer
28 import com.android.systemui.shared.system.InteractionJankMonitorWrapper
29 import com.android.wm.shell.shared.desktopmode.DesktopModeCompatPolicy
30 import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
31 import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource
32 
33 /** A menu item, "Desktop", that allows the user to bring the current app into Desktop Windowing. */
34 class DesktopSystemShortcut(
35     container: RecentsViewContainer,
36     private val taskContainer: TaskContainer,
37     abstractFloatingViewHelper: AbstractFloatingViewHelper,
38 ) :
39     SystemShortcut<RecentsViewContainer>(
40         R.drawable.ic_desktop,
41         R.string.recent_task_option_desktop,
42         container,
43         taskContainer.itemInfo,
44         taskContainer.taskView,
45         abstractFloatingViewHelper,
46     ) {
onClicknull47     override fun onClick(view: View) {
48         InteractionJankMonitorWrapper.begin(view, Cuj.CUJ_DESKTOP_MODE_ENTER_FROM_OVERVIEW_MENU)
49         dismissTaskMenuView()
50         val recentsView = mTarget.getOverviewPanel<RecentsView<*, *>>()
51         recentsView.moveTaskToDesktop(
52             taskContainer,
53             DesktopModeTransitionSource.APP_FROM_OVERVIEW,
54         ) {
55             InteractionJankMonitorWrapper.end(Cuj.CUJ_DESKTOP_MODE_ENTER_FROM_OVERVIEW_MENU)
56             mTarget.statsLogManager
57                 .logger()
58                 .withItemInfo(taskContainer.itemInfo)
59                 .log(LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_DESKTOP_TAP)
60         }
61     }
62 
63     companion object {
64         /** Creates a factory for creating Desktop system shortcuts. */
65         @JvmOverloads
createFactorynull66         fun createFactory(
67             abstractFloatingViewHelper: AbstractFloatingViewHelper = AbstractFloatingViewHelper()
68         ): TaskShortcutFactory {
69             return object : TaskShortcutFactory {
70                 override fun getShortcuts(
71                     container: RecentsViewContainer,
72                     taskContainer: TaskContainer,
73                 ): List<DesktopSystemShortcut>? {
74                     val context = container.asContext()
75                     val taskKey = taskContainer.task.key
76                     val desktopModeCompatPolicy = DesktopModeCompatPolicy(context)
77                     return when {
78                         !DesktopModeStatus.canEnterDesktopMode(context) -> null
79 
80                         desktopModeCompatPolicy.isTopActivityExemptFromDesktopWindowing(
81                             taskKey.baseActivity?.packageName,
82                             taskKey.numActivities,
83                             taskKey.isTopActivityNoDisplay,
84                             taskKey.isActivityStackTransparent,
85                             taskKey.userId,
86                         ) -> null
87 
88                         !taskContainer.task.isDockable -> null
89 
90                         else -> {
91                             listOf(
92                                 DesktopSystemShortcut(
93                                     container,
94                                     taskContainer,
95                                     abstractFloatingViewHelper,
96                                 )
97                             )
98                         }
99                     }
100                 }
101 
102                 override fun showForGroupedTask() = true
103             }
104         }
105     }
106 }
107