Always clean up taskview
When creating a TaskViewTaskController, it registers itself in
TaskViewTransitions in the constructor.
This means, even if the task is not initialized, we still need to clean
up the TaskViewTaskController.
Ignoring that task id is not present and always calling the removeTask
method in BubbleTaskView.
Updating TaskViewTaskController removeTask method to always remove the
class from TaskViewTransitions. Even if the task itself is not
initialized.
Bug: 369995920
Flag: com.android.wm.shell.enable_task_view_controller_cleanup
Test: atest BubbleTaskViewTest
Change-Id: Ie4766452c30a497a7a447c7473a85be1ddc45b0e
diff --git a/libs/WindowManager/Shell/multivalentTests/Android.bp b/libs/WindowManager/Shell/multivalentTests/Android.bp
index ee0d5bb..41d1b5c 100644
--- a/libs/WindowManager/Shell/multivalentTests/Android.bp
+++ b/libs/WindowManager/Shell/multivalentTests/Android.bp
@@ -53,6 +53,8 @@
"mockito-robolectric-prebuilt",
"mockito-kotlin2",
"truth",
+ "flag-junit-base",
+ "flag-junit",
],
auto_gen_config: true,
}
diff --git a/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/BubbleTaskViewTest.kt b/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/BubbleTaskViewTest.kt
index 398fd55..4214e6f 100644
--- a/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/BubbleTaskViewTest.kt
+++ b/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/BubbleTaskViewTest.kt
@@ -18,14 +18,19 @@
import android.content.ComponentName
import android.content.Context
+import android.platform.test.annotations.DisableFlags
+import android.platform.test.annotations.EnableFlags
+import android.platform.test.flag.junit.SetFlagsRule
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
+import com.android.wm.shell.Flags
import com.android.wm.shell.taskview.TaskView
import com.google.common.truth.Truth.assertThat
import com.google.common.util.concurrent.MoreExecutors.directExecutor
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.mock
@@ -36,6 +41,9 @@
@RunWith(AndroidJUnit4::class)
class BubbleTaskViewTest {
+ @get:Rule
+ val setFlagsRule = SetFlagsRule()
+
private lateinit var bubbleTaskView: BubbleTaskView
private val context = ApplicationProvider.getApplicationContext<Context>()
private lateinit var taskView: TaskView
@@ -75,14 +83,33 @@
assertThat(actualComponentName).isEqualTo(componentName)
}
+ @DisableFlags(Flags.FLAG_ENABLE_TASK_VIEW_CONTROLLER_CLEANUP)
@Test
- fun cleanup_invalidTaskId_doesNotRemoveTask() {
+ fun cleanup_flagOff_invalidTaskId_doesNotRemoveTask() {
bubbleTaskView.cleanup()
verify(taskView, never()).removeTask()
}
+ @EnableFlags(Flags.FLAG_ENABLE_TASK_VIEW_CONTROLLER_CLEANUP)
@Test
- fun cleanup_validTaskId_removesTask() {
+ fun cleanup_flagOn_invalidTaskId_removesTask() {
+ bubbleTaskView.cleanup()
+ verify(taskView).removeTask()
+ }
+
+ @DisableFlags(Flags.FLAG_ENABLE_TASK_VIEW_CONTROLLER_CLEANUP)
+ @Test
+ fun cleanup_flagOff_validTaskId_removesTask() {
+ val componentName = ComponentName(context, "TestClass")
+ bubbleTaskView.listener.onTaskCreated(123, componentName)
+
+ bubbleTaskView.cleanup()
+ verify(taskView).removeTask()
+ }
+
+ @EnableFlags(Flags.FLAG_ENABLE_TASK_VIEW_CONTROLLER_CLEANUP)
+ @Test
+ fun cleanup_flagOn_validTaskId_removesTask() {
val componentName = ComponentName(context, "TestClass")
bubbleTaskView.listener.onTaskCreated(123, componentName)