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

Commit 96235f48 authored by Xiaowen Lei's avatar Xiaowen Lei Committed by Android (Google) Code Review
Browse files

Merge "[HSUM] Use SmartspaceManager in the current foreground user context." into main

parents 3be70132 42960ddd
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -91,7 +91,6 @@ class LockscreenSmartspaceController
constructor(
        private val context: Context,
        private val featureFlags: FeatureFlags,
        private val smartspaceManager: SmartspaceManager?,
        private val activityStarter: ActivityStarter,
        private val falsingManager: FalsingManager,
        private val systemClock: SystemClock,
@@ -124,6 +123,7 @@ constructor(
        private const val MAX_RECENT_SMARTSPACE_DATA_FOR_DUMP = 5
    }

    private var userSmartspaceManager: SmartspaceManager? = null
    private var session: SmartspaceSession? = null
    private val datePlugin: BcSmartspaceDataPlugin? = optionalDatePlugin.orElse(null)
    private val weatherPlugin: BcSmartspaceDataPlugin? = optionalWeatherPlugin.orElse(null)
@@ -461,7 +461,11 @@ constructor(
    }

    private fun connectSession() {
        if (smartspaceManager == null) return
        if (userSmartspaceManager == null) {
            userSmartspaceManager =
                userTracker.userContext.getSystemService(SmartspaceManager::class.java)
        }
        if (userSmartspaceManager == null) return
        if (datePlugin == null && weatherPlugin == null && plugin == null) return
        if (session != null || smartspaceViews.isEmpty()) {
            return
@@ -474,12 +478,14 @@ constructor(
            return
        }

        val newSession = smartspaceManager.createSmartspaceSession(
        val newSession = userSmartspaceManager?.createSmartspaceSession(
            SmartspaceConfig.Builder(
                        context, BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD).build())
                userTracker.userContext, BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD
            ).build()
        )
        Log.d(TAG, "Starting smartspace session for " +
                BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD)
        newSession.addOnTargetsAvailableListener(uiExecutor, sessionListener)
        newSession?.addOnTargetsAvailableListener(uiExecutor, sessionListener)
        this.session = newSession

        deviceProvisionedController.removeCallback(deviceProvisionedListener)
+13 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.app.smartspace.SmartspaceSession.OnTargetsAvailableListener
import android.app.smartspace.SmartspaceTarget
import android.content.ComponentName
import android.content.ContentResolver
import android.content.Context
import android.content.pm.UserInfo
import android.database.ContentObserver
import android.graphics.drawable.Drawable
@@ -207,6 +208,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
    private val userHandleManaged: UserHandle = UserHandle(2)
    private val userHandleSecondary: UserHandle = UserHandle(3)

    @Mock private lateinit var userContextPrimary: Context
    @Mock private lateinit var userContextSecondary: Context

    private val userList = listOf(
            mockUserInfo(userHandlePrimary, isManagedProfile = false),
            mockUserInfo(userHandleManaged, isManagedProfile = true),
@@ -234,7 +238,11 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        `when`(deviceProvisionedController.isDeviceProvisioned).thenReturn(true)
        `when`(deviceProvisionedController.isCurrentUserSetup).thenReturn(true)

        setActiveUser(userHandlePrimary)
        `when`(userContextPrimary.getSystemService(SmartspaceManager::class.java)).thenReturn(
            smartspaceManager
        )

        setActiveUser(userHandlePrimary, userContextPrimary)
        setAllowPrivateNotifications(userHandlePrimary, true)
        setAllowPrivateNotifications(userHandleManaged, true)
        setAllowPrivateNotifications(userHandleSecondary, true)
@@ -252,7 +260,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        controller = LockscreenSmartspaceController(
                context,
                featureFlags,
                smartspaceManager,
                activityStarter,
                falsingManager,
                clock,
@@ -709,7 +716,8 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        connectSession()

        // WHEN the secondary user becomes the active user
        setActiveUser(userHandleSecondary)
        // Note: it doesn't switch to the SmartspaceManager for userContextSecondary
        setActiveUser(userHandleSecondary, userContextSecondary)
        userListener.onUserChanged(userHandleSecondary.identifier, context)

        // WHEN we receive a new list of targets
@@ -912,9 +920,10 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        clearInvocations(smartspaceView)
    }

    private fun setActiveUser(userHandle: UserHandle) {
    private fun setActiveUser(userHandle: UserHandle, userContext: Context) {
        `when`(userTracker.userId).thenReturn(userHandle.identifier)
        `when`(userTracker.userHandle).thenReturn(userHandle)
        `when`(userTracker.userContext).thenReturn(userContext)
    }

    private fun mockUserInfo(userHandle: UserHandle, isManagedProfile: Boolean): UserInfo {