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

Commit 7f07319d authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Fix shade header Clock sizing on display move

When used from compose there was no other class propagating the configruation change to the clock. However, the clock receives the configuration itself though the standard View#onConfigurationChanged, so there is no point in propagating it from elsewhere, as it might only result it the wrong signal, and is more error prone.

Also, there was no point for the Clock to implement ConfigurationListener, as it was never registered with any ConfigurationController.

The onLocaleListChanged call was also misleading, as there was no implementation of it in Clock.java.

Bug: 362719719
Bug: 417959771
Test: ShadeHeaderControllerTest + expand/collapse dual shade + move between displays. After the fix clock dimensions are always correct.
Flag: com.android.systemui.shade_window_goes_around
Change-Id: If8ea2a83f4c707a8e8dc17a27862c1301d352197
parent e9c31bae
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -343,8 +343,11 @@ constructor(
                lastInsets?.let { updateConstraintsForInsets(header, it) }
                updateResources()
                updateCarrierGroupPadding()
                if (!ShadeWindowGoesAround.isEnabled) {
                    // the clock handles the config change itself.
                    clock.onDensityOrFontScaleChanged()
                }
            }

            override fun onThemeChanged() {
                updateColors()
@@ -353,10 +356,6 @@ constructor(
            override fun onUiModeChanged() {
                updateColors()
            }

            override fun onLocaleListChanged() {
                clock.onLocaleListChanged()
            }
        }

    private val nextAlarmCallback =
+8 −2
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ private constructor(
    private val configurationListener =
        object : ConfigurationController.ConfigurationListener {
            override fun onDensityOrFontScaleChanged() {
                ShadeWindowGoesAround.assertInLegacyMode()
                clock.onDensityOrFontScaleChanged()
            }
        }
@@ -154,8 +155,11 @@ private constructor(
        }

        progressProvider?.setReadyToHandleTransition(true)
        if (!ShadeWindowGoesAround.isEnabled) {
            // the clock handles the config change itself.
            configurationController.addCallback(configurationListener)
        }
    }

    private fun addCursorSupportToIconContainers() {
        endSideContainer = mView.requireViewById(R.id.system_icons)
@@ -191,8 +195,10 @@ private constructor(
        startSideContainer.setOnHoverListener(null)
        endSideContainer.setOnHoverListener(null)
        progressProvider?.setReadyToHandleTransition(false)
        if (!ShadeWindowGoesAround.isEnabled) {
            configurationController.removeCallback(configurationListener)
        }
    }

    init {
        // These should likely be done in `onInit`, not `init`.
+29 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.icu.lang.UCharacter;
@@ -52,10 +53,10 @@ import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.res.R;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.shade.shared.flag.ShadeWindowGoesAround;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.core.StatusBarRootModernization;
import com.android.systemui.statusbar.phone.ui.StatusBarIconController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;

@@ -72,7 +73,7 @@ public class Clock extends TextView implements
        DemoModeCommandReceiver,
        Tunable,
        CommandQueue.Callbacks,
        DarkReceiver, ConfigurationListener {
        DarkReceiver {

    public static final String CLOCK_SECONDS = "clock_seconds";
    private static final String CLOCK_SUPER_PARCELABLE = "clock_super_parcelable";
@@ -97,6 +98,7 @@ public class Clock extends TextView implements
    private SimpleDateFormat mContentDescriptionFormat;
    private Locale mLocale;
    private DateTimePatternGenerator mDateTimePatternGenerator;
    private Configuration oldConfig = new Configuration();

    private static final int AM_PM_STYLE_NORMAL  = 0;
    private static final int AM_PM_STYLE_SMALL   = 1;
@@ -367,8 +369,10 @@ public class Clock extends TextView implements
        setTextColor(Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColor));
    }

    @Override
    public void onDensityOrFontScaleChanged() {
        ShadeWindowGoesAround.assertInLegacyMode();
        // Note that this class is not being registered as configuration listener when used
        // from compose. It will instead receive a normal "View#onConfigurationChanged".
        reloadDimens();
    }

@@ -386,6 +390,23 @@ public class Clock extends TextView implements
                0);
    }


    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (ShadeWindowGoesAround.isEnabled()) {
            if (densityOrFontScaleChanged(oldConfig, newConfig)) {
                reloadDimens();
            }
            oldConfig = newConfig;
        }
    }

    private boolean densityOrFontScaleChanged(Configuration oldConfig, Configuration newConfig) {
        return (oldConfig.densityDpi != newConfig.densityDpi)
                || oldConfig.fontScale != newConfig.fontScale;
    }

    private void updateShowSeconds() {
        if (mShowSeconds) {
            // Wait until we have a display to start trying to show seconds.
+0 −7
Original line number Diff line number Diff line
@@ -327,13 +327,6 @@ class ShadeHeaderControllerTest : SysuiTestCase() {
        verify(date).setTextAppearance(R.style.TextAppearance_QS_Status)
    }

    @Test
    fun updateLocale_clockUpdates() {
        configurationController.notifyLocaleChanged()

        verify(clock).onLocaleListChanged()
    }

    @Test
    fun animateOutOnStartCustomizing() {
        val animator = mock(ViewPropertyAnimator::class.java, Answers.RETURNS_SELF)
+12 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.view.View
import android.view.ViewTreeObserver
import android.widget.FrameLayout
import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestableContext
import com.android.systemui.battery.BatteryMeterView
@@ -178,6 +179,7 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
    }

    @Test
    @DisableFlags(Flags.FLAG_SHADE_WINDOW_GOES_AROUND)
    fun onViewAttachedAndDrawn_addStatusBarConfigurationControllerCallback() {
        val view = createViewMock(view)

@@ -186,6 +188,16 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
        verify(mStatusBarConfigurationController).addCallback(any())
    }

    @Test
    @EnableFlags(Flags.FLAG_SHADE_WINDOW_GOES_AROUND)
    fun onViewAttachedAndDrawn_doesNotAddStatusBarConfigurationControllerCallback() {
        val view = createViewMock(view)

        controller = createAndInitController(view)

        verify(mStatusBarConfigurationController, never()).addCallback(any())
    }

    @Test
    fun onViewAttachedAndDrawn_darkReceiversRegistered() {
        val view = createViewMock(view)