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

Commit 28baed28 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin Committed by Ale Nijamkin
Browse files

[flexiglass] Fix multiple smartspace view issue.

There is an issue where, every time we return to the Lockscreen scene,
an additional smartpsace view is added to the smartspace area.

This CL fixes that.

The fix moves the responsibility of removing the views that were added
by KeyguardClockSwitchController into that same class and utilizes a
view tag to identify which children of the smartspace area should be
removed.

Before this, the responsibility for removing the views was in
LockscreenSmartspaceController which was not the same class that was
adding the views (KeyguardClockSwitchController adds the views to the
smartspace area) and has a bug where the smartspace views being tracked
get removed when they're detached, which happens before the old
removeViewsFromParent(...) was invoked.

Bug: 280879610
Test: unit tests pass
Test: manually verified that leaving and returning to the Lockscreen
scene correctly shows only one data-time smartspace view.
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:eedb2b14f54d58fb82f94afa84c5f894e5ea99a6)
Merged-In: I94f16972f3be402cf1a581d6fd2d355bbea5c85e
Change-Id: I94f16972f3be402cf1a581d6fd2d355bbea5c85e
parent af3eb24f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -222,4 +222,10 @@

    <!-- Communal mode -->
    <item type="id" name="communal_widget_wrapper" />

    <!--
    Used to tag views programmatically added to the smartspace area so they can be more easily
    removed later.
    -->
    <item type="id" name="tag_smartspace_view" />
</resources>
+11 −2
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
            int viewIndex = mStatusArea.indexOfChild(ksv);
            ksv.setVisibility(View.GONE);

            mSmartspaceController.removeViewsFromParent(mStatusArea);
            removeViewsFromStatusArea();
            addSmartspaceView();
            // TODO(b/261757708): add content observer for the Settings toggle and add/remove
            //  weather according to the Settings.
@@ -325,7 +325,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS

    void onLocaleListChanged() {
        if (mSmartspaceController.isEnabled()) {
            mSmartspaceController.removeViewsFromParent(mStatusArea);
            removeViewsFromStatusArea();
            addSmartspaceView();
            if (mSmartspaceController.isDateWeatherDecoupled()) {
                mDateWeatherView.removeView(mWeatherView);
@@ -620,4 +620,13 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        return ((mCurrentClockSize == LARGE) ? clock.getLargeClock() : clock.getSmallClock())
                .getConfig().getHasCustomWeatherDataDisplay();
    }

    private void removeViewsFromStatusArea() {
        for  (int i = mStatusArea.getChildCount() - 1; i >= 0; i--) {
            final View childView = mStatusArea.getChildAt(i);
            if (childView.getTag(R.id.tag_smartspace_view) != null) {
                mStatusArea.removeViewAt(i);
            }
        }
    }
}
+5 −7
Original line number Diff line number Diff line
@@ -388,7 +388,10 @@ constructor(
        })
        ssView.setFalsingManager(falsingManager)
        ssView.setKeyguardBypassEnabled(bypassController.bypassEnabled)
        return (ssView as View).apply { addOnAttachStateChangeListener(stateChangeListener) }
        return (ssView as View).apply {
            setTag(R.id.tag_smartspace_view, Any())
            addOnAttachStateChangeListener(stateChangeListener)
        }
    }

    private fun connectSession() {
@@ -451,12 +454,6 @@ constructor(
        session?.requestSmartspaceUpdate()
    }

    fun removeViewsFromParent(viewGroup: ViewGroup) {
        smartspaceViews.toList().forEach {
            viewGroup.removeView(it as View)
        }
    }

    /**
     * Disconnects the smartspace view from the smartspace service and cleans up any resources.
     */
@@ -597,3 +594,4 @@ constructor(
        }
    }
}
+4 −7
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static com.android.systemui.flags.Flags.LOCKSCREEN_WALLPAPER_DREAM_ENABLE

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -136,6 +135,10 @@ public class KeyguardClockSwitchControllerBaseTest extends SysuiTestCase {
    public void setup() {
        MockitoAnnotations.initMocks(this);

        mFakeDateView.setTag(R.id.tag_smartspace_view, new Object());
        mFakeWeatherView.setTag(R.id.tag_smartspace_view, new Object());
        mFakeSmartspaceView.setTag(R.id.tag_smartspace_view, new Object());

        when(mView.findViewById(R.id.left_aligned_notification_icon_container))
                .thenReturn(mNotificationIcons);
        when(mNotificationIcons.getLayoutParams()).thenReturn(
@@ -158,12 +161,6 @@ public class KeyguardClockSwitchControllerBaseTest extends SysuiTestCase {
        when(mSmartspaceController.buildAndConnectDateView(any())).thenReturn(mFakeDateView);
        when(mSmartspaceController.buildAndConnectWeatherView(any())).thenReturn(mFakeWeatherView);
        when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mFakeSmartspaceView);
        doAnswer(invocation -> {
            removeView(mFakeDateView);
            removeView(mFakeWeatherView);
            removeView(mFakeSmartspaceView);
            return null;
        }).when(mSmartspaceController).removeViewsFromParent(any());
        mExecutor = new FakeExecutor(new FakeSystemClock());
        mFakeFeatureFlags = new FakeFeatureFlags();
        mFakeFeatureFlags.set(FACE_AUTH_REFACTOR, false);