Loading quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +1 −7 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.launcher3.taskbar; import static android.content.Context.RECEIVER_NOT_EXPORTED; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; Loading Loading @@ -220,7 +219,7 @@ public class TaskbarManager { TaskbarNavButtonCallbacks navCallbacks, @NonNull DesktopVisibilityController desktopVisibilityController) { Display display = context.getSystemService(DisplayManager.class).getDisplay(DEFAULT_DISPLAY); context.getSystemService(DisplayManager.class).getDisplay(context.getDisplayId()); mContext = context.createWindowContext(display, ENABLE_TASKBAR_NAVBAR_UNIFICATION ? TYPE_NAVIGATION_BAR : TYPE_NAVIGATION_BAR_PANEL, null); Loading Loading @@ -672,11 +671,6 @@ public class TaskbarManager { @VisibleForTesting public void setSuspended(boolean isSuspended) { mIsSuspended = isSuspended; if (mIsSuspended) { removeTaskbarRootViewFromWindow(); } else { addTaskbarRootViewToWindow(); } } private void addTaskbarRootViewToWindow() { Loading quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt +46 −4 Original line number Diff line number Diff line Loading @@ -16,19 +16,61 @@ package com.android.launcher3.taskbar.rules import android.content.Context import android.content.ContextWrapper import android.hardware.display.DisplayManager import android.hardware.display.VirtualDisplay import android.view.Display.DEFAULT_DISPLAY import androidx.test.core.app.ApplicationProvider import com.android.launcher3.util.MainThreadInitializedObject.ObjectSandbox import com.android.launcher3.util.SandboxApplication import org.junit.rules.ExternalResource import org.junit.rules.RuleChain import org.junit.rules.TestRule /** Sandbox Context for running Taskbar tests. */ class TaskbarWindowSandboxContext private constructor(base: SandboxApplication) : ContextWrapper(base), ObjectSandbox by base, TestRule by base { /** * [SandboxApplication] for running Taskbar tests. * * Tests need to run on a [VirtualDisplay] to avoid conflicting with Launcher's Taskbar on the * [DEFAULT_DISPLAY] (i.e. test is executing on a device). */ class TaskbarWindowSandboxContext private constructor(base: SandboxApplication, val virtualDisplay: VirtualDisplay) : ContextWrapper(base), ObjectSandbox by base, TestRule by RuleChain.outerRule(virtualDisplayRule(virtualDisplay)).around(base) { companion object { private const val VIRTUAL_DISPLAY_NAME = "TaskbarSandboxDisplay" /** Creates a [SandboxApplication] for Taskbar tests. */ fun create(): TaskbarWindowSandboxContext { return TaskbarWindowSandboxContext(SandboxApplication()) val base = ApplicationProvider.getApplicationContext<Context>() val displayManager = checkNotNull(base.getSystemService(DisplayManager::class.java)) // Create virtual display to avoid clashing with Taskbar on default display. val virtualDisplay = base.resources.displayMetrics.let { displayManager.createVirtualDisplay( VIRTUAL_DISPLAY_NAME, it.widthPixels, it.heightPixels, it.densityDpi, /* surface= */ null, /* flags= */ 0, ) } return TaskbarWindowSandboxContext( SandboxApplication(base.createDisplayContext(virtualDisplay.display)), virtualDisplay, ) } } } private fun virtualDisplayRule(virtualDisplay: VirtualDisplay): TestRule { return object : ExternalResource() { override fun after() = virtualDisplay.release() } } quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContextTest.kt 0 → 100644 +47 −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.launcher3.taskbar.rules import com.android.launcher3.util.LauncherMultivalentJUnit import com.android.launcher3.util.LauncherMultivalentJUnit.EmulatedDevices import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.Description import org.junit.runner.RunWith import org.junit.runners.model.Statement @RunWith(LauncherMultivalentJUnit::class) @EmulatedDevices(["pixelFoldable2023"]) class TaskbarWindowSandboxContextTest { @Test fun testVirtualDisplay_releasedOnTeardown() { val context = TaskbarWindowSandboxContext.create() assertThat(context.virtualDisplay.token).isNotNull() context .apply( object : Statement() { override fun evaluate() = Unit }, Description.createSuiteDescription(TaskbarWindowSandboxContextTest::class.java), ) .evaluate() assertThat(context.virtualDisplay.token).isNull() } } Loading
quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +1 −7 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.launcher3.taskbar; import static android.content.Context.RECEIVER_NOT_EXPORTED; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; Loading Loading @@ -220,7 +219,7 @@ public class TaskbarManager { TaskbarNavButtonCallbacks navCallbacks, @NonNull DesktopVisibilityController desktopVisibilityController) { Display display = context.getSystemService(DisplayManager.class).getDisplay(DEFAULT_DISPLAY); context.getSystemService(DisplayManager.class).getDisplay(context.getDisplayId()); mContext = context.createWindowContext(display, ENABLE_TASKBAR_NAVBAR_UNIFICATION ? TYPE_NAVIGATION_BAR : TYPE_NAVIGATION_BAR_PANEL, null); Loading Loading @@ -672,11 +671,6 @@ public class TaskbarManager { @VisibleForTesting public void setSuspended(boolean isSuspended) { mIsSuspended = isSuspended; if (mIsSuspended) { removeTaskbarRootViewFromWindow(); } else { addTaskbarRootViewToWindow(); } } private void addTaskbarRootViewToWindow() { Loading
quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt +46 −4 Original line number Diff line number Diff line Loading @@ -16,19 +16,61 @@ package com.android.launcher3.taskbar.rules import android.content.Context import android.content.ContextWrapper import android.hardware.display.DisplayManager import android.hardware.display.VirtualDisplay import android.view.Display.DEFAULT_DISPLAY import androidx.test.core.app.ApplicationProvider import com.android.launcher3.util.MainThreadInitializedObject.ObjectSandbox import com.android.launcher3.util.SandboxApplication import org.junit.rules.ExternalResource import org.junit.rules.RuleChain import org.junit.rules.TestRule /** Sandbox Context for running Taskbar tests. */ class TaskbarWindowSandboxContext private constructor(base: SandboxApplication) : ContextWrapper(base), ObjectSandbox by base, TestRule by base { /** * [SandboxApplication] for running Taskbar tests. * * Tests need to run on a [VirtualDisplay] to avoid conflicting with Launcher's Taskbar on the * [DEFAULT_DISPLAY] (i.e. test is executing on a device). */ class TaskbarWindowSandboxContext private constructor(base: SandboxApplication, val virtualDisplay: VirtualDisplay) : ContextWrapper(base), ObjectSandbox by base, TestRule by RuleChain.outerRule(virtualDisplayRule(virtualDisplay)).around(base) { companion object { private const val VIRTUAL_DISPLAY_NAME = "TaskbarSandboxDisplay" /** Creates a [SandboxApplication] for Taskbar tests. */ fun create(): TaskbarWindowSandboxContext { return TaskbarWindowSandboxContext(SandboxApplication()) val base = ApplicationProvider.getApplicationContext<Context>() val displayManager = checkNotNull(base.getSystemService(DisplayManager::class.java)) // Create virtual display to avoid clashing with Taskbar on default display. val virtualDisplay = base.resources.displayMetrics.let { displayManager.createVirtualDisplay( VIRTUAL_DISPLAY_NAME, it.widthPixels, it.heightPixels, it.densityDpi, /* surface= */ null, /* flags= */ 0, ) } return TaskbarWindowSandboxContext( SandboxApplication(base.createDisplayContext(virtualDisplay.display)), virtualDisplay, ) } } } private fun virtualDisplayRule(virtualDisplay: VirtualDisplay): TestRule { return object : ExternalResource() { override fun after() = virtualDisplay.release() } }
quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContextTest.kt 0 → 100644 +47 −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.launcher3.taskbar.rules import com.android.launcher3.util.LauncherMultivalentJUnit import com.android.launcher3.util.LauncherMultivalentJUnit.EmulatedDevices import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.Description import org.junit.runner.RunWith import org.junit.runners.model.Statement @RunWith(LauncherMultivalentJUnit::class) @EmulatedDevices(["pixelFoldable2023"]) class TaskbarWindowSandboxContextTest { @Test fun testVirtualDisplay_releasedOnTeardown() { val context = TaskbarWindowSandboxContext.create() assertThat(context.virtualDisplay.token).isNotNull() context .apply( object : Statement() { override fun evaluate() = Unit }, Description.createSuiteDescription(TaskbarWindowSandboxContextTest::class.java), ) .evaluate() assertThat(context.virtualDisplay.token).isNull() } }