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

Commit 2bde1bdc authored by Xiaowen Lei's avatar Xiaowen Lei Committed by Android (Google) Code Review
Browse files

Merge "Add date(+weather)(+alarm+dnd) view to lockscreen if decoupling enabled." into tm-qpr-dev

parents ad6b846c 44d7e571
Loading
Loading
Loading
Loading
+26 −5
Original line number Diff line number Diff line
@@ -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;

@@ -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;
            }

@@ -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);
@@ -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) {
+4 −0
Original line number Diff line number Diff line
@@ -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();
+5 −0
Original line number Diff line number Diff line
@@ -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.
         */
+28 −2
Original line number Diff line number Diff line
@@ -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
@@ -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>,
@@ -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)
@@ -222,7 +226,7 @@ constructor(
        execution.assertIsMainThread()

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

    private fun updateBypassEnabled() {
@@ -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.
     */
@@ -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
        }
@@ -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) }

@@ -383,6 +407,8 @@ constructor(
        bypassController.unregisterOnBypassStateChangedListener(bypassStateChangedListener)
        session = null

        datePlugin?.registerSmartspaceEventNotifier(null)

        weatherPlugin?.registerSmartspaceEventNotifier(null)
        weatherPlugin?.onTargetsAvailable(emptyList())

+21 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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(
@@ -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