• 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.wm.shell.bubbles
18 
19 import android.app.ActivityTaskManager.INVALID_TASK_ID
20 import android.content.ComponentName
21 import androidx.annotation.VisibleForTesting
22 import com.android.wm.shell.Flags
23 import com.android.wm.shell.taskview.TaskView
24 import java.util.concurrent.Executor
25 
26 /**
27  * A wrapper class around [TaskView] for bubble expanded views.
28  *
29  * [delegateListener] allows callers to change listeners after a task has been created.
30  */
31 class BubbleTaskView(val taskView: TaskView, executor: Executor) {
32 
33     /** Whether the task is already created. */
34     var isCreated = false
35       private set
36 
37     /** The task id. */
38     var taskId = INVALID_TASK_ID
39       private set
40 
41     /** The component name of the application running in the task. */
42     var componentName: ComponentName? = null
43       private set
44 
45     /**
46      * Whether the task view is visible and has a surface. Note that this does not check the alpha
47      * value of the task view.
48      *
49      * When this is `true` it is safe to start showing the task view. Otherwise if this is `false`
50      * callers should wait for it to be visible which will be indicated either by a call to
51      * [TaskView.Listener.onTaskCreated] or [TaskView.Listener.onTaskVisibilityChanged]. */
52     var isVisible = false
53       private set
54 
55     /** [TaskView.Listener] for users of this class. */
56     var delegateListener: TaskView.Listener? = null
57 
58     /** A [TaskView.Listener] that delegates to [delegateListener]. */
59     @get:VisibleForTesting
60     val listener = object : TaskView.Listener {
onInitializednull61         override fun onInitialized() {
62             delegateListener?.onInitialized()
63         }
64 
onReleasednull65         override fun onReleased() {
66             delegateListener?.onReleased()
67         }
68 
onTaskCreatednull69         override fun onTaskCreated(taskId: Int, name: ComponentName) {
70             delegateListener?.onTaskCreated(taskId, name)
71             this@BubbleTaskView.taskId = taskId
72             isCreated = true
73             componentName = name
74             // when the task is created it is visible
75             isVisible = true
76         }
77 
onTaskVisibilityChangednull78         override fun onTaskVisibilityChanged(taskId: Int, visible: Boolean) {
79             this@BubbleTaskView.isVisible = visible
80             delegateListener?.onTaskVisibilityChanged(taskId, visible)
81         }
82 
onTaskRemovalStartednull83         override fun onTaskRemovalStarted(taskId: Int) {
84             delegateListener?.onTaskRemovalStarted(taskId)
85         }
86 
onBackPressedOnTaskRootnull87         override fun onBackPressedOnTaskRoot(taskId: Int) {
88             delegateListener?.onBackPressedOnTaskRoot(taskId)
89         }
90     }
91 
92     init {
93         taskView.setListener(executor, listener)
94     }
95 
96     /**
97      * Removes the [TaskView] from window manager.
98      *
99      * This should be called after all other cleanup animations have finished.
100      */
cleanupnull101     fun cleanup() {
102         if (Flags.enableTaskViewControllerCleanup() || taskId != INVALID_TASK_ID) {
103             taskView.removeTask()
104         }
105     }
106 }
107