Fix incorrect border after folding/unfolding the device

The display size is changed after folding/unfolding the device.
We need to refetch the size to draw the correct boundary on
the screen. Display#realSize is not updated in time, so we get the
bounds directly from windowConfiguration.

Bug: 190007130
Test: manual test
Change-Id: I942e333f62510650eec8b49d77ccf46a85a7457e
This commit is contained in:
ryanlwlin
2021-06-10 16:57:44 +08:00
parent b6bfa26864
commit 827247ab2a
5 changed files with 41 additions and 29 deletions

View File

@@ -283,7 +283,7 @@ public class FullScreenMagnificationController {
}
@Override
public void onRotationChanged(int rotation) {
public void onDisplaySizeChanged() {
// Treat as context change and reset
final Message m = PooledLambda.obtainMessage(
FullScreenMagnificationController::resetIfNeeded,

View File

@@ -326,7 +326,8 @@ final class AccessibilityController {
}
}
void onRotationChanged(DisplayContent displayContent) {
void onDisplaySizeChanged(DisplayContent displayContent) {
if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK
| FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK)) {
mAccessibilityTracing.logTrace(TAG + ".onRotationChanged",
@@ -336,7 +337,7 @@ final class AccessibilityController {
final int displayId = displayContent.getDisplayId();
final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
if (displayMagnifier != null) {
displayMagnifier.onRotationChanged(displayContent);
displayMagnifier.onDisplaySizeChanged(displayContent);
}
final WindowsForAccessibilityObserver windowsForA11yObserver =
mWindowsForAccessibilityObserver.get(displayId);
@@ -608,7 +609,7 @@ final class AccessibilityController {
private static final String LOG_TAG = TAG_WITH_CLASS_NAME ? "DisplayMagnifier" : TAG_WM;
private static final boolean DEBUG_WINDOW_TRANSITIONS = false;
private static final boolean DEBUG_ROTATION = false;
private static final boolean DEBUG_DISPLAY_SIZE = false;
private static final boolean DEBUG_LAYERS = false;
private static final boolean DEBUG_RECTANGLE_REQUESTED = false;
private static final boolean DEBUG_VIEWPORT_WINDOW = false;
@@ -725,18 +726,18 @@ final class AccessibilityController {
mService.scheduleAnimationLocked();
}
void onRotationChanged(DisplayContent displayContent) {
void onDisplaySizeChanged(DisplayContent displayContent) {
if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
mAccessibilityTracing.logTrace(LOG_TAG + ".onRotationChanged",
mAccessibilityTracing.logTrace(LOG_TAG + ".onDisplaySizeChanged",
FLAGS_MAGNIFICATION_CALLBACK, "displayContent={" + displayContent + "}");
}
if (DEBUG_ROTATION) {
if (DEBUG_DISPLAY_SIZE) {
final int rotation = displayContent.getRotation();
Slog.i(LOG_TAG, "Rotation: " + Surface.rotationToString(rotation)
+ " displayId: " + displayContent.getDisplayId());
}
mMagnifedViewport.onRotationChanged();
mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_ROTATION_CHANGED);
mMagnifedViewport.onDisplaySizeChanged();
mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_DISPLAY_SIZE_CHANGED);
}
void onAppWindowTransition(int displayId, int transition) {
@@ -923,7 +924,8 @@ final class AccessibilityController {
if (mDisplayContext.getResources().getConfiguration().isScreenRound()) {
mCircularPath = new Path();
mDisplay.getRealSize(mScreenSize);
getDisplaySizeLocked(mScreenSize);
final int centerXY = mScreenSize.x / 2;
mCircularPath.addCircle(centerXY, centerXY, centerXY, Path.Direction.CW);
} else {
@@ -953,7 +955,7 @@ final class AccessibilityController {
}
void recomputeBounds() {
mDisplay.getRealSize(mScreenSize);
getDisplaySizeLocked(mScreenSize);
final int screenWidth = mScreenSize.x;
final int screenHeight = mScreenSize.y;
@@ -1088,9 +1090,10 @@ final class AccessibilityController {
|| windowType == TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY;
}
void onRotationChanged() {
void onDisplaySizeChanged() {
// If we are showing the magnification border, hide it immediately so
// the user does not see strange artifacts during rotation. The screenshot
// the user does not see strange artifacts during display size changed caused by
// rotation or folding/unfolding the device. In the rotation case, the screenshot
// used for rotation already has the border. After the rotation is complete
// we will show the border.
if (isMagnifying() || isForceShowingMagnifiableBounds()) {
@@ -1148,6 +1151,12 @@ final class AccessibilityController {
}, false /* traverseTopToBottom */ );
}
private void getDisplaySizeLocked(Point outSize) {
final Rect bounds =
mDisplayContent.getConfiguration().windowConfiguration.getBounds();
outSize.set(bounds.width(), bounds.height());
}
void dump(PrintWriter pw, String prefix) {
mWindow.dump(pw, prefix);
}
@@ -1262,7 +1271,7 @@ final class AccessibilityController {
void updateSize() {
synchronized (mService.mGlobalLock) {
mDisplay.getRealSize(mScreenSize);
getDisplaySizeLocked(mScreenSize);
mBlastBufferQueue.update(mSurfaceControl, mScreenSize.x, mScreenSize.y,
PixelFormat.RGBA_8888);
invalidate(mDirtyRect);
@@ -1401,7 +1410,7 @@ final class AccessibilityController {
public static final int MESSAGE_NOTIFY_MAGNIFICATION_REGION_CHANGED = 1;
public static final int MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED = 2;
public static final int MESSAGE_NOTIFY_USER_CONTEXT_CHANGED = 3;
public static final int MESSAGE_NOTIFY_ROTATION_CHANGED = 4;
public static final int MESSAGE_NOTIFY_DISPLAY_SIZE_CHANGED = 4;
public static final int MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED = 5;
public static final int MESSAGE_NOTIFY_IME_WINDOW_VISIBILITY_CHANGED = 6;
@@ -1433,9 +1442,8 @@ final class AccessibilityController {
mCallbacks.onUserContextChanged();
} break;
case MESSAGE_NOTIFY_ROTATION_CHANGED: {
final int rotation = message.arg1;
mCallbacks.onRotationChanged(rotation);
case MESSAGE_NOTIFY_DISPLAY_SIZE_CHANGED: {
mCallbacks.onDisplaySizeChanged();
} break;
case MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED : {

View File

@@ -1897,10 +1897,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
}
}
}
if (mWmService.mAccessibilityController != null) {
mWmService.mAccessibilityController.onRotationChanged(this);
}
}
void configureDisplayPolicy() {
@@ -5572,6 +5568,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
ActivityTaskManagerService.LAYOUT_REASON_CONFIG_CHANGED);
}
@Override
void onResize() {
super.onResize();
if (mWmService.mAccessibilityController != null) {
mWmService.mAccessibilityController.onDisplaySizeChanged(this);
}
}
/**
* If the launching rotated activity ({@link #mFixedRotationLaunchingApp}) is null, it simply
* applies the rotation to display. Otherwise because the activity has shown as rotated, the

View File

@@ -160,11 +160,11 @@ public abstract class WindowManagerInternal {
void onRectangleOnScreenRequested(int left, int top, int right, int bottom);
/**
* Notifies that the rotation changed.
* Notifies that the display size is changed when rotation or the
* logical display is changed.
*
* @param rotation The current rotation.
*/
void onRotationChanged(int rotation);
void onDisplaySizeChanged();
/**
* Notifies that the context of the user changed. For example, an application

View File

@@ -777,20 +777,20 @@ public class FullScreenMagnificationControllerTest {
}
@Test
public void testRotation_resetsMagnification() {
public void testDisplaySizeChanged_resetsMagnification() {
for (int i = 0; i < DISPLAY_COUNT; i++) {
rotation_resetsMagnification(i);
changeDisplaySize_resetsMagnification(i);
resetMockWindowManager();
}
}
private void rotation_resetsMagnification(int displayId) {
private void changeDisplaySize_resetsMagnification(int displayId) {
register(displayId);
MagnificationCallbacks callbacks = getMagnificationCallbacks(displayId);
zoomIn2xToMiddle(displayId);
mMessageCapturingHandler.sendAllMessages();
assertTrue(mFullScreenMagnificationController.isMagnifying(displayId));
callbacks.onRotationChanged(0);
callbacks.onDisplaySizeChanged();
mMessageCapturingHandler.sendAllMessages();
assertFalse(mFullScreenMagnificationController.isMagnifying(displayId));
}