Merge "Restore config of associated window when clearing fixed rotation" into rvc-dev am: 766aa3a107

Change-Id: I929ceb71bdc6f746553749a2e173520a52495d02
This commit is contained in:
TreeHugger Robot
2020-04-10 16:18:16 +00:00
committed by Automerger Merge Worker
2 changed files with 43 additions and 3 deletions

View File

@@ -554,13 +554,12 @@ class WindowToken extends WindowContainer<WindowState> {
// cleared and the configuration is restored from parent. // cleared and the configuration is restored from parent.
if (!changed) { if (!changed) {
clearFixedRotationTransform(null /* applyDisplayRotation */); clearFixedRotationTransform(null /* applyDisplayRotation */);
onConfigurationChanged(getParent().getConfiguration());
} }
} }
/** /**
* Clears the transform and apply display rotation if the action is given. The caller needs to * Clears the transform and apply display rotation if the action is given. If the display will
* refresh the configuration of this container after this method call. * not rotate, the transformed containers are restored to their original states.
*/ */
void clearFixedRotationTransform(Runnable applyDisplayRotation) { void clearFixedRotationTransform(Runnable applyDisplayRotation) {
final FixedRotationTransformState state = mFixedRotationTransformState; final FixedRotationTransformState state = mFixedRotationTransformState;
@@ -574,6 +573,12 @@ class WindowToken extends WindowContainer<WindowState> {
state.mIsTransforming = false; state.mIsTransforming = false;
if (applyDisplayRotation != null) { if (applyDisplayRotation != null) {
applyDisplayRotation.run(); applyDisplayRotation.run();
} else {
// The display will not rotate to the rotation of this container, let's cancel them.
for (int i = state.mAssociatedTokens.size() - 1; i >= 0; i--) {
state.mAssociatedTokens.get(i).cancelFixedRotationTransform();
}
cancelFixedRotationTransform();
} }
// The state is cleared at the end, because it is used to indicate that other windows can // The state is cleared at the end, because it is used to indicate that other windows can
// use seamless rotation when applying rotation to display. // use seamless rotation when applying rotation to display.
@@ -583,6 +588,16 @@ class WindowToken extends WindowContainer<WindowState> {
mFixedRotationTransformState = null; mFixedRotationTransformState = null;
} }
/** Restores the changes that applies to this container. */
private void cancelFixedRotationTransform() {
final WindowContainer<?> parent = getParent();
if (parent == null) {
// The window may be detached or detaching.
return;
}
onConfigurationChanged(parent.getConfiguration());
}
@Override @Override
void resolveOverrideConfiguration(Configuration newParentConfig) { void resolveOverrideConfiguration(Configuration newParentConfig) {
super.resolveOverrideConfiguration(newParentConfig); super.resolveOverrideConfiguration(newParentConfig);

View File

@@ -29,6 +29,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import android.content.res.Configuration;
import android.os.IBinder; import android.os.IBinder;
import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.Presubmit;
@@ -134,6 +135,30 @@ public class WindowTokenTests extends WindowTestsBase {
assertEquals(0, token.getWindowsCount()); assertEquals(0, token.getWindowsCount());
} }
@Test
public void testClearFixedRotationTransform() {
final WindowToken appToken = mAppWindow.mToken;
final WindowToken wallpaperToken = mWallpaperWindow.mToken;
final Configuration config = new Configuration(mDisplayContent.getConfiguration());
final int originalRotation = config.windowConfiguration.getRotation();
final int targetRotation = (originalRotation + 1) % 4;
config.windowConfiguration.setRotation(targetRotation);
appToken.applyFixedRotationTransform(mDisplayInfo, mDisplayContent.mDisplayFrames, config);
wallpaperToken.linkFixedRotationTransform(appToken);
// The window tokens should apply the rotation by the transformation.
assertEquals(targetRotation, appToken.getWindowConfiguration().getRotation());
assertEquals(targetRotation, wallpaperToken.getWindowConfiguration().getRotation());
// The display doesn't rotate, the transformation will be canceled.
mAppWindow.mToken.clearFixedRotationTransform(null /* applyDisplayRotation */);
// The window tokens should restore to the original rotation.
assertEquals(originalRotation, appToken.getWindowConfiguration().getRotation());
assertEquals(originalRotation, wallpaperToken.getWindowConfiguration().getRotation());
}
/** /**
* Test that {@link WindowToken} constructor parameters is set with expectation. * Test that {@link WindowToken} constructor parameters is set with expectation.
*/ */