Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 664d05c1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Register DesktopUserRepos with ShellController" into main

parents e26c4745 e87b983a
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -1025,12 +1025,14 @@ public abstract class WMShellModule {
    static DesktopUserRepositories provideDesktopUserRepositories(
    static DesktopUserRepositories provideDesktopUserRepositories(
            Context context,
            Context context,
            ShellInit shellInit,
            ShellInit shellInit,
            ShellController shellController,
            DesktopPersistentRepository desktopPersistentRepository,
            DesktopPersistentRepository desktopPersistentRepository,
            DesktopRepositoryInitializer desktopRepositoryInitializer,
            DesktopRepositoryInitializer desktopRepositoryInitializer,
            @ShellMainThread CoroutineScope mainScope,
            @ShellMainThread CoroutineScope mainScope,
            UserManager userManager
            UserManager userManager
    ) {
    ) {
        return new DesktopUserRepositories(context, shellInit, desktopPersistentRepository,
        return new DesktopUserRepositories(context, shellInit, shellController,
                desktopPersistentRepository,
                desktopRepositoryInitializer,
                desktopRepositoryInitializer,
                mainScope, userManager);
                mainScope, userManager);
    }
    }
+5 −2
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.wm.shell.desktopmode.persistence.DesktopRepositoryInitializer
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.shared.annotations.ShellMainThread
import com.android.wm.shell.shared.annotations.ShellMainThread
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.sysui.UserChangeListener
import com.android.wm.shell.sysui.UserChangeListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineScope
@@ -36,6 +37,7 @@ import kotlinx.coroutines.CoroutineScope
class DesktopUserRepositories(
class DesktopUserRepositories(
    context: Context,
    context: Context,
    shellInit: ShellInit,
    shellInit: ShellInit,
    private val shellController: ShellController,
    private val persistentRepository: DesktopPersistentRepository,
    private val persistentRepository: DesktopPersistentRepository,
    private val repositoryInitializer: DesktopRepositoryInitializer,
    private val repositoryInitializer: DesktopRepositoryInitializer,
    @ShellMainThread private val mainCoroutineScope: CoroutineScope,
    @ShellMainThread private val mainCoroutineScope: CoroutineScope,
@@ -61,15 +63,16 @@ class DesktopUserRepositories(
    init {
    init {
        userId = ActivityManager.getCurrentUser()
        userId = ActivityManager.getCurrentUser()
        if (DesktopModeStatus.canEnterDesktopMode(context)) {
        if (DesktopModeStatus.canEnterDesktopMode(context)) {
            shellInit.addInitCallback(::initRepoFromPersistentStorage, this)
            shellInit.addInitCallback(::onInit, this)
        }
        }
        if (Flags.enableDesktopWindowingHsum()) {
        if (Flags.enableDesktopWindowingHsum()) {
            userIdToProfileIdsMap[userId] = userManager.getProfiles(userId).map { it.id }
            userIdToProfileIdsMap[userId] = userManager.getProfiles(userId).map { it.id }
        }
        }
    }
    }


    private fun initRepoFromPersistentStorage() {
    private fun onInit() {
        repositoryInitializer.initialize(this)
        repositoryInitializer.initialize(this)
        shellController.addUserChangeListener(this)
    }
    }


    /** Returns [DesktopRepository] for the parent user id. */
    /** Returns [DesktopRepository] for the parent user id. */
+3 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.dx.mockito.inline.extended.ExtendedMockito.never
import com.android.dx.mockito.inline.extended.StaticMockitoSession
import com.android.dx.mockito.inline.extended.StaticMockitoSession
import com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE
import com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE
import com.android.window.flags.Flags.FLAG_RESPECT_ORIENTATION_CHANGE_FOR_UNRESIZEABLE
import com.android.window.flags.Flags.FLAG_RESPECT_ORIENTATION_CHANGE_FOR_UNRESIZEABLE
import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.ShellExecutor
@@ -98,6 +99,7 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
    @Mock lateinit var persistentRepository: DesktopPersistentRepository
    @Mock lateinit var persistentRepository: DesktopPersistentRepository
    @Mock lateinit var repositoryInitializer: DesktopRepositoryInitializer
    @Mock lateinit var repositoryInitializer: DesktopRepositoryInitializer
    @Mock lateinit var userManager: UserManager
    @Mock lateinit var userManager: UserManager
    @Mock lateinit var shellController: ShellController


    private lateinit var mockitoSession: StaticMockitoSession
    private lateinit var mockitoSession: StaticMockitoSession
    private lateinit var handler: DesktopActivityOrientationChangeHandler
    private lateinit var handler: DesktopActivityOrientationChangeHandler
@@ -123,6 +125,7 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
            DesktopUserRepositories(
            DesktopUserRepositories(
                context,
                context,
                shellInit,
                shellInit,
                shellController,
                persistentRepository,
                persistentRepository,
                repositoryInitializer,
                repositoryInitializer,
                testScope,
                testScope,
+1 −1
Original line number Original line Diff line number Diff line
@@ -89,7 +89,7 @@ class DesktopImmersiveControllerTest : ShellTestCase() {
    @Before
    @Before
    fun setUp() {
    fun setUp() {
        userRepositories = DesktopUserRepositories(
        userRepositories = DesktopUserRepositories(
            context, ShellInit(TestShellExecutor()), mock(), mock(), mock(), mock()
            context, ShellInit(TestShellExecutor()), mock(), mock(), mock(), mock(), mock()
        )
        )
        whenever(mockDisplayController.getDisplayLayout(DEFAULT_DISPLAY))
        whenever(mockDisplayController.getDisplayLayout(DEFAULT_DISPLAY))
            .thenReturn(mockDisplayLayout)
            .thenReturn(mockDisplayLayout)
+2 −1
Original line number Original line Diff line number Diff line
@@ -276,6 +276,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
      DesktopUserRepositories(
      DesktopUserRepositories(
        context,
        context,
        shellInit,
        shellInit,
        shellController,
        persistentRepository,
        persistentRepository,
        repositoryInitializer,
        repositoryInitializer,
        testScope,
        testScope,
@@ -3907,7 +3908,7 @@ class DesktopTasksControllerTest : ShellTestCase() {


  @Test
  @Test
  fun shellController_registersUserChangeListener() {
  fun shellController_registersUserChangeListener() {
      verify(shellController, times(1)).addUserChangeListener(any())
      verify(shellController, times(2)).addUserChangeListener(any())
  }
  }


  @Test
  @Test
Loading