diff --git a/packages/SystemUI/plugin/Android.bp b/packages/SystemUI/plugin/Android.bp index 7709f210f22f8..fb1c454de70d3 100644 --- a/packages/SystemUI/plugin/Android.bp +++ b/packages/SystemUI/plugin/Android.bp @@ -29,6 +29,7 @@ java_library { "src/**/*.java", "src/**/*.kt", "bcsmartspace/src/**/*.java", + "bcsmartspace/src/**/*.kt", ], static_libs: [ diff --git a/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceConfigPlugin.kt b/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceConfigPlugin.kt new file mode 100644 index 0000000000000..509f022310d00 --- /dev/null +++ b/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceConfigPlugin.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.plugins + +// TODO(b/265360975): Evaluate this plugin approach. +/** Plugin to provide BC smartspace configuration */ +interface BcSmartspaceConfigPlugin { + /** Gets default date/weather disabled status. */ + val isDefaultDateWeatherDisabled: Boolean +} diff --git a/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java b/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java index 51f5baa8b45ff..bc6e5ec6117ce 100644 --- a/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java +++ b/packages/SystemUI/plugin/bcsmartspace/src/com/android/systemui/plugins/BcSmartspaceDataPlugin.java @@ -93,6 +93,11 @@ public interface BcSmartspaceDataPlugin extends Plugin { interface SmartspaceView { void registerDataProvider(BcSmartspaceDataPlugin plugin); + /** + * Sets {@link BcSmartspaceConfigPlugin}. + */ + void registerConfigProvider(BcSmartspaceConfigPlugin configProvider); + /** * Primary color for unprotected text */ diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 6d13740afe8ba..2d0dfa1d921b0 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -54,6 +54,7 @@ import com.android.systemui.motiontool.MotionToolModule; import com.android.systemui.navigationbar.NavigationBarComponent; import com.android.systemui.notetask.NoteTaskModule; import com.android.systemui.people.PeopleModule; +import com.android.systemui.plugins.BcSmartspaceConfigPlugin; import com.android.systemui.plugins.BcSmartspaceDataPlugin; import com.android.systemui.privacy.PrivacyModule; import com.android.systemui.qs.FgsManagerController; @@ -210,6 +211,9 @@ public abstract class SystemUIModule { @BindsOptionalOf abstract BcSmartspaceDataPlugin optionalBcSmartspaceDataPlugin(); + @BindsOptionalOf + abstract BcSmartspaceConfigPlugin optionalBcSmartspaceConfigPlugin(); + @BindsOptionalOf abstract Recents optionalRecents(); diff --git a/packages/SystemUI/src/com/android/systemui/smartspace/config/BcSmartspaceConfigProvider.kt b/packages/SystemUI/src/com/android/systemui/smartspace/config/BcSmartspaceConfigProvider.kt new file mode 100644 index 0000000000000..ab0d6e3a63826 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/smartspace/config/BcSmartspaceConfigProvider.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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) +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt index d6ad7d0fb8cfd..2849739760030 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt @@ -43,6 +43,7 @@ import com.android.systemui.dagger.qualifiers.Main 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 import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceTargetListener import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceView @@ -60,11 +61,11 @@ import java.util.Optional import java.util.concurrent.Executor import javax.inject.Inject -/** - * Controller for managing the smartspace view on the lockscreen - */ +/** Controller for managing the smartspace view on the lockscreen */ @SysUISingleton -class LockscreenSmartspaceController @Inject constructor( +class LockscreenSmartspaceController +@Inject +constructor( private val context: Context, private val featureFlags: FeatureFlags, private val smartspaceManager: SmartspaceManager, @@ -81,7 +82,8 @@ class LockscreenSmartspaceController @Inject constructor( @Main private val uiExecutor: Executor, @Background private val bgExecutor: Executor, @Main private val handler: Handler, - optionalPlugin: Optional + optionalPlugin: Optional, + optionalConfigPlugin: Optional, ) { companion object { private const val TAG = "LockscreenSmartspaceController" @@ -89,6 +91,7 @@ class LockscreenSmartspaceController @Inject constructor( private var session: SmartspaceSession? = null private val plugin: BcSmartspaceDataPlugin? = optionalPlugin.orElse(null) + private val configPlugin: BcSmartspaceConfigPlugin? = optionalConfigPlugin.orElse(null) // Smartspace can be used on multiple displays, such as when the user casts their screen private var smartspaceViews = mutableSetOf() @@ -240,6 +243,7 @@ class LockscreenSmartspaceController @Inject constructor( val ssView = plugin.getView(parent) ssView.setUiSurface(BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD) ssView.registerDataProvider(plugin) + ssView.registerConfigProvider(configPlugin) ssView.setIntentStarter(object : BcSmartspaceDataPlugin.IntentStarter { override fun startIntent(view: View, intent: Intent, showOnLockscreen: Boolean) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/smartspace/BcSmartspaceConfigProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/smartspace/BcSmartspaceConfigProviderTest.kt new file mode 100644 index 0000000000000..5fb1e79e93e84 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/smartspace/BcSmartspaceConfigProviderTest.kt @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.smartspace + +import android.testing.AndroidTestingRunner +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 +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.MockitoAnnotations + +@SmallTest +@RunWith(AndroidTestingRunner::class) +class BcSmartspaceConfigProviderTest : SysuiTestCase() { + @Mock private lateinit var featureFlags: FeatureFlags + + private lateinit var configProvider: BcSmartspaceConfigProvider + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + configProvider = BcSmartspaceConfigProvider(featureFlags) + } + + @Test + fun isDefaultDateWeatherDisabled_flagIsTrue_returnsTrue() { + whenever(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(true) + + assertTrue(configProvider.isDefaultDateWeatherDisabled) + } + + @Test + fun isDefaultDateWeatherDisabled_flagIsFalse_returnsFalse() { + whenever(featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED)).thenReturn(false) + + assertFalse(configProvider.isDefaultDateWeatherDisabled) + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt index 001e1f4d8086d..c5432c5fe330d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt @@ -27,6 +27,7 @@ import android.view.ViewGroup import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.dreams.smartspace.DreamSmartspaceController +import com.android.systemui.plugins.BcSmartspaceConfigPlugin import com.android.systemui.plugins.BcSmartspaceDataPlugin import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceView import com.android.systemui.plugins.FalsingManager @@ -94,6 +95,8 @@ class DreamSmartspaceControllerTest : SysuiTestCase() { private class TestView(context: Context?) : View(context), SmartspaceView { override fun registerDataProvider(plugin: BcSmartspaceDataPlugin?) {} + override fun registerConfigProvider(plugin: BcSmartspaceConfigPlugin?) {} + override fun setPrimaryTextColor(color: Int) {} override fun setIsDreaming(isDreaming: Boolean) {} diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt index ddcf59ec001fc..4bcb54ddbbc02 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt @@ -36,6 +36,7 @@ import com.android.systemui.SysuiTestCase 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 import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceTargetListener import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceView @@ -114,6 +115,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() { @Mock private lateinit var plugin: BcSmartspaceDataPlugin + @Mock + private lateinit var configPlugin: BcSmartspaceConfigPlugin + @Mock private lateinit var controllerListener: SmartspaceTargetListener @@ -209,7 +213,8 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() { executor, bgExecutor, handler, - Optional.of(plugin) + Optional.of(plugin), + Optional.of(configPlugin), ) verify(deviceProvisionedController).addCallback(capture(deviceProvisionedCaptor)) @@ -520,6 +525,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() { verify(smartspaceManager, never()).createSmartspaceSession(any()) verify(smartspaceView2).setUiSurface(BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD) verify(smartspaceView2).registerDataProvider(plugin) + verify(smartspaceView2).registerConfigProvider(configPlugin) } @Test @@ -557,6 +563,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() { verify(smartspaceView).setUiSurface(BcSmartspaceDataPlugin.UI_SURFACE_LOCK_SCREEN_AOD) verify(smartspaceView).registerDataProvider(plugin) + verify(smartspaceView).registerConfigProvider(configPlugin) verify(smartspaceSession) .addOnTargetsAvailableListener(any(), capture(sessionListenerCaptor)) sessionListener = sessionListenerCaptor.value @@ -638,6 +645,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() { override fun registerDataProvider(plugin: BcSmartspaceDataPlugin?) { } + override fun registerConfigProvider(plugin: BcSmartspaceConfigPlugin?) { + } + override fun setPrimaryTextColor(color: Int) { }