Loading packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +26 −5 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private ViewGroup mStatusArea; // If the SMARTSPACE flag is set, keyguard_slice_view is replaced by the following views. private ViewGroup mDateWeatherView; private View mWeatherView; private View mSmartspaceView; Loading Loading @@ -201,7 +202,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS // TODO(b/261757708): add content observer for the Settings toggle and add/remove // weather according to the Settings. if (mSmartspaceController.isDateWeatherDecoupled()) { addWeatherView(viewIndex); addDateWeatherView(viewIndex); viewIndex += 1; } Loading Loading @@ -239,6 +240,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS void onLocaleListChanged() { if (mSmartspaceController.isEnabled()) { if (mSmartspaceController.isDateWeatherDecoupled()) { mDateWeatherView.removeView(mWeatherView); int index = mStatusArea.indexOfChild(mDateWeatherView); if (index >= 0) { mStatusArea.removeView(mDateWeatherView); addDateWeatherView(index); } } int index = mStatusArea.indexOfChild(mSmartspaceView); if (index >= 0) { mStatusArea.removeView(mSmartspaceView); Loading @@ -247,16 +256,28 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS } } private void addWeatherView(int index) { mWeatherView = mSmartspaceController.buildAndConnectWeatherView(mView); private void addDateWeatherView(int index) { mDateWeatherView = (ViewGroup) mSmartspaceController.buildAndConnectDateView(mView); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( MATCH_PARENT, WRAP_CONTENT); mStatusArea.addView(mWeatherView, index, lp); mStatusArea.addView(mDateWeatherView, index, lp); int startPadding = getContext().getResources().getDimensionPixelSize( R.dimen.below_clock_padding_start); int endPadding = getContext().getResources().getDimensionPixelSize( R.dimen.below_clock_padding_end); mWeatherView.setPaddingRelative(startPadding, 0, endPadding, 0); mDateWeatherView.setPaddingRelative(startPadding, 0, endPadding, 0); addWeatherView(); } private void addWeatherView() { LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( WRAP_CONTENT, WRAP_CONTENT); mWeatherView = mSmartspaceController.buildAndConnectWeatherView(mView); // Place weather right after the date, before the extras final int index = mDateWeatherView.getChildCount() == 0 ? 0 : 1; mDateWeatherView.addView(mWeatherView, index, lp); mWeatherView.setPaddingRelative(0, 0, 4, 0); } private void addSmartspaceView(int index) { Loading packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +4 −0 Original line number Diff line number Diff line Loading @@ -217,6 +217,10 @@ public abstract class SystemUIModule { @BindsOptionalOf abstract BcSmartspaceConfigPlugin optionalBcSmartspaceConfigPlugin(); @BindsOptionalOf @Named(SmartspaceModule.DATE_SMARTSPACE_DATA_PLUGIN) abstract BcSmartspaceDataPlugin optionalDateSmartspaceConfigPlugin(); @BindsOptionalOf @Named(SmartspaceModule.WEATHER_SMARTSPACE_DATA_PLUGIN) abstract BcSmartspaceDataPlugin optionalWeatherSmartspaceConfigPlugin(); Loading packages/SystemUI/src/com/android/systemui/smartspace/dagger/SmartspaceModule.kt +5 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,11 @@ abstract class SmartspaceModule { */ const val DREAM_SMARTSPACE_PRECONDITION = "dream_smartspace_precondition" /** * The BcSmartspaceDataPlugin for the standalone date (+alarm+dnd). */ const val DATE_SMARTSPACE_DATA_PLUGIN = "date_smartspace_data_plugin" /** * The BcSmartspaceDataPlugin for the standalone weather. */ Loading packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +28 −2 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.settings.UserTracker import com.android.systemui.shared.regionsampling.RegionSampler import com.android.systemui.shared.regionsampling.UpdateColorCallback import com.android.systemui.smartspace.dagger.SmartspaceModule.Companion.DATE_SMARTSPACE_DATA_PLUGIN import com.android.systemui.smartspace.dagger.SmartspaceModule.Companion.WEATHER_SMARTSPACE_DATA_PLUGIN import com.android.systemui.statusbar.phone.KeyguardBypassController import com.android.systemui.statusbar.policy.ConfigurationController Loading Loading @@ -84,6 +85,8 @@ constructor( @Main private val uiExecutor: Executor, @Background private val bgExecutor: Executor, @Main private val handler: Handler, @Named(DATE_SMARTSPACE_DATA_PLUGIN) optionalDatePlugin: Optional<BcSmartspaceDataPlugin>, @Named(WEATHER_SMARTSPACE_DATA_PLUGIN) optionalWeatherPlugin: Optional<BcSmartspaceDataPlugin>, optionalPlugin: Optional<BcSmartspaceDataPlugin>, Loading @@ -94,6 +97,7 @@ constructor( } private var session: SmartspaceSession? = null private val datePlugin: BcSmartspaceDataPlugin? = optionalDatePlugin.orElse(null) private val weatherPlugin: BcSmartspaceDataPlugin? = optionalWeatherPlugin.orElse(null) private val plugin: BcSmartspaceDataPlugin? = optionalPlugin.orElse(null) private val configPlugin: BcSmartspaceConfigPlugin? = optionalConfigPlugin.orElse(null) Loading Loading @@ -222,7 +226,7 @@ constructor( execution.assertIsMainThread() return featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED) && weatherPlugin != null datePlugin != null && weatherPlugin != null } private fun updateBypassEnabled() { Loading @@ -230,6 +234,25 @@ constructor( smartspaceViews.forEach { it.setKeyguardBypassEnabled(bypassEnabled) } } /** * Constructs the date view and connects it to the smartspace service. */ fun buildAndConnectDateView(parent: ViewGroup): View? { execution.assertIsMainThread() if (!isEnabled()) { throw RuntimeException("Cannot build view when not enabled") } if (!isDateWeatherDecoupled()) { throw RuntimeException("Cannot build date view when not decoupled") } val view = buildView(parent, datePlugin) connectSession() return view } /** * Constructs the weather view and connects it to the smartspace service. */ Loading Loading @@ -308,7 +331,7 @@ constructor( } private fun connectSession() { if (weatherPlugin == null && plugin == null) return if (datePlugin == null && weatherPlugin == null && plugin == null) return if (session != null || smartspaceViews.isEmpty()) { return } Loading Loading @@ -346,6 +369,7 @@ constructor( statusBarStateController.addCallback(statusBarStateListener) bypassController.registerOnBypassStateChangedListener(bypassStateChangedListener) datePlugin?.registerSmartspaceEventNotifier { e -> session?.notifySmartspaceEvent(e) } weatherPlugin?.registerSmartspaceEventNotifier { e -> session?.notifySmartspaceEvent(e) } plugin?.registerSmartspaceEventNotifier { e -> session?.notifySmartspaceEvent(e) } Loading Loading @@ -383,6 +407,8 @@ constructor( bypassController.unregisterOnBypassStateChangedListener(bypassStateChangedListener) session = null datePlugin?.registerSmartspaceEventNotifier(null) weatherPlugin?.registerSmartspaceEventNotifier(null) weatherPlugin?.onTargetsAvailable(emptyList()) Loading packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.os.UserHandle; import android.provider.Settings; import android.testing.AndroidTestingRunner; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.RelativeLayout; Loading Loading @@ -118,6 +119,11 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { @Mock private LogBuffer mLogBuffer; private final View mFakeDateView = (View) (new ViewGroup(mContext) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) {} }); private final View mFakeWeatherView = new View(mContext); private final View mFakeSmartspaceView = new View(mContext); private KeyguardClockSwitchController mController; Loading Loading @@ -145,6 +151,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { when(mLargeClockView.getContext()).thenReturn(getContext()); when(mView.isAttachedToWindow()).thenReturn(true); when(mSmartspaceController.buildAndConnectDateView(any())).thenReturn(mFakeDateView); when(mSmartspaceController.buildAndConnectWeatherView(any())).thenReturn(mFakeWeatherView); when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mFakeSmartspaceView); mExecutor = new FakeExecutor(new FakeSystemClock()); mController = new KeyguardClockSwitchController( Loading Loading @@ -251,6 +259,19 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { verify(mSmartspaceController, times(2)).buildAndConnectView(mView); } @Test public void onLocaleListChanged_rebuildsSmartspaceViews_whenDecouplingEnabled() { when(mSmartspaceController.isEnabled()).thenReturn(true); when(mSmartspaceController.isDateWeatherDecoupled()).thenReturn(true); mController.init(); mController.onLocaleListChanged(); // Should be called once on initial setup, then once again for locale change verify(mSmartspaceController, times(2)).buildAndConnectDateView(mView); verify(mSmartspaceController, times(2)).buildAndConnectWeatherView(mView); verify(mSmartspaceController, times(2)).buildAndConnectView(mView); } @Test public void testSmartspaceDisabledShowsKeyguardStatusArea() { when(mSmartspaceController.isEnabled()).thenReturn(false); Loading Loading
packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +26 −5 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS private ViewGroup mStatusArea; // If the SMARTSPACE flag is set, keyguard_slice_view is replaced by the following views. private ViewGroup mDateWeatherView; private View mWeatherView; private View mSmartspaceView; Loading Loading @@ -201,7 +202,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS // TODO(b/261757708): add content observer for the Settings toggle and add/remove // weather according to the Settings. if (mSmartspaceController.isDateWeatherDecoupled()) { addWeatherView(viewIndex); addDateWeatherView(viewIndex); viewIndex += 1; } Loading Loading @@ -239,6 +240,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS void onLocaleListChanged() { if (mSmartspaceController.isEnabled()) { if (mSmartspaceController.isDateWeatherDecoupled()) { mDateWeatherView.removeView(mWeatherView); int index = mStatusArea.indexOfChild(mDateWeatherView); if (index >= 0) { mStatusArea.removeView(mDateWeatherView); addDateWeatherView(index); } } int index = mStatusArea.indexOfChild(mSmartspaceView); if (index >= 0) { mStatusArea.removeView(mSmartspaceView); Loading @@ -247,16 +256,28 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS } } private void addWeatherView(int index) { mWeatherView = mSmartspaceController.buildAndConnectWeatherView(mView); private void addDateWeatherView(int index) { mDateWeatherView = (ViewGroup) mSmartspaceController.buildAndConnectDateView(mView); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( MATCH_PARENT, WRAP_CONTENT); mStatusArea.addView(mWeatherView, index, lp); mStatusArea.addView(mDateWeatherView, index, lp); int startPadding = getContext().getResources().getDimensionPixelSize( R.dimen.below_clock_padding_start); int endPadding = getContext().getResources().getDimensionPixelSize( R.dimen.below_clock_padding_end); mWeatherView.setPaddingRelative(startPadding, 0, endPadding, 0); mDateWeatherView.setPaddingRelative(startPadding, 0, endPadding, 0); addWeatherView(); } private void addWeatherView() { LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( WRAP_CONTENT, WRAP_CONTENT); mWeatherView = mSmartspaceController.buildAndConnectWeatherView(mView); // Place weather right after the date, before the extras final int index = mDateWeatherView.getChildCount() == 0 ? 0 : 1; mDateWeatherView.addView(mWeatherView, index, lp); mWeatherView.setPaddingRelative(0, 0, 4, 0); } private void addSmartspaceView(int index) { Loading
packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +4 −0 Original line number Diff line number Diff line Loading @@ -217,6 +217,10 @@ public abstract class SystemUIModule { @BindsOptionalOf abstract BcSmartspaceConfigPlugin optionalBcSmartspaceConfigPlugin(); @BindsOptionalOf @Named(SmartspaceModule.DATE_SMARTSPACE_DATA_PLUGIN) abstract BcSmartspaceDataPlugin optionalDateSmartspaceConfigPlugin(); @BindsOptionalOf @Named(SmartspaceModule.WEATHER_SMARTSPACE_DATA_PLUGIN) abstract BcSmartspaceDataPlugin optionalWeatherSmartspaceConfigPlugin(); Loading
packages/SystemUI/src/com/android/systemui/smartspace/dagger/SmartspaceModule.kt +5 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,11 @@ abstract class SmartspaceModule { */ const val DREAM_SMARTSPACE_PRECONDITION = "dream_smartspace_precondition" /** * The BcSmartspaceDataPlugin for the standalone date (+alarm+dnd). */ const val DATE_SMARTSPACE_DATA_PLUGIN = "date_smartspace_data_plugin" /** * The BcSmartspaceDataPlugin for the standalone weather. */ Loading
packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +28 −2 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.settings.UserTracker import com.android.systemui.shared.regionsampling.RegionSampler import com.android.systemui.shared.regionsampling.UpdateColorCallback import com.android.systemui.smartspace.dagger.SmartspaceModule.Companion.DATE_SMARTSPACE_DATA_PLUGIN import com.android.systemui.smartspace.dagger.SmartspaceModule.Companion.WEATHER_SMARTSPACE_DATA_PLUGIN import com.android.systemui.statusbar.phone.KeyguardBypassController import com.android.systemui.statusbar.policy.ConfigurationController Loading Loading @@ -84,6 +85,8 @@ constructor( @Main private val uiExecutor: Executor, @Background private val bgExecutor: Executor, @Main private val handler: Handler, @Named(DATE_SMARTSPACE_DATA_PLUGIN) optionalDatePlugin: Optional<BcSmartspaceDataPlugin>, @Named(WEATHER_SMARTSPACE_DATA_PLUGIN) optionalWeatherPlugin: Optional<BcSmartspaceDataPlugin>, optionalPlugin: Optional<BcSmartspaceDataPlugin>, Loading @@ -94,6 +97,7 @@ constructor( } private var session: SmartspaceSession? = null private val datePlugin: BcSmartspaceDataPlugin? = optionalDatePlugin.orElse(null) private val weatherPlugin: BcSmartspaceDataPlugin? = optionalWeatherPlugin.orElse(null) private val plugin: BcSmartspaceDataPlugin? = optionalPlugin.orElse(null) private val configPlugin: BcSmartspaceConfigPlugin? = optionalConfigPlugin.orElse(null) Loading Loading @@ -222,7 +226,7 @@ constructor( execution.assertIsMainThread() return featureFlags.isEnabled(Flags.SMARTSPACE_DATE_WEATHER_DECOUPLED) && weatherPlugin != null datePlugin != null && weatherPlugin != null } private fun updateBypassEnabled() { Loading @@ -230,6 +234,25 @@ constructor( smartspaceViews.forEach { it.setKeyguardBypassEnabled(bypassEnabled) } } /** * Constructs the date view and connects it to the smartspace service. */ fun buildAndConnectDateView(parent: ViewGroup): View? { execution.assertIsMainThread() if (!isEnabled()) { throw RuntimeException("Cannot build view when not enabled") } if (!isDateWeatherDecoupled()) { throw RuntimeException("Cannot build date view when not decoupled") } val view = buildView(parent, datePlugin) connectSession() return view } /** * Constructs the weather view and connects it to the smartspace service. */ Loading Loading @@ -308,7 +331,7 @@ constructor( } private fun connectSession() { if (weatherPlugin == null && plugin == null) return if (datePlugin == null && weatherPlugin == null && plugin == null) return if (session != null || smartspaceViews.isEmpty()) { return } Loading Loading @@ -346,6 +369,7 @@ constructor( statusBarStateController.addCallback(statusBarStateListener) bypassController.registerOnBypassStateChangedListener(bypassStateChangedListener) datePlugin?.registerSmartspaceEventNotifier { e -> session?.notifySmartspaceEvent(e) } weatherPlugin?.registerSmartspaceEventNotifier { e -> session?.notifySmartspaceEvent(e) } plugin?.registerSmartspaceEventNotifier { e -> session?.notifySmartspaceEvent(e) } Loading Loading @@ -383,6 +407,8 @@ constructor( bypassController.unregisterOnBypassStateChangedListener(bypassStateChangedListener) session = null datePlugin?.registerSmartspaceEventNotifier(null) weatherPlugin?.registerSmartspaceEventNotifier(null) weatherPlugin?.onTargetsAvailable(emptyList()) Loading
packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.os.UserHandle; import android.provider.Settings; import android.testing.AndroidTestingRunner; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.RelativeLayout; Loading Loading @@ -118,6 +119,11 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { @Mock private LogBuffer mLogBuffer; private final View mFakeDateView = (View) (new ViewGroup(mContext) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) {} }); private final View mFakeWeatherView = new View(mContext); private final View mFakeSmartspaceView = new View(mContext); private KeyguardClockSwitchController mController; Loading Loading @@ -145,6 +151,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { when(mLargeClockView.getContext()).thenReturn(getContext()); when(mView.isAttachedToWindow()).thenReturn(true); when(mSmartspaceController.buildAndConnectDateView(any())).thenReturn(mFakeDateView); when(mSmartspaceController.buildAndConnectWeatherView(any())).thenReturn(mFakeWeatherView); when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mFakeSmartspaceView); mExecutor = new FakeExecutor(new FakeSystemClock()); mController = new KeyguardClockSwitchController( Loading Loading @@ -251,6 +259,19 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { verify(mSmartspaceController, times(2)).buildAndConnectView(mView); } @Test public void onLocaleListChanged_rebuildsSmartspaceViews_whenDecouplingEnabled() { when(mSmartspaceController.isEnabled()).thenReturn(true); when(mSmartspaceController.isDateWeatherDecoupled()).thenReturn(true); mController.init(); mController.onLocaleListChanged(); // Should be called once on initial setup, then once again for locale change verify(mSmartspaceController, times(2)).buildAndConnectDateView(mView); verify(mSmartspaceController, times(2)).buildAndConnectWeatherView(mView); verify(mSmartspaceController, times(2)).buildAndConnectView(mView); } @Test public void testSmartspaceDisabledShowsKeyguardStatusArea() { when(mSmartspaceController.isEnabled()).thenReturn(false); Loading