Loading libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/desktopmode/DesktopWallpaperActivityTest.kt +27 −17 Original line number Diff line number Diff line Loading @@ -16,9 +16,9 @@ package com.android.wm.shell.desktopmode import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.platform.test.flag.junit.SetFlagsRule import android.view.Display.DEFAULT_DISPLAY import android.view.WindowManager import androidx.activity.BackEventCompat import androidx.fragment.app.FragmentActivity Loading @@ -34,42 +34,39 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith /** Tests for [DesktopWallpaperActivity]. /** * Tests for [DesktopWallpaperActivity]. * * Build/Install/Run: * atest WMShellRobolectricTests:DesktopWallpaperActivityTest (on host) * atest WMShellMultivalentTestsOnDevice:DesktopWallpaperActivityTest (on device) * Build/Install/Run: atest WMShellRobolectricTests:DesktopWallpaperActivityTest (on host) atest * WMShellMultivalentTestsOnDevice:DesktopWallpaperActivityTest (on device) */ @SmallTest @RunWith(AndroidJUnit4::class) class DesktopWallpaperActivityTest() { @get:Rule val setFlagsRule = SetFlagsRule() @get:Rule val setFlagsRule = SetFlagsRule() @Rule @JvmField val activityScenarioRule = ActivityScenarioRule(DesktopWallpaperActivity::class.java) val activityScenarioRule = ActivityScenarioRule(DesktopWallpaperActivity::class.java) @Test @EnableFlags( Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE, ) fun onTopResumedActivityChanged_whenTrue_setsWindowFocusable() { activityScenarioRule.scenario.onActivity { activity -> activity.onTopResumedActivityChanged(true) val windowFlags = activity.window.attributes.flags assertThat(windowFlags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) .isEqualTo(0) assertThat(windowFlags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE).isEqualTo(0) } } @Test @EnableFlags( Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE, ) fun onTopResumedActivityChanged_whenFalse_setsWindowNotFocusable() { activityScenarioRule.scenario.onActivity { activity -> Loading @@ -91,7 +88,7 @@ class DesktopWallpaperActivityTest() { @Test @EnableFlags( Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE, ) fun onBackPressed_movesTaskToBack() { var wallpaperActivity: FragmentActivity? = null Loading @@ -105,6 +102,19 @@ class DesktopWallpaperActivityTest() { assertThat(wallpaperActivity?.isFinishing).isFalse() } @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun onMovedToDisplay_finishesActivity() { var wallpaperActivity: FragmentActivity? = null activityScenarioRule.scenario.onActivity { activity -> wallpaperActivity = activity activity.onMovedToDisplay(DEFAULT_DISPLAY, null) } assertThat(wallpaperActivity?.isFinishing).isTrue() } private fun backEvent(progress: Float = 0f): BackEventCompat { return BackEventCompat( touchX = 0f, Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +0 −1 Original line number Diff line number Diff line Loading @@ -767,7 +767,6 @@ class DesktopTasksController( ) } snapEventHandler.onDisplayDisconnected(disconnectedDisplayId) removeWallpaperTask(wct, disconnectedDisplayId) removeHomeTask(wct, disconnectedDisplayId) userRepositories.forAllRepositories { desktopRepository -> val userId = desktopRepository.userId Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopWallpaperActivity.kt +36 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.app.TaskInfo import android.app.WallpaperColors import android.app.WallpaperManager import android.content.ComponentName import android.content.res.Configuration import android.hardware.display.DisplayManager import android.os.Bundle import android.util.Log import android.view.WindowManager Loading @@ -42,8 +44,10 @@ import androidx.fragment.app.FragmentActivity class DesktopWallpaperActivity : FragmentActivity() { private var wallpaperManager: WallpaperManager? = null private var displayManager: DisplayManager? = null // TODO(b/432710419): Refresh current user on user change if needed private var currentUser: Int = getCurrentUser() private var initialDisplayId: Int? = null private val wallpaperColorsListener = object : WallpaperManager.OnColorsChangedListener { Loading @@ -56,6 +60,25 @@ class DesktopWallpaperActivity : FragmentActivity() { } } private val displayRemovedListener = object : DisplayManager.DisplayListener { override fun onDisplayAdded(displayId: Int) { // No-op } override fun onDisplayRemoved(displayId: Int) { // DesktopWallpaperActivity should never move to another display; if this // activity's display is removed, finish the activity. if (displayId == initialDisplayId) { finish() } } override fun onDisplayChanged(displayId: Int) { // No-op } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, "onCreate") Loading @@ -80,13 +103,25 @@ class DesktopWallpaperActivity : FragmentActivity() { wallpaperManager = getSystemService(WallpaperManager::class.java) wallpaperManager?.addOnColorsChangedListener(wallpaperColorsListener, mainThreadHandler) // Handle self-removal on display disconnect displayManager = getSystemService(DisplayManager::class.java) displayManager?.registerDisplayListener(displayRemovedListener, mainThreadHandler) // Set the initial color of status bar icons on activity creation. updateStatusBarIconColors(wallpaperManager?.getWallpaperColors(WallpaperManager.FLAG_SYSTEM, currentUser)) updateStatusBarIconColors( wallpaperManager?.getWallpaperColors(WallpaperManager.FLAG_SYSTEM, currentUser) ) initialDisplayId = displayId } override fun onDestroy() { super.onDestroy() wallpaperManager?.removeOnColorsChangedListener(wallpaperColorsListener) displayManager?.unregisterDisplayListener(displayRemovedListener) } override fun onMovedToDisplay(displayId: Int, config: Configuration?) { finish() } override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) { Loading Loading
libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/desktopmode/DesktopWallpaperActivityTest.kt +27 −17 Original line number Diff line number Diff line Loading @@ -16,9 +16,9 @@ package com.android.wm.shell.desktopmode import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.platform.test.flag.junit.SetFlagsRule import android.view.Display.DEFAULT_DISPLAY import android.view.WindowManager import androidx.activity.BackEventCompat import androidx.fragment.app.FragmentActivity Loading @@ -34,42 +34,39 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith /** Tests for [DesktopWallpaperActivity]. /** * Tests for [DesktopWallpaperActivity]. * * Build/Install/Run: * atest WMShellRobolectricTests:DesktopWallpaperActivityTest (on host) * atest WMShellMultivalentTestsOnDevice:DesktopWallpaperActivityTest (on device) * Build/Install/Run: atest WMShellRobolectricTests:DesktopWallpaperActivityTest (on host) atest * WMShellMultivalentTestsOnDevice:DesktopWallpaperActivityTest (on device) */ @SmallTest @RunWith(AndroidJUnit4::class) class DesktopWallpaperActivityTest() { @get:Rule val setFlagsRule = SetFlagsRule() @get:Rule val setFlagsRule = SetFlagsRule() @Rule @JvmField val activityScenarioRule = ActivityScenarioRule(DesktopWallpaperActivity::class.java) val activityScenarioRule = ActivityScenarioRule(DesktopWallpaperActivity::class.java) @Test @EnableFlags( Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE, ) fun onTopResumedActivityChanged_whenTrue_setsWindowFocusable() { activityScenarioRule.scenario.onActivity { activity -> activity.onTopResumedActivityChanged(true) val windowFlags = activity.window.attributes.flags assertThat(windowFlags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) .isEqualTo(0) assertThat(windowFlags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE).isEqualTo(0) } } @Test @EnableFlags( Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE, ) fun onTopResumedActivityChanged_whenFalse_setsWindowNotFocusable() { activityScenarioRule.scenario.onActivity { activity -> Loading @@ -91,7 +88,7 @@ class DesktopWallpaperActivityTest() { @Test @EnableFlags( Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE Flags.FLAG_ENABLE_EMPTY_DESK_ON_MINIMIZE, ) fun onBackPressed_movesTaskToBack() { var wallpaperActivity: FragmentActivity? = null Loading @@ -105,6 +102,19 @@ class DesktopWallpaperActivityTest() { assertThat(wallpaperActivity?.isFinishing).isFalse() } @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun onMovedToDisplay_finishesActivity() { var wallpaperActivity: FragmentActivity? = null activityScenarioRule.scenario.onActivity { activity -> wallpaperActivity = activity activity.onMovedToDisplay(DEFAULT_DISPLAY, null) } assertThat(wallpaperActivity?.isFinishing).isTrue() } private fun backEvent(progress: Float = 0f): BackEventCompat { return BackEventCompat( touchX = 0f, Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +0 −1 Original line number Diff line number Diff line Loading @@ -767,7 +767,6 @@ class DesktopTasksController( ) } snapEventHandler.onDisplayDisconnected(disconnectedDisplayId) removeWallpaperTask(wct, disconnectedDisplayId) removeHomeTask(wct, disconnectedDisplayId) userRepositories.forAllRepositories { desktopRepository -> val userId = desktopRepository.userId Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopWallpaperActivity.kt +36 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.app.TaskInfo import android.app.WallpaperColors import android.app.WallpaperManager import android.content.ComponentName import android.content.res.Configuration import android.hardware.display.DisplayManager import android.os.Bundle import android.util.Log import android.view.WindowManager Loading @@ -42,8 +44,10 @@ import androidx.fragment.app.FragmentActivity class DesktopWallpaperActivity : FragmentActivity() { private var wallpaperManager: WallpaperManager? = null private var displayManager: DisplayManager? = null // TODO(b/432710419): Refresh current user on user change if needed private var currentUser: Int = getCurrentUser() private var initialDisplayId: Int? = null private val wallpaperColorsListener = object : WallpaperManager.OnColorsChangedListener { Loading @@ -56,6 +60,25 @@ class DesktopWallpaperActivity : FragmentActivity() { } } private val displayRemovedListener = object : DisplayManager.DisplayListener { override fun onDisplayAdded(displayId: Int) { // No-op } override fun onDisplayRemoved(displayId: Int) { // DesktopWallpaperActivity should never move to another display; if this // activity's display is removed, finish the activity. if (displayId == initialDisplayId) { finish() } } override fun onDisplayChanged(displayId: Int) { // No-op } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, "onCreate") Loading @@ -80,13 +103,25 @@ class DesktopWallpaperActivity : FragmentActivity() { wallpaperManager = getSystemService(WallpaperManager::class.java) wallpaperManager?.addOnColorsChangedListener(wallpaperColorsListener, mainThreadHandler) // Handle self-removal on display disconnect displayManager = getSystemService(DisplayManager::class.java) displayManager?.registerDisplayListener(displayRemovedListener, mainThreadHandler) // Set the initial color of status bar icons on activity creation. updateStatusBarIconColors(wallpaperManager?.getWallpaperColors(WallpaperManager.FLAG_SYSTEM, currentUser)) updateStatusBarIconColors( wallpaperManager?.getWallpaperColors(WallpaperManager.FLAG_SYSTEM, currentUser) ) initialDisplayId = displayId } override fun onDestroy() { super.onDestroy() wallpaperManager?.removeOnColorsChangedListener(wallpaperColorsListener) displayManager?.unregisterDisplayListener(displayRemovedListener) } override fun onMovedToDisplay(displayId: Int, config: Configuration?) { finish() } override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) { Loading