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
This commit is contained in:
Massimo Carli
2023-02-21 16:41:34 +00:00
parent 98626dc72d
commit e97c22fcfd
5 changed files with 53 additions and 17 deletions

View File

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

View File

@@ -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,19 +370,20 @@ 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);
}
layout.setRequestRestartDialog(
mSetOfTaskIdsShowingRestartDialog.contains(taskInfo.taskId));
// UI already exists, update the UI layout.
if (!layout.updateCompatInfo(taskInfo, taskListener,
showOnDisplay(layout.getDisplayId()))) {
// The layout is no longer eligible to be shown, remove from active layouts.
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.
if (!layout.updateCompatInfo(taskInfo, taskListener,
showOnDisplay(layout.getDisplayId()))) {
// The layout is no longer eligible to be shown, remove from active layouts.
mTaskIdToRestartDialogWindowManagerMap.remove(taskInfo.taskId);
}
return;
}
return;
}
// Create a new UI layout.
final Context context = getOrCreateDisplayContext(taskInfo.displayId);

View File

@@ -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();

View File

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

View File

@@ -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();