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

Commit e97c22fc authored by Massimo Carli's avatar Massimo Carli
Browse files

Restart Dialog reacts to Light/Dark theme

Fixes: 266262111
Test: Manual. Display a size compat mode restart dialog, change
      from Light mode to Dark or vice versa, and check the dialog
      updates the theme.
      Run `atest CompatUIControllerTest`

Change-Id: Iceb4a1aaaeccbad39e108933aeab557c52201664
parent 98626dc7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -444,6 +444,7 @@ public class TaskInfo {
                && Objects.equals(shouldDockBigOverlays, that.shouldDockBigOverlays)
                && Objects.equals(displayCutoutInsets, that.displayCutoutInsets)
                && getWindowingMode() == that.getWindowingMode()
                && configuration.uiMode == that.configuration.uiMode
                && Objects.equals(taskDescription, that.taskDescription)
                && isFocused == that.isFocused
                && isVisible == that.isVisible
@@ -472,6 +473,7 @@ public class TaskInfo {
                    .equals(that.configuration.windowConfiguration.getBounds()))
                && (!hasCompatUI() || configuration.getLayoutDirection()
                    == that.configuration.getLayoutDirection())
                && (!hasCompatUI() || configuration.uiMode == that.configuration.uiMode)
                && (!hasCompatUI() || isVisible == that.isVisible);
    }

+14 −15
Original line number Diff line number Diff line
@@ -126,14 +126,12 @@ public class CompatUIController implements OnDisplaysChangedListener,
    private final Lazy<Transitions> mTransitionsLazy;
    private final DockStateReader mDockStateReader;
    private final CompatUIConfiguration mCompatUIConfiguration;

    private CompatUICallback mCallback;

    // Only show each hint once automatically in the process life.
    private final CompatUIHintsState mCompatUIHintsState;

    private final CompatUIShellCommandHandler mCompatUIShellCommandHandler;

    private CompatUICallback mCallback;

    // Indicates if the keyguard is currently showing, in which case compat UIs shouldn't
    // be shown.
    private boolean mKeyguardShowing;
@@ -372,10 +370,10 @@ public class CompatUIController implements OnDisplaysChangedListener,
        RestartDialogWindowManager layout =
                mTaskIdToRestartDialogWindowManagerMap.get(taskInfo.taskId);
        if (layout != null) {
            // TODO(b/266262111) Handle theme change when taskListener changes
            if (layout.getTaskListener() != taskListener) {
                mSetOfTaskIdsShowingRestartDialog.remove(taskInfo.taskId);
            }
            if (layout.needsToBeRecreated(taskInfo, taskListener)) {
                mTaskIdToRestartDialogWindowManagerMap.remove(taskInfo.taskId);
                layout.release();
            } else {
                layout.setRequestRestartDialog(
                        mSetOfTaskIdsShowingRestartDialog.contains(taskInfo.taskId));
                // UI already exists, update the UI layout.
@@ -386,6 +384,7 @@ public class CompatUIController implements OnDisplaysChangedListener,
                }
                return;
            }
        }
        // Create a new UI layout.
        final Context context = getOrCreateDisplayContext(taskInfo.displayId);
        if (context == null) {
+2 −2
Original line number Diff line number Diff line
@@ -151,7 +151,6 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
    @Override
    public void setConfiguration(Configuration configuration) {
        super.setConfiguration(configuration);
        // TODO(b/266262111): Investigate loss of theme configuration when switching TaskListener
        mContext = mContext.createConfigurationContext(configuration);
    }

@@ -211,7 +210,8 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
        }

        View layout = getLayout();
        if (layout == null || prevTaskListener != taskListener) {
        if (layout == null || prevTaskListener != taskListener
                || mTaskConfig.uiMode != prevTaskConfig.uiMode) {
            // Layout wasn't created yet or TaskListener changed, recreate the layout for new
            // surface parent.
            release();
+5 −0
Original line number Diff line number Diff line
@@ -155,6 +155,11 @@ class RestartDialogWindowManager extends CompatUIWindowManagerAbstract {
        return super.updateCompatInfo(taskInfo, taskListener, canShow);
    }

    boolean needsToBeRecreated(TaskInfo taskInfo, ShellTaskOrganizer.TaskListener taskListener) {
        return taskInfo.configuration.uiMode != mTaskInfo.configuration.uiMode
                || !getTaskListener().equals(taskListener);
    }

    private void updateDialogMargins() {
        if (mLayout == null) {
            return;
+30 −0
Original line number Diff line number Diff line
@@ -474,6 +474,36 @@ public class CompatUIControllerTest extends ShellTestCase {
        verify(mMockRestartDialogLayout).updateVisibility(true);
    }

    @Test
    public void testRestartLayoutRecreatedIfNeeded() {
        final TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID,
                /* hasSizeCompat= */ true, CAMERA_COMPAT_CONTROL_HIDDEN);
        doReturn(true).when(mMockRestartDialogLayout)
                .needsToBeRecreated(any(TaskInfo.class),
                        any(ShellTaskOrganizer.TaskListener.class));

        mController.onCompatInfoChanged(taskInfo, mMockTaskListener);
        mController.onCompatInfoChanged(taskInfo, mMockTaskListener);

        verify(mMockRestartDialogLayout, times(2))
                .createLayout(anyBoolean());
    }

    @Test
    public void testRestartLayoutNotRecreatedIfNotNeeded() {
        final TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID,
                /* hasSizeCompat= */ true, CAMERA_COMPAT_CONTROL_HIDDEN);
        doReturn(false).when(mMockRestartDialogLayout)
                .needsToBeRecreated(any(TaskInfo.class),
                        any(ShellTaskOrganizer.TaskListener.class));

        mController.onCompatInfoChanged(taskInfo, mMockTaskListener);
        mController.onCompatInfoChanged(taskInfo, mMockTaskListener);

        verify(mMockRestartDialogLayout, times(1))
                .createLayout(anyBoolean());
    }

    private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat,
            @CameraCompatControlState int cameraCompatControlState) {
        RunningTaskInfo taskInfo = new RunningTaskInfo();