Merge "Restart Dialog reacts to Light/Dark theme" into tm-qpr-dev

This commit is contained in:
Massimo Carli
2023-02-28 09:27:15 +00:00
committed by Android (Google) Code Review
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(shouldDockBigOverlays, that.shouldDockBigOverlays)
&& Objects.equals(displayCutoutInsets, that.displayCutoutInsets) && Objects.equals(displayCutoutInsets, that.displayCutoutInsets)
&& getWindowingMode() == that.getWindowingMode() && getWindowingMode() == that.getWindowingMode()
&& configuration.uiMode == that.configuration.uiMode
&& Objects.equals(taskDescription, that.taskDescription) && Objects.equals(taskDescription, that.taskDescription)
&& isFocused == that.isFocused && isFocused == that.isFocused
&& isVisible == that.isVisible && isVisible == that.isVisible
@@ -472,6 +473,7 @@ public class TaskInfo {
.equals(that.configuration.windowConfiguration.getBounds())) .equals(that.configuration.windowConfiguration.getBounds()))
&& (!hasCompatUI() || configuration.getLayoutDirection() && (!hasCompatUI() || configuration.getLayoutDirection()
== that.configuration.getLayoutDirection()) == that.configuration.getLayoutDirection())
&& (!hasCompatUI() || configuration.uiMode == that.configuration.uiMode)
&& (!hasCompatUI() || isVisible == that.isVisible); && (!hasCompatUI() || isVisible == that.isVisible);
} }

View File

@@ -126,14 +126,12 @@ public class CompatUIController implements OnDisplaysChangedListener,
private final Lazy<Transitions> mTransitionsLazy; private final Lazy<Transitions> mTransitionsLazy;
private final DockStateReader mDockStateReader; private final DockStateReader mDockStateReader;
private final CompatUIConfiguration mCompatUIConfiguration; private final CompatUIConfiguration mCompatUIConfiguration;
private CompatUICallback mCallback;
// Only show each hint once automatically in the process life. // Only show each hint once automatically in the process life.
private final CompatUIHintsState mCompatUIHintsState; private final CompatUIHintsState mCompatUIHintsState;
private final CompatUIShellCommandHandler mCompatUIShellCommandHandler; private final CompatUIShellCommandHandler mCompatUIShellCommandHandler;
private CompatUICallback mCallback;
// Indicates if the keyguard is currently showing, in which case compat UIs shouldn't // Indicates if the keyguard is currently showing, in which case compat UIs shouldn't
// be shown. // be shown.
private boolean mKeyguardShowing; private boolean mKeyguardShowing;
@@ -372,10 +370,10 @@ public class CompatUIController implements OnDisplaysChangedListener,
RestartDialogWindowManager layout = RestartDialogWindowManager layout =
mTaskIdToRestartDialogWindowManagerMap.get(taskInfo.taskId); mTaskIdToRestartDialogWindowManagerMap.get(taskInfo.taskId);
if (layout != null) { if (layout != null) {
// TODO(b/266262111) Handle theme change when taskListener changes if (layout.needsToBeRecreated(taskInfo, taskListener)) {
if (layout.getTaskListener() != taskListener) { mTaskIdToRestartDialogWindowManagerMap.remove(taskInfo.taskId);
mSetOfTaskIdsShowingRestartDialog.remove(taskInfo.taskId); layout.release();
} } else {
layout.setRequestRestartDialog( layout.setRequestRestartDialog(
mSetOfTaskIdsShowingRestartDialog.contains(taskInfo.taskId)); mSetOfTaskIdsShowingRestartDialog.contains(taskInfo.taskId));
// UI already exists, update the UI layout. // UI already exists, update the UI layout.
@@ -386,6 +384,7 @@ public class CompatUIController implements OnDisplaysChangedListener,
} }
return; return;
} }
}
// Create a new UI layout. // Create a new UI layout.
final Context context = getOrCreateDisplayContext(taskInfo.displayId); final Context context = getOrCreateDisplayContext(taskInfo.displayId);
if (context == null) { if (context == null) {

View File

@@ -151,7 +151,6 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
@Override @Override
public void setConfiguration(Configuration configuration) { public void setConfiguration(Configuration configuration) {
super.setConfiguration(configuration); super.setConfiguration(configuration);
// TODO(b/266262111): Investigate loss of theme configuration when switching TaskListener
mContext = mContext.createConfigurationContext(configuration); mContext = mContext.createConfigurationContext(configuration);
} }
@@ -211,7 +210,8 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
} }
View layout = getLayout(); 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 // Layout wasn't created yet or TaskListener changed, recreate the layout for new
// surface parent. // surface parent.
release(); release();

View File

@@ -155,6 +155,11 @@ class RestartDialogWindowManager extends CompatUIWindowManagerAbstract {
return super.updateCompatInfo(taskInfo, taskListener, canShow); 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() { private void updateDialogMargins() {
if (mLayout == null) { if (mLayout == null) {
return; return;

View File

@@ -474,6 +474,36 @@ public class CompatUIControllerTest extends ShellTestCase {
verify(mMockRestartDialogLayout).updateVisibility(true); 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, private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat,
@CameraCompatControlState int cameraCompatControlState) { @CameraCompatControlState int cameraCompatControlState) {
RunningTaskInfo taskInfo = new RunningTaskInfo(); RunningTaskInfo taskInfo = new RunningTaskInfo();