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

Commit 1b8bf6c9 authored by Grace's avatar Grace
Browse files

Enable Region Sampling for Lockscreen Smartspace

This change adds region sampling to the views of lockscreen
smartspace.

Bug: 202758428
Test: atest LockscreenSmartspaceControllerTest

Merged-In: Id890309c95eab1251d09485ce560e1eae5c15900
Change-Id: I89dfbc284348db849823f44d7388356f4b0171a8
parent 03718764
Loading
Loading
Loading
Loading
+67 −18
Original line number Diff line number Diff line
@@ -31,11 +31,13 @@ import android.os.UserHandle
import android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
import android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS
import android.util.Log
import android.view.ContextThemeWrapper
import android.view.View
import android.view.ViewGroup
import com.android.settingslib.Utils
import com.android.systemui.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
@@ -46,6 +48,7 @@ import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceView
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.settings.UserTracker
import com.android.systemui.shared.regionsampling.RegionSamplingInstance
import com.android.systemui.statusbar.phone.KeyguardBypassController
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.statusbar.policy.DeviceProvisionedController
@@ -74,6 +77,7 @@ class LockscreenSmartspaceController @Inject constructor(
        private val bypassController: KeyguardBypassController,
        private val execution: Execution,
        @Main private val uiExecutor: Executor,
        @Background private val bgExecutor: Executor,
        @Main private val handler: Handler,
        optionalPlugin: Optional<BcSmartspaceDataPlugin>
) {
@@ -86,15 +90,36 @@ class LockscreenSmartspaceController @Inject constructor(

    // Smartspace can be used on multiple displays, such as when the user casts their screen
    private var smartspaceViews = mutableSetOf<SmartspaceView>()
    private var regionSamplingInstances =
            mutableMapOf<SmartspaceView, RegionSamplingInstance>()

    private val regionSamplingEnabled =
            featureFlags.isEnabled(Flags.REGION_SAMPLING)

    private var showNotifications = false
    private var showSensitiveContentForCurrentUser = false
    private var showSensitiveContentForManagedUser = false
    private var managedUserHandle: UserHandle? = null

    private val updateFun = object : RegionSamplingInstance.UpdateColorCallback {
        override fun updateColors() {
            updateTextColorFromRegionSampler()
        }
    }

    var stateChangeListener = object : View.OnAttachStateChangeListener {
        override fun onViewAttachedToWindow(v: View) {
            smartspaceViews.add(v as SmartspaceView)

            var regionSamplingInstance = RegionSamplingInstance(
                    v,
                    uiExecutor,
                    bgExecutor,
                    regionSamplingEnabled,
                    updateFun
            )
            regionSamplingInstance.startRegionSampler()
            regionSamplingInstances.put(v, regionSamplingInstance)
            connectSession()

            updateTextColorFromWallpaper()
@@ -104,6 +129,10 @@ class LockscreenSmartspaceController @Inject constructor(
        override fun onViewDetachedFromWindow(v: View) {
            smartspaceViews.remove(v as SmartspaceView)

            var regionSamplingInstance = regionSamplingInstances.getValue(v)
            regionSamplingInstance.stopRegionSampler()
            regionSamplingInstances.remove(v)

            if (smartspaceViews.isEmpty()) {
                disconnect()
            }
@@ -332,9 +361,29 @@ class LockscreenSmartspaceController @Inject constructor(
        }
    }

    private fun updateTextColorFromRegionSampler() {
        smartspaceViews.forEach {
            val isRegionDark = regionSamplingInstances.getValue(it).currentRegionDarkness()
            val themeID = if (isRegionDark.isDark) {
                R.style.Theme_SystemUI
            } else {
                R.style.Theme_SystemUI_LightWallpaper
            }
            val themedContext = ContextThemeWrapper(context, themeID)
            val wallpaperTextColor =
                    Utils.getColorAttrDefaultColor(themedContext, R.attr.wallpaperTextColor)
            it.setPrimaryTextColor(wallpaperTextColor)
        }
    }

    private fun updateTextColorFromWallpaper() {
        val wallpaperTextColor = Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor)
        if (!regionSamplingEnabled) {
            val wallpaperTextColor =
                    Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor)
            smartspaceViews.forEach { it.setPrimaryTextColor(wallpaperTextColor) }
        } else {
            updateTextColorFromRegionSampler()
        }
    }

    private fun reloadSmartspace() {
+5 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import com.android.systemui.util.mockito.eq
import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.time.FakeSystemClock
import java.util.Optional
import java.util.concurrent.Executor
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentCaptor
@@ -104,6 +105,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
    @Mock
    private lateinit var deviceProvisionedController: DeviceProvisionedController

    @Mock
    private lateinit var bgExecutor: Executor

    @Mock
    private lateinit var handler: Handler

@@ -203,6 +207,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
                keyguardBypassController,
                execution,
                executor,
                bgExecutor,
                handler,
                Optional.of(plugin)
        )