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

Commit cc9c7f85 authored by David Thames's avatar David Thames Committed by Android (Google) Code Review
Browse files

Merge "Propogate the BcSmartspaceConfigPlugin to the BcSmartspaceDataPlugin in...

Merge "Propogate the BcSmartspaceConfigPlugin to the BcSmartspaceDataPlugin in order to flag ViewPager2." into main
parents 38eeee3d 882ec1a0
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -103,6 +103,15 @@ public interface BcSmartspaceDataPlugin extends Plugin {
        void onSmartspaceTargetsUpdated(List<? extends Parcelable> targets);
    }

    /**
     * Sets {@link BcSmartspaceConfigPlugin}.
     *
     * TODO: b/259566300 - Remove once isViewPager2Enabled is fully rolled out
     */
    default void registerConfigProvider(BcSmartspaceConfigPlugin configProvider) {
        throw new UnsupportedOperationException("Not implemented by " + getClass());
    }

    /** View to which this plugin can be registered, in order to get updates. */
    interface SmartspaceView {
        void registerDataProvider(BcSmartspaceDataPlugin plugin);
+212 −210
Original line number Diff line number Diff line
@@ -83,7 +83,6 @@ import java.util.concurrent.Executor
import javax.inject.Inject
import javax.inject.Named


/** Controller for managing the smartspace view on the lockscreen */
@SysUISingleton
class LockscreenSmartspaceController
@@ -110,10 +109,8 @@ constructor(
    @Background private val bgExecutor: Executor,
    @Main private val handler: Handler,
    @Background private val bgHandler: Handler,
        @Named(DATE_SMARTSPACE_DATA_PLUGIN)
        optionalDatePlugin: Optional<BcSmartspaceDataPlugin>,
        @Named(WEATHER_SMARTSPACE_DATA_PLUGIN)
        optionalWeatherPlugin: Optional<BcSmartspaceDataPlugin>,
    @Named(DATE_SMARTSPACE_DATA_PLUGIN) optionalDatePlugin: Optional<BcSmartspaceDataPlugin>,
    @Named(WEATHER_SMARTSPACE_DATA_PLUGIN) optionalWeatherPlugin: Optional<BcSmartspaceDataPlugin>,
    optionalPlugin: Optional<BcSmartspaceDataPlugin>,
    optionalConfigPlugin: Optional<BcSmartspaceConfigPlugin>,
) : Dumpable {
@@ -135,11 +132,9 @@ constructor(

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

    private val regionSamplingEnabled =
            featureFlags.isEnabled(Flags.REGION_SAMPLING)
    private val regionSamplingEnabled = featureFlags.isEnabled(Flags.REGION_SAMPLING)
    private var isRegionSamplersCreated = false
    private var showNotifications = false
    private var showSensitiveContentForCurrentUser = false
@@ -157,7 +152,8 @@ constructor(
    //  how we test color updates when theme changes (See testThemeChangeUpdatesTextColor).

    // TODO: Move logic into SmartspaceView
    var stateChangeListener = object : View.OnAttachStateChangeListener {
    var stateChangeListener =
        object : View.OnAttachStateChangeListener {
            override fun onViewAttachedToWindow(v: View) {
                (v as SmartspaceView).setSplitShadeEnabled(mSplitShadeEnabled)
                smartspaceViews.add(v as SmartspaceView)
@@ -168,13 +164,16 @@ constructor(
                statusBarStateListener.onDozeAmountChanged(0f, statusBarStateController.dozeAmount)

                if (regionSamplingEnabled && (!regionSamplers.containsKey(v))) {
                var regionSampler = RegionSampler(
                    var regionSampler =
                        RegionSampler(
                            v as View,
                            uiExecutor,
                            bgExecutor,
                            regionSamplingEnabled,
                            isLockscreen = true,
                ) { updateTextColorFromRegionSampler() }
                        ) {
                            updateTextColorFromRegionSampler()
                        }
                    initializeTextColors(regionSampler)
                    regionSamplers[v] = regionSampler
                    regionSampler.startRegionSampler()
@@ -193,30 +192,33 @@ constructor(
            }
        }

    private val sessionListener = SmartspaceSession.OnTargetsAvailableListener { targets ->
    private val sessionListener =
        SmartspaceSession.OnTargetsAvailableListener { targets ->
            execution.assertIsMainThread()

        // The weather data plugin takes unfiltered targets and performs the filtering internally.
            // The weather data plugin takes unfiltered targets and performs the filtering
            // internally.
            weatherPlugin?.onTargetsAvailable(targets)

            val now = Instant.ofEpochMilli(systemClock.currentTimeMillis())
        val weatherTarget = targets.find { t ->
            val weatherTarget =
                targets.find { t ->
                    t.featureType == SmartspaceTarget.FEATURE_WEATHER &&
                        now.isAfter(Instant.ofEpochMilli(t.creationTimeMillis)) &&
                        now.isBefore(Instant.ofEpochMilli(t.expiryTimeMillis))
                }
            if (weatherTarget != null) {
                val clickIntent = weatherTarget.headerAction?.intent
            val weatherData = weatherTarget.baseAction?.extras?.let { extras ->
                WeatherData.fromBundle(
                    extras,
                ) { _ ->
                val weatherData =
                    weatherTarget.baseAction?.extras?.let { extras ->
                        WeatherData.fromBundle(extras) { _ ->
                            if (!falsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
                                activityStarter.startActivity(
                                    clickIntent,
                                    true, /* dismissShade */
                                    null,
                            false)
                                    false,
                                )
                            }
                        }
                    }
@@ -238,28 +240,32 @@ constructor(
            plugin?.onTargetsAvailable(filteredTargets)
        }

    private val userTrackerCallback = object : UserTracker.Callback {
    private val userTrackerCallback =
        object : UserTracker.Callback {
            override fun onUserChanged(newUser: Int, userContext: Context) {
                execution.assertIsMainThread()
                reloadSmartspace()
            }
        }

    private val settingsObserver = object : ContentObserver(handler) {
    private val settingsObserver =
        object : ContentObserver(handler) {
            override fun onChange(selfChange: Boolean, uri: Uri?) {
                execution.assertIsMainThread()
                reloadSmartspace()
            }
        }

    private val configChangeListener = object : ConfigurationController.ConfigurationListener {
    private val configChangeListener =
        object : ConfigurationController.ConfigurationListener {
            override fun onThemeChanged() {
                execution.assertIsMainThread()
                updateTextColorFromWallpaper()
            }
        }

    private val statusBarStateListener = object : StatusBarStateController.StateListener {
    private val statusBarStateListener =
        object : StatusBarStateController.StateListener {
            override fun onDozeAmountChanged(linear: Float, eased: Float) {
                execution.assertIsMainThread()
                smartspaceViews.forEach { it.setDozeAmount(eased) }
@@ -313,11 +319,8 @@ constructor(
    val isWeatherEnabled: Boolean
        get() {
            val showWeather =
                secureSettings.getIntForUser(
                    LOCK_SCREEN_WEATHER_ENABLED,
                    1,
                    userTracker.userId,
                ) == 1
                secureSettings.getIntForUser(LOCK_SCREEN_WEATHER_ENABLED, 1, userTracker.userId) ==
                    1
            return showWeather
        }

@@ -326,9 +329,7 @@ constructor(
        smartspaceViews.forEach { it.setKeyguardBypassEnabled(bypassEnabled) }
    }

    /**
     * Constructs the date view and connects it to the smartspace service.
     */
    /** Constructs the date view and connects it to the smartspace service. */
    fun buildAndConnectDateView(parent: ViewGroup): View? {
        execution.assertIsMainThread()

@@ -343,16 +344,14 @@ constructor(
            buildView(
                surfaceName = SmartspaceViewModel.SURFACE_DATE_VIEW,
                parent = parent,
                plugin = datePlugin
                plugin = datePlugin,
            )
        connectSession()

        return view
    }

    /**
     * Constructs the weather view and connects it to the smartspace service.
     */
    /** Constructs the weather view and connects it to the smartspace service. */
    fun buildAndConnectWeatherView(parent: ViewGroup): View? {
        execution.assertIsMainThread()

@@ -367,16 +366,14 @@ constructor(
            buildView(
                surfaceName = SmartspaceViewModel.SURFACE_WEATHER_VIEW,
                parent = parent,
                plugin = weatherPlugin
                plugin = weatherPlugin,
            )
        connectSession()

        return view
    }

    /**
     * Constructs the smartspace view and connects it to the smartspace service.
     */
    /** Constructs the smartspace view and connects it to the smartspace service. */
    fun buildAndConnectView(parent: ViewGroup): View? {
        execution.assertIsMainThread()

@@ -384,12 +381,14 @@ constructor(
            throw RuntimeException("Cannot build view when not enabled")
        }

        configPlugin?.let { plugin?.registerConfigProvider(it) }

        val view =
            buildView(
                surfaceName = SmartspaceViewModel.SURFACE_GENERAL_VIEW,
                parent = parent,
                plugin = plugin,
                configPlugin = configPlugin
                configPlugin = configPlugin,
            )
        connectSession()

@@ -400,7 +399,7 @@ constructor(
        surfaceName: String,
        parent: ViewGroup,
        plugin: BcSmartspaceDataPlugin?,
        configPlugin: BcSmartspaceConfigPlugin? = null
        configPlugin: BcSmartspaceConfigPlugin? = null,
    ): View? {
        if (plugin == null) {
            return null
@@ -413,7 +412,8 @@ constructor(
        ssView.setTimeChangedDelegate(SmartspaceTimeChangedDelegate(keyguardUpdateMonitor))
        ssView.registerDataProvider(plugin)

        ssView.setIntentStarter(object : BcSmartspaceDataPlugin.IntentStarter {
        ssView.setIntentStarter(
            object : BcSmartspaceDataPlugin.IntentStarter {
                override fun startIntent(view: View, intent: Intent, showOnLockscreen: Boolean) {
                    if (showOnLockscreen) {
                        activityStarter.startActivity(
@@ -421,7 +421,7 @@ constructor(
                            true, /* dismissShade */
                            // launch animator - looks bad with the transparent smartspace bg
                            null,
                            true
                            true,
                        )
                    } else {
                        activityStarter.postStartActivityDismissingKeyguard(intent, 0)
@@ -431,19 +431,22 @@ constructor(
                override fun startPendingIntent(
                    view: View,
                    pi: PendingIntent,
                    showOnLockscreen: Boolean
                    showOnLockscreen: Boolean,
                ) {
                    if (showOnLockscreen) {
                    val options = ActivityOptions.makeBasic()
                        val options =
                            ActivityOptions.makeBasic()
                                .setPendingIntentBackgroundActivityStartMode(
                                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED)
                                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
                                )
                                .toBundle()
                        pi.send(options)
                    } else {
                        activityStarter.postStartActivityDismissingKeyguard(pi)
                    }
                }
        })
            }
        )
        ssView.setFalsingManager(falsingManager)
        ssView.setKeyguardBypassEnabled(bypassController.bypassEnabled)
        return (ssView as View).apply {
@@ -452,10 +455,7 @@ constructor(

            if (smartspaceLockscreenViewmodel()) {
                val viewModel = smartspaceViewModelFactory.create(surfaceName)
                SmartspaceViewBinder.bind(
                    smartspaceView = ssView,
                    viewModel = viewModel,
                )
                SmartspaceViewBinder.bind(smartspaceView = ssView, viewModel = viewModel)
            }
        }
    }
@@ -473,18 +473,25 @@ constructor(

        // Only connect after the device is fully provisioned to avoid connection caching
        // issues
        if (!deviceProvisionedController.isDeviceProvisioned() ||
                !deviceProvisionedController.isCurrentUserSetup()) {
        if (
            !deviceProvisionedController.isDeviceProvisioned() ||
                !deviceProvisionedController.isCurrentUserSetup()
        ) {
            return
        }

        val newSession = userSmartspaceManager?.createSmartspaceSession(
        val newSession =
            userSmartspaceManager?.createSmartspaceSession(
                SmartspaceConfig.Builder(
                userTracker.userContext, 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,
        )
        Log.d(TAG, "Starting smartspace session for " +
                BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD)
        newSession?.addOnTargetsAvailableListener(uiExecutor, sessionListener)
        this.session = newSession

@@ -494,13 +501,13 @@ constructor(
            secureSettings.getUriFor(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS),
            true,
            settingsObserver,
                UserHandle.USER_ALL
            UserHandle.USER_ALL,
        )
        contentResolver.registerContentObserver(
            secureSettings.getUriFor(LOCK_SCREEN_SHOW_NOTIFICATIONS),
            true,
            settingsObserver,
                UserHandle.USER_ALL
            UserHandle.USER_ALL,
        )
        configurationController.addCallback(configChangeListener)
        statusBarStateController.addCallback(statusBarStateListener)
@@ -522,16 +529,12 @@ constructor(
        smartspaceViews.forEach { it.setSplitShadeEnabled(enabled) }
    }

    /**
     * Requests the smartspace session for an update.
     */
    /** Requests the smartspace session for an update. */
    fun requestSmartspaceUpdate() {
        session?.requestSmartspaceUpdate()
    }

    /**
     * Disconnects the smartspace view from the smartspace service and cleans up any resources.
     */
    /** Disconnects the smartspace view from the smartspace service and cleans up any resources. */
    fun disconnect() {
        if (!smartspaceViews.isEmpty()) return
        if (suppressDisconnects) return
@@ -646,25 +649,24 @@ constructor(
    }

    private fun reloadSmartspace() {
        showNotifications = secureSettings.getIntForUser(
            LOCK_SCREEN_SHOW_NOTIFICATIONS,
            0,
            userTracker.userId
        ) == 1
        showNotifications =
            secureSettings.getIntForUser(LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userTracker.userId) == 1

        showSensitiveContentForCurrentUser = secureSettings.getIntForUser(
        showSensitiveContentForCurrentUser =
            secureSettings.getIntForUser(
                LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
                0,
            userTracker.userId
                userTracker.userId,
            ) == 1

        managedUserHandle = getWorkProfileUser()
        val managedId = managedUserHandle?.identifier
        if (managedId != null) {
            showSensitiveContentForManagedUser = secureSettings.getIntForUser(
            showSensitiveContentForManagedUser =
                secureSettings.getIntForUser(
                    LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
                    0,
                managedId
                    managedId,
                ) == 1
        }

@@ -682,9 +684,7 @@ constructor(

    override fun dump(pw: PrintWriter, args: Array<out String>) {
        pw.asIndenting().run {
            printCollection("Region Samplers", regionSamplers.values) {
                it.dump(this)
            }
            printCollection("Region Samplers", regionSamplers.values) { it.dump(this) }
        }

        pw.println("Recent BC Smartspace Targets (most recent first)")
@@ -707,11 +707,13 @@ constructor(
        private val keyguardUpdateMonitor: KeyguardUpdateMonitor
    ) : TimeChangedDelegate {
        private var keyguardUpdateMonitorCallback: KeyguardUpdateMonitorCallback? = null

        override fun register(callback: Runnable) {
            if (keyguardUpdateMonitorCallback != null) {
                unregister()
            }
            keyguardUpdateMonitorCallback = object : KeyguardUpdateMonitorCallback() {
            keyguardUpdateMonitorCallback =
                object : KeyguardUpdateMonitorCallback() {
                    override fun onTimeChanged() {
                        callback.run()
                    }