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

Commit aaef048c authored by Andy Wickham's avatar Andy Wickham Committed by Android (Google) Code Review
Browse files

Merge "Removes System UI plugin for BC Smartspace." into sc-dev

parents 7ae022ad 46ad0118
Loading
Loading
Loading
Loading
+47 −86
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ import android.app.WallpaperManager;
import android.app.smartspace.SmartspaceConfig;
import android.app.smartspace.SmartspaceManager;
import android.app.smartspace.SmartspaceSession;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.text.TextUtils;
@@ -39,14 +37,13 @@ import com.android.internal.graphics.ColorUtils;
import com.android.keyguard.clock.ClockManager;
import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.BcSmartspaceDataPlugin;
import com.android.systemui.plugins.ClockPlugin;
import com.android.systemui.plugins.PluginListener;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shared.plugins.PluginManager;
import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.notification.AnimatableProperty;
import com.android.systemui.statusbar.notification.PropertyAnimator;
@@ -69,14 +66,16 @@ import javax.inject.Inject;
public class KeyguardClockSwitchController extends ViewController<KeyguardClockSwitch> {
    private static final boolean CUSTOM_CLOCKS_ENABLED = true;

    private final Resources mResources;
    private final StatusBarStateController mStatusBarStateController;
    private final SysuiColorExtractor mColorExtractor;
    private final ClockManager mClockManager;
    private final KeyguardSliceViewController mKeyguardSliceViewController;
    private final NotificationIconAreaController mNotificationIconAreaController;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final Executor mUiExecutor;
    private final BatteryController mBatteryController;
    private final FeatureFlags mFeatureFlags;
    private final SystemUIFactory mSystemUIFactory;

    /**
     * Clock for both small and large sizes
@@ -86,10 +85,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    private AnimatableClockController mLargeClockViewController;
    private FrameLayout mLargeClockFrame;

    private PluginManager mPluginManager;
    private boolean mIsSmartspaceEnabled;
    PluginListener mPluginListener;
    private Executor mUiExecutor;
    private SmartspaceSession mSmartspaceSession;
    private SmartspaceSession.Callback mSmartspaceCallback;
    private float mDozeAmount;
@@ -137,31 +132,28 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    @Inject
    public KeyguardClockSwitchController(
            KeyguardClockSwitch keyguardClockSwitch,
            @Main Resources resources,
            StatusBarStateController statusBarStateController,
            SysuiColorExtractor colorExtractor, ClockManager clockManager,
            KeyguardSliceViewController keyguardSliceViewController,
            NotificationIconAreaController notificationIconAreaController,
            ContentResolver contentResolver,
            BroadcastDispatcher broadcastDispatcher,
            PluginManager pluginManager,
            FeatureFlags featureFlags,
            @Main Executor uiExecutor,
            BatteryController batteryController,
            ConfigurationController configurationController) {
            ConfigurationController configurationController,
            SystemUIFactory systemUIFactory) {
        super(keyguardClockSwitch);
        mResources = resources;
        mStatusBarStateController = statusBarStateController;
        mColorExtractor = colorExtractor;
        mClockManager = clockManager;
        mKeyguardSliceViewController = keyguardSliceViewController;
        mNotificationIconAreaController = notificationIconAreaController;
        mBroadcastDispatcher = broadcastDispatcher;
        mPluginManager = pluginManager;
        mIsSmartspaceEnabled = featureFlags.isSmartspaceEnabled();
        mFeatureFlags = featureFlags;
        mUiExecutor = uiExecutor;
        mBatteryController = batteryController;
        mConfigurationController = configurationController;
        mSystemUIFactory = systemUIFactory;
    }

    /**
@@ -206,24 +198,18 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        mStatusBarStateController.addCallback(mStatusBarStateListener);
        mConfigurationController.addCallback(mConfigurationListener);

        // If a smartspace plugin is detected, replace the existing smartspace
        // (keyguard_status_area), and initialize a new session
        mPluginListener = new PluginListener<BcSmartspaceDataPlugin>() {

            @Override
            public void onPluginConnected(BcSmartspaceDataPlugin plugin, Context pluginContext) {
                if (!mIsSmartspaceEnabled) return;

        BcSmartspaceDataPlugin smartspaceDataPlugin = mSystemUIFactory.getSmartspaceDataProvider();
        if (mFeatureFlags.isSmartspaceEnabled() && smartspaceDataPlugin != null) {
            View ksa = mView.findViewById(R.id.keyguard_status_area);
            int ksaIndex = mView.indexOfChild(ksa);
            ksa.setVisibility(View.GONE);

                mSmartspaceView = plugin.getView(mView);
                mSmartspaceView.registerDataProvider(plugin);
            mSmartspaceView = smartspaceDataPlugin.getView(mView);
            mSmartspaceView.registerDataProvider(smartspaceDataPlugin);
            updateSmartspaceColor();
            View asView = (View) mSmartspaceView;

                // Place plugin view below normal clock...
            // Place smartspace view below normal clock...
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    MATCH_PARENT, WRAP_CONTENT);
            lp.addRule(RelativeLayout.BELOW, R.id.lockscreen_clock_view);
@@ -239,42 +225,18 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
            mLargeClockFrame.setLayoutParams(lp);

            View nic = mView.findViewById(
                        com.android.systemui.R.id.left_aligned_notification_icon_container);
                    R.id.left_aligned_notification_icon_container);
            lp = (RelativeLayout.LayoutParams) nic.getLayoutParams();
            lp.addRule(RelativeLayout.BELOW, asView.getId());
            nic.setLayoutParams(lp);

                createSmartspaceSession(plugin);
            }

            @Override
            public void onPluginDisconnected(BcSmartspaceDataPlugin plugin) {
                if (!mIsSmartspaceEnabled) return;

                mView.removeView((View) mSmartspaceView);
                mView.findViewById(R.id.keyguard_status_area).setVisibility(View.VISIBLE);

                View nic = mView.findViewById(
                        com.android.systemui.R.id.left_aligned_notification_icon_container);
                RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)
                        nic.getLayoutParams();
                lp.addRule(RelativeLayout.BELOW, R.id.keyguard_status_area);
                nic.setLayoutParams(lp);
                mLargeClockFrame.setLayoutParams(lp);

                mSmartspaceView = null;
            }

            private void createSmartspaceSession(BcSmartspaceDataPlugin plugin) {
            mSmartspaceSession = getContext().getSystemService(SmartspaceManager.class)
                    .createSmartspaceSession(
                            new SmartspaceConfig.Builder(getContext(), "lockscreen").build());
                mSmartspaceCallback = targets -> plugin.onTargetsAvailable(targets);
            mSmartspaceCallback = targets -> smartspaceDataPlugin.onTargetsAvailable(targets);
            mSmartspaceSession.registerSmartspaceUpdates(mUiExecutor, mSmartspaceCallback);
            mSmartspaceSession.requestSmartspaceUpdate();
        }
        };
        mPluginManager.addPluginListener(mPluginListener, BcSmartspaceDataPlugin.class, false);
    }

    private void updateWallpaperColor() {
@@ -303,7 +265,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
            mSmartspaceSession.destroy();
            mSmartspaceSession = null;
        }
        mPluginManager.removePluginListener(mPluginListener);
        mStatusBarStateController.removeCallback(mStatusBarStateListener);
        mConfigurationController.removeCallback(mConfigurationListener);
    }
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.dagger.GlobalRootComponent;
import com.android.systemui.dagger.SysUIComponent;
import com.android.systemui.dagger.WMComponent;
import com.android.systemui.navigationbar.gestural.BackGestureTfClassifierProvider;
import com.android.systemui.plugins.BcSmartspaceDataPlugin;
import com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider;
import com.android.wm.shell.transition.Transitions;

@@ -209,4 +210,8 @@ public class SystemUIFactory {
            AssetManager am, String modelName) {
        return new BackGestureTfClassifierProvider();
    }

    public BcSmartspaceDataPlugin getSmartspaceDataProvider() {
        return null;
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.keyguard.clock.ClockModule;
import com.android.keyguard.dagger.KeyguardBouncerComponent;
import com.android.systemui.BootCompleteCache;
import com.android.systemui.BootCompleteCacheImpl;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.appops.dagger.AppOpsModule;
import com.android.systemui.assist.AssistModule;
import com.android.systemui.classifier.FalsingModule;
@@ -159,6 +160,11 @@ public abstract class SystemUIModule {
    @Binds
    abstract SystemClock bindSystemClock(SystemClockImpl systemClock);

    @Provides
    static SystemUIFactory getSystemUIFactory() {
        return SystemUIFactory.getInstance();
    }

    // TODO: This should provided by the WM component
    /** Provides Optional of BubbleManager */
    @SysUISingleton
+33 −36
Original line number Diff line number Diff line
@@ -16,16 +16,15 @@

package com.android.keyguard;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.test.suitebuilder.annotation.SmallTest;
@@ -38,13 +37,13 @@ import android.widget.RelativeLayout;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.keyguard.clock.ClockManager;
import com.android.systemui.R;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.plugins.BcSmartspaceDataPlugin;
import com.android.systemui.plugins.ClockPlugin;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shared.plugins.PluginManager;
import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.phone.NotificationIconAreaController;
@@ -87,12 +86,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
    @Mock
    NotificationIconAreaController mNotificationIconAreaController;
    @Mock
    ContentResolver mContentResolver;
    @Mock
    BroadcastDispatcher mBroadcastDispatcher;
    @Mock
    private PluginManager mPluginManager;
    @Mock
    private FeatureFlags mFeatureFlags;
    @Mock
    private Executor mExecutor;
@@ -106,6 +101,12 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
    BatteryController mBatteryController;
    @Mock
    ConfigurationController mConfigurationController;
    @Mock
    BcSmartspaceDataPlugin mSmartspaceDataProvider;
    @Mock
    SmartspaceView mSmartspaceView;
    @Mock
    SystemUIFactory mSystemUIFactory;

    private KeyguardClockSwitchController mController;
    private View mStatusArea;
@@ -129,27 +130,28 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
        when(mFeatureFlags.isSmartspaceEnabled()).thenReturn(true);
        when(mView.isAttachedToWindow()).thenReturn(true);
        when(mResources.getString(anyInt())).thenReturn("h:mm");
        when(mSystemUIFactory.getSmartspaceDataProvider()).thenReturn(mSmartspaceDataProvider);
        mController = new KeyguardClockSwitchController(
                mView,
                mResources,
                mStatusBarStateController,
                mColorExtractor,
                mClockManager,
                mKeyguardSliceViewController,
                mNotificationIconAreaController,
                mContentResolver,
                mBroadcastDispatcher,
                mPluginManager,
                mFeatureFlags,
                mExecutor,
                mBatteryController,
                mConfigurationController);
                mConfigurationController,
                mSystemUIFactory
        );

        when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE);
        when(mColorExtractor.getColors(anyInt())).thenReturn(mGradientColors);

        mStatusArea = mock(View.class);
        mStatusArea = new View(getContext());
        when(mView.findViewById(R.id.keyguard_status_area)).thenReturn(mStatusArea);
        when(mSmartspaceDataProvider.getView(any())).thenReturn(mSmartspaceView);

    }

@@ -210,43 +212,37 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
    }

    @Test
    public void testSmartspacePluginConnectedRemovesKeyguardStatusArea() {
    public void testSmartspaceEnabledRemovesKeyguardStatusArea() {
        when(mFeatureFlags.isSmartspaceEnabled()).thenReturn(true);
        mController.init();

        BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class);
        TestView view = mock(TestView.class);
        when(plugin.getView(any())).thenReturn(view);

        mController.mPluginListener.onPluginConnected(plugin, mContext);
        verify(mStatusArea).setVisibility(View.GONE);
        assertEquals(View.GONE, mStatusArea.getVisibility());
    }

    @Test
    public void testSmartspacePluginDisconnectedShowsKeyguardStatusArea() {
    public void testSmartspaceEnabledNoDataProviderShowsKeyguardStatusArea() {
        when(mFeatureFlags.isSmartspaceEnabled()).thenReturn(true);
        when(mSystemUIFactory.getSmartspaceDataProvider()).thenReturn(null);
        mController.init();

        BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class);
        TestView view = mock(TestView.class);
        when(plugin.getView(any())).thenReturn(view);

        mController.mPluginListener.onPluginConnected(plugin, mContext);
        mController.mPluginListener.onPluginDisconnected(plugin);
        verify(mStatusArea).setVisibility(View.VISIBLE);
        assertEquals(View.VISIBLE, mStatusArea.getVisibility());
    }

    @Test
    public void testThemeChangeNotifiesSmartspace() {
    public void testSmartspaceDisabledShowsKeyguardStatusArea() {
        when(mFeatureFlags.isSmartspaceEnabled()).thenReturn(false);
        mController.init();

        BcSmartspaceDataPlugin plugin = mock(BcSmartspaceDataPlugin.class);
        TestView view = mock(TestView.class);
        when(plugin.getView(any())).thenReturn(view);
        assertEquals(View.VISIBLE, mStatusArea.getVisibility());
    }

        mController.mPluginListener.onPluginConnected(plugin, mContext);
    @Test
    public void testThemeChangeNotifiesSmartspace() {
        mController.init();
        verify(mSmartspaceView).setPrimaryTextColor(anyInt());

        reset(view);
        mController.getConfigurationListener().onThemeChanged();
        verify(view).setPrimaryTextColor(anyInt());
        verify(mSmartspaceView, times(2)).setPrimaryTextColor(anyInt());
    }

    private void verifyAttachment(VerificationMode times) {
@@ -257,8 +253,9 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
        verify(mView, times).updateColors(mGradientColors);
    }

    private static class TestView extends View implements BcSmartspaceDataPlugin.SmartspaceView {
        TestView(Context context, AttributeSet attrs) {
    private static class SmartspaceView extends View
            implements BcSmartspaceDataPlugin.SmartspaceView {
        SmartspaceView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }