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

Commit c7a66d4f authored by Maryam Dehaini's avatar Maryam Dehaini
Browse files

Reinflate window decor views if font scale has changed

When the font sizing is changed via settings, the view must be
reinflated so that the window decor reflects the changes.

Bug: 329189228
Test: Change font size from settings
Flag: EXEMPT bugfix
Change-Id: I14c46c88073daa46f8ceb8dae3aa10925e0da4b1
parent 10d770d4
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -361,6 +361,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        }
        }


        outResult.mRootView = rootView;
        outResult.mRootView = rootView;
        final boolean fontScaleChanged = mWindowDecorConfig != null
                && mWindowDecorConfig.fontScale != mTaskInfo.configuration.fontScale;
        final int oldDensityDpi = mWindowDecorConfig != null
        final int oldDensityDpi = mWindowDecorConfig != null
                ? mWindowDecorConfig.densityDpi : DENSITY_DPI_UNDEFINED;
                ? mWindowDecorConfig.densityDpi : DENSITY_DPI_UNDEFINED;
        final int oldNightMode =  mWindowDecorConfig != null
        final int oldNightMode =  mWindowDecorConfig != null
@@ -375,7 +377,8 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
                || mDisplay.getDisplayId() != mTaskInfo.displayId
                || mDisplay.getDisplayId() != mTaskInfo.displayId
                || oldLayoutResId != mLayoutResId
                || oldLayoutResId != mLayoutResId
                || oldNightMode != newNightMode
                || oldNightMode != newNightMode
                || mDecorWindowContext == null) {
                || mDecorWindowContext == null
                || fontScaleChanged) {
            releaseViews(wct);
            releaseViews(wct);


            if (!obtainDisplayOrRegisterListener()) {
            if (!obtainDisplayOrRegisterListener()) {
+44 −0
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.inOrder;
@@ -386,6 +387,49 @@ public class WindowDecorationTests extends ShellTestCase {
        verify(mMockWindowDecorViewHost).updateView(same(mMockView), any(), any(), any(), any());
        verify(mMockWindowDecorViewHost).updateView(same(mMockView), any(), any(), any(), any());
    }
    }



    @Test
    public void testReinflateViewsOnFontScaleChange() {
        final Display defaultDisplay = mock(Display.class);
        doReturn(defaultDisplay).when(mMockDisplayController)
                .getDisplay(Display.DEFAULT_DISPLAY);

        final ActivityManager.RunningTaskInfo taskInfo = new TestRunningTaskInfoBuilder()
                .setVisible(true)
                .setDisplayId(Display.DEFAULT_DISPLAY)
                .build();
        final TestWindowDecoration windowDecor = spy(createWindowDecoration(taskInfo));
        windowDecor.relayout(taskInfo, true /* hasGlobalFocus */, Region.obtain());
        clearInvocations(windowDecor);
        final ActivityManager.RunningTaskInfo taskInfo2 = new TestRunningTaskInfoBuilder()
                .setVisible(true)
                .setDisplayId(Display.DEFAULT_DISPLAY)
                .build();
        taskInfo2.configuration.fontScale = taskInfo.configuration.fontScale + 1;
        windowDecor.relayout(taskInfo2, true /* hasGlobalFocus */, Region.obtain());
        // WindowDecoration#releaseViews should be called since the font scale has changed.
        verify(windowDecor).releaseViews(any());
    }

    @Test
    public void testViewNotReinflatedWhenFontScaleNotChanged() {
        final Display defaultDisplay = mock(Display.class);
        doReturn(defaultDisplay).when(mMockDisplayController)
                .getDisplay(Display.DEFAULT_DISPLAY);

        final ActivityManager.RunningTaskInfo taskInfo = new TestRunningTaskInfoBuilder()
                .setVisible(true)
                .setDisplayId(Display.DEFAULT_DISPLAY)
                .build();
        final TestWindowDecoration windowDecor = spy(createWindowDecoration(taskInfo));
        windowDecor.relayout(taskInfo, true /* hasGlobalFocus */, Region.obtain());
        clearInvocations(windowDecor);
        windowDecor.relayout(taskInfo, true /* hasGlobalFocus */, Region.obtain());
        // WindowDecoration#releaseViews should be called since task info (and therefore the
        // fontScale) has not changed.
        verify(windowDecor, never()).releaseViews(any());
    }

    @Test
    @Test
    public void testAddViewHostViewContainer() {
    public void testAddViewHostViewContainer() {
        final Display defaultDisplay = mock(Display.class);
        final Display defaultDisplay = mock(Display.class);