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

Commit e60d5c87 authored by Xiaowen Lei's avatar Xiaowen Lei
Browse files

Remove released flag SMARTSPACE_DATE_WEATHER_DECOUPLED and its use sites.

Also, fixed a mistake in LSController.filterSmartspaceTarget. After the
flag value in LSControllerTest, the mistake was caught by the following
unit tests:
   - testSettingsAreReloaded
   - testSensitiveTargetsAreFilteredOutForAppropriateUsers
   - testRecognizeSwitchToSecondaryUser
   - testAllTargetsAreFilteredExceptWeatherWhenNotificationsAreDisabled
I believe the mistake caused a regression on filtering sensitive targets
for work profile. See http://b/277963509#comment14 for more details.

Flag: LEGACY SMARTSPACE_DATE_WEATHER_DECOUPLED NEXTFOOD
Bug: 309825884
Bug: 277963509
Test: unit (see updated Test files)
Test: on device, trigger alarm, dnd, timer, calendar
Change-Id: I33075849ca95c1bab5f9260eaf7506513883efef
parent 7a338c16
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -345,11 +345,6 @@ object Flags {
    val SMARTSPACE_SHARED_ELEMENT_TRANSITION_ENABLED =
        releasedFlag("smartspace_shared_element_transition_enabled")

    // TODO(b/258517050): Clean up after the feature is launched.
    @JvmField
    val SMARTSPACE_DATE_WEATHER_DECOUPLED =
        sysPropBooleanFlag("persist.sysui.ss.dw_decoupled", default = true)

    // TODO(b/270223352): Tracking Bug
    @JvmField
    val HIDE_SMARTSPACE_ON_DREAM_OVERLAY = releasedFlag("hide_smartspace_on_dream_overlay")
+1 −2
Original line number Diff line number Diff line
@@ -17,11 +17,10 @@
package com.android.systemui.smartspace.config

import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.plugins.BcSmartspaceConfigPlugin

class BcSmartspaceConfigProvider(private val featureFlags: FeatureFlags) :
    BcSmartspaceConfigPlugin {
    override val isDefaultDateWeatherDisabled: Boolean
        get() = featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)
        get() = true
}
+3 −4
Original line number Diff line number Diff line
@@ -267,8 +267,7 @@ constructor(
    fun isDateWeatherDecoupled(): Boolean {
        execution.assertIsMainThread()

        return featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED) &&
                datePlugin != null && weatherPlugin != null
        return datePlugin != null && weatherPlugin != null
    }

    fun isWeatherEnabled(): Boolean {
@@ -499,8 +498,8 @@ constructor(
    }

    private fun filterSmartspaceTarget(t: SmartspaceTarget): Boolean {
        if (isDateWeatherDecoupled()) {
            return t.featureType != SmartspaceTarget.FEATURE_WEATHER
        if (isDateWeatherDecoupled() && t.featureType == SmartspaceTarget.FEATURE_WEATHER) {
            return false
        }
        if (!showNotifications) {
            return t.featureType == SmartspaceTarget.FEATURE_WEATHER
+1 −13
Original line number Diff line number Diff line
@@ -20,10 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.smartspace.config.BcSmartspaceConfigProvider
import com.android.systemui.util.mockito.whenever
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.junit.Before
import org.junit.Test
@@ -45,16 +42,7 @@ class BcSmartspaceConfigProviderTest : SysuiTestCase() {
    }

    @Test
    fun isDefaultDateWeatherDisabled_flagIsTrue_returnsTrue() {
        whenever(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(true)

    fun isDefaultDateWeatherDisabled_returnsTrue() {
        assertTrue(configProvider.isDefaultDateWeatherDisabled)
    }

    @Test
    fun isDefaultDateWeatherDisabled_flagIsFalse_returnsFalse() {
        whenever(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(false)

        assertFalse(configProvider.isDefaultDateWeatherDisabled)
    }
}
+33 −116
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import com.android.keyguard.KeyguardUpdateMonitor
import com.android.systemui.SysuiTestCase
import com.android.systemui.dump.DumpManager
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.BcSmartspaceConfigPlugin
import com.android.systemui.plugins.BcSmartspaceDataPlugin
@@ -205,10 +204,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
    fun setUp() {
        MockitoAnnotations.initMocks(this)

        // Todo(b/261760571): flip the flag value here when feature is launched, and update relevant
        //  tests.
        `when`(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(false)

        `when`(secureSettings.getUriFor(PRIVATE_LOCKSCREEN_SETTING))
                .thenReturn(fakePrivateLockscreenSettingUri)
        `when`(secureSettings.getUriFor(NOTIF_ON_LOCKSCREEN_SETTING))
@@ -260,17 +255,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        deviceProvisionedListener = deviceProvisionedCaptor.value
    }

    @Test(expected = RuntimeException::class)
    fun testBuildAndConnectWeatherView_throwsIfDecouplingDisabled() {
        // GIVEN the feature flag is disabled
        `when`(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(false)

        // WHEN we try to build the view
        controller.buildAndConnectWeatherView(fakeParent)

        // THEN an exception is thrown
    }

    @Test
    fun testBuildAndConnectView_connectsOnlyAfterDeviceIsProvisioned() {
        // GIVEN an unprovisioned device and an attempt to connect
@@ -332,6 +316,8 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        clearInvocations(plugin)

        // WHEN the session is closed
        controller.stateChangeListener.onViewDetachedFromWindow(dateSmartspaceView as View)
        controller.stateChangeListener.onViewDetachedFromWindow(weatherSmartspaceView as View)
        controller.stateChangeListener.onViewDetachedFromWindow(smartspaceView as View)
        controller.disconnect()

@@ -375,20 +361,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        // WHEN the theme changes
        configChangeListener.onThemeChanged()

        // We update the new text color to match the wallpaper color
        verify(smartspaceView).setPrimaryTextColor(anyInt())
    }

    @Test
    fun testThemeChange_ifDecouplingEnabled_updatesTextColor() {
        `when`(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(true)

        // GIVEN a connected smartspace session
        connectSession()

        // WHEN the theme changes
        configChangeListener.onThemeChanged()

        // We update the new text color to match the wallpaper color
        verify(dateSmartspaceView).setPrimaryTextColor(anyInt())
        verify(weatherSmartspaceView).setPrimaryTextColor(anyInt())
@@ -403,20 +375,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        // WHEN the doze amount changes
        statusBarStateListener.onDozeAmountChanged(0.1f, 0.7f)

        // We pass that along to the view
        verify(smartspaceView).setDozeAmount(0.7f)
    }

    @Test
    fun testDozeAmountChange_ifDecouplingEnabled_updatesViews() {
        `when`(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(true)

        // GIVEN a connected smartspace session
        connectSession()

        // WHEN the doze amount changes
        statusBarStateListener.onDozeAmountChanged(0.1f, 0.7f)

        // We pass that along to the view
        verify(dateSmartspaceView).setDozeAmount(0.7f)
        verify(weatherSmartspaceView).setDozeAmount(0.7f)
@@ -472,7 +430,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
    }

    @Test
    fun testAllTargetsAreFilteredExceptWeatherWhenNotificationsAreDisabled() {
    fun testAllTargetsAreFilteredInclWeatherWhenNotificationsAreDisabled() {
        // GIVEN the active user doesn't allow any notifications on lockscreen
        setShowNotifications(userHandlePrimary, false)
        connectSession()
@@ -488,7 +446,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        sessionListener.onTargetsAvailable(targets)

        // THEN all non-sensitive content is still shown
        verify(plugin).onTargetsAvailable(eq(listOf(targets[3])))
        verify(plugin).onTargetsAvailable(emptyList())
    }

    @Test
@@ -519,8 +477,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
    }

    @Test
    fun testSessionListener_ifDecouplingEnabled_weatherTargetIsFilteredOut() {
        `when`(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(true)
    fun testSessionListener_weatherTargetIsFilteredOut() {
        connectSession()

        // WHEN we receive a list of targets
@@ -670,8 +627,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
    }

    @Test
    fun testSessionListener_ifDecouplingEnabled_weatherDataUpdates() {
        `when`(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(true)
    fun testSessionListener_weatherDataUpdates() {
        connectSession()

        clock.setCurrentTimeMillis(SMARTSPACE_TIME_JUST_RIGHT)
@@ -698,33 +654,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        })
    }

    @Test
    fun testSessionListener_ifDecouplingDisabled_weatherDataUpdates() {
        `when`(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(false)
        connectSession()

        clock.setCurrentTimeMillis(SMARTSPACE_TIME_JUST_RIGHT)
        // WHEN we receive a list of targets
        val targets = listOf(
                makeWeatherTargetWithExtras(
                        id = 1,
                        userHandle = userHandlePrimary,
                        description = "Sunny",
                        state = WeatherData.WeatherStateIcon.SUNNY.id,
                        temperature = "32",
                        useCelsius = false),
                makeTarget(2, userHandlePrimary, isSensitive = true)
        )

        sessionListener.onTargetsAvailable(targets)

        verify(keyguardUpdateMonitor).sendWeatherData(argThat { w ->
            w.description == "Sunny" &&
                    w.state == WeatherData.WeatherStateIcon.SUNNY &&
                    w.temperature == 32 && !w.useCelsius
        })
    }

    @Test
    fun testSettingsAreReloaded() {
        // GIVEN a connected session where the privacy settings later flip to false
@@ -781,6 +710,8 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        connectSession()

        // WHEN we are told to cleanup
        controller.stateChangeListener.onViewDetachedFromWindow(dateSmartspaceView as View)
        controller.stateChangeListener.onViewDetachedFromWindow(weatherSmartspaceView as View)
        controller.stateChangeListener.onViewDetachedFromWindow(smartspaceView as View)
        controller.disconnect()

@@ -815,16 +746,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        verify(smartspaceView2).registerConfigProvider(configPlugin)
    }

    @Test
    fun testWeatherViewUsesSameSession() {
        `when`(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(true)
        // GIVEN a connected session
        connectSession()

        // No checks is needed here, since connectSession() already checks internally that
        // createSmartspaceSession is invoked only once.
    }

    @Test
    fun testViewGetInitializedWithBypassEnabledState() {
        // GIVEN keyguard bypass is enabled.
@@ -853,7 +774,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
    }

    private fun connectSession() {
        if (controller.isDateWeatherDecoupled()) {
        val dateView = controller.buildAndConnectDateView(fakeParent)
        dateSmartspaceView = dateView as SmartspaceView
        fakeParent.addView(dateView)
@@ -877,7 +797,6 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {

        verify(weatherSmartspaceView).setPrimaryTextColor(anyInt())
        verify(weatherSmartspaceView).setDozeAmount(0.5f)
        }

        val view = controller.buildAndConnectView(fakeParent)
        smartspaceView = view as SmartspaceView
@@ -918,10 +837,8 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
        verify(smartspaceView).setPrimaryTextColor(anyInt())
        verify(smartspaceView).setDozeAmount(0.5f)

        if (controller.isDateWeatherDecoupled()) {
        clearInvocations(dateSmartspaceView)
        clearInvocations(weatherSmartspaceView)
        }
        clearInvocations(smartspaceView)
    }