Merge "Ignore orientation from invisible non-activity window" into rvc-qpr-dev

This commit is contained in:
Riddle Hsu
2020-10-15 07:20:42 +00:00
committed by Android (Google) Code Review
3 changed files with 49 additions and 1 deletions

View File

@@ -200,6 +200,9 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
Comparator.comparingInt(WindowToken::getWindowLayerFromType); Comparator.comparingInt(WindowToken::getWindowLayerFromType);
private final Predicate<WindowState> mGetOrientingWindow = w -> { private final Predicate<WindowState> mGetOrientingWindow = w -> {
if (!w.isVisible() || !w.mLegacyPolicyVisibilityAfterAnim) {
return false;
}
final WindowManagerPolicy policy = mWmService.mPolicy; final WindowManagerPolicy policy = mWmService.mPolicy;
if (policy.isKeyguardHostWindow(w.mAttrs)) { if (policy.isKeyguardHostWindow(w.mAttrs)) {
if (mWmService.mKeyguardGoingAway) { if (mWmService.mKeyguardGoingAway) {
@@ -235,6 +238,7 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
@Override @Override
int getOrientation(int candidate) { int getOrientation(int candidate) {
mLastOrientationSource = null;
// Find a window requesting orientation. // Find a window requesting orientation.
final WindowState win = getWindow(mGetOrientingWindow); final WindowState win = getWindow(mGetOrientingWindow);

View File

@@ -2555,8 +2555,9 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
pw.print(prefix); pw.println("ContainerAnimator:"); pw.print(prefix); pw.println("ContainerAnimator:");
mSurfaceAnimator.dump(pw, prefix + " "); mSurfaceAnimator.dump(pw, prefix + " ");
} }
if (mLastOrientationSource != null) { if (mLastOrientationSource != null && this == mDisplayContent) {
pw.println(prefix + "mLastOrientationSource=" + mLastOrientationSource); pw.println(prefix + "mLastOrientationSource=" + mLastOrientationSource);
pw.println(prefix + "deepestLastOrientationSource=" + getLastOrientationSource());
} }
} }

View File

@@ -20,6 +20,9 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.server.wm.DisplayArea.Type.ABOVE_TASKS; import static com.android.server.wm.DisplayArea.Type.ABOVE_TASKS;
import static com.android.server.wm.DisplayArea.Type.ANY; import static com.android.server.wm.DisplayArea.Type.ANY;
import static com.android.server.wm.DisplayArea.Type.BELOW_TASKS; import static com.android.server.wm.DisplayArea.Type.BELOW_TASKS;
@@ -29,11 +32,15 @@ import static com.android.server.wm.DisplayArea.Type.typeOf;
import static com.android.server.wm.testing.Assert.assertThrows; import static com.android.server.wm.testing.Assert.assertThrows;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import android.content.pm.ActivityInfo;
import android.os.Binder; import android.os.Binder;
import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.Presubmit;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.view.View;
import android.view.WindowManager;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -97,6 +104,42 @@ public class DisplayAreaTest {
assertThrows(IllegalStateException.class, () -> checkChild(BELOW_TASKS, ANY)); assertThrows(IllegalStateException.class, () -> checkChild(BELOW_TASKS, ANY));
} }
@Test
public void testGetOrientation() {
final DisplayArea.Tokens area = new DisplayArea.Tokens(mWmsRule.getWindowManagerService(),
ABOVE_TASKS, "test");
final WindowToken token = createWindowToken(TYPE_APPLICATION_OVERLAY);
spyOn(token);
doReturn(mock(DisplayContent.class)).when(token).getDisplayContent();
doNothing().when(token).setParent(any());
final WindowState win = createWindowState(token);
spyOn(win);
doNothing().when(win).setParent(any());
win.mAttrs.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
token.addChild(win, 0);
area.addChild(token);
doReturn(true).when(win).isVisible();
assertEquals("Visible window can request orientation",
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
area.getOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR));
doReturn(false).when(win).isVisible();
assertEquals("Invisible window cannot request orientation",
ActivityInfo.SCREEN_ORIENTATION_NOSENSOR,
area.getOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR));
}
private WindowState createWindowState(WindowToken token) {
return new WindowState(mWmsRule.getWindowManagerService(), mock(Session.class),
new TestIWindow(), token, null /* parentWindow */, 0 /* appOp */, 0 /* seq*/,
new WindowManager.LayoutParams(), View.VISIBLE, 0 /* ownerId */, 0 /* showUserId */,
false /* ownerCanAddInternalSystemWindow */, null);
}
private WindowToken createWindowToken(int type) { private WindowToken createWindowToken(int type) {
return new WindowToken(mWmsRule.getWindowManagerService(), new Binder(), return new WindowToken(mWmsRule.getWindowManagerService(), new Binder(),
type, false /* persist */, null /* displayContent */, type, false /* persist */, null /* displayContent */,