From 954bb63899e27f1cf85f14896f0597f58661f10e Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Wed, 27 Jan 2021 14:03:51 -0800 Subject: [PATCH] Fix launcher flicker when unlocking on seascape. Test: manual Fixes: 160544577 Launcher flickers if it is locked on portrait, then unlocked on seascape. DisplayController.Info was consistenly being updated late causing launcher to unlock in lanscape then switching to seascape with enough frames in-between for the user to notice. Updated DisplayController to properly update its rotation info and updated DeviceProfile to force an info update when checking if the device is in seascape orientation. demo: https://drive.google.com/file/d/1JBCvK3brLwOSTC4k56GSxeYozl5x0k7X/view?usp=sharing Change-Id: Idce139f0e16cb686684c0d3a460c4ec9e5ae466a --- src/com/android/launcher3/DeviceProfile.java | 5 ++-- .../launcher3/util/DisplayController.java | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 12ce9f3448..f681d75eef 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -607,8 +607,9 @@ public class DeviceProfile { */ public boolean updateIsSeascape(Context context) { if (isVerticalBarLayout()) { - boolean isSeascape = DisplayController.getDefaultDisplay(context).getInfo().rotation - == Surface.ROTATION_270; + // Check an up-to-date info. + boolean isSeascape = DisplayController.getDefaultDisplay(context) + .createInfoForContext(context).rotation == Surface.ROTATION_270; if (mIsSeascape != isSeascape) { mIsSeascape = isSeascape; return true; diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index 355c949325..3b7bcc285a 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -31,6 +31,8 @@ import android.view.Display; import androidx.annotation.VisibleForTesting; +import com.android.launcher3.Utilities; + import java.util.ArrayList; /** @@ -179,23 +181,35 @@ public class DisplayController implements DisplayListener { return mInfo; } + /** Creates and up-to-date DisplayController.Info for the given context. */ + public Info createInfoForContext(Context context) { + Display display = Utilities.ATLEAST_R + ? context.getDisplay() + : context + .getSystemService(DisplayManager.class) + .getDisplay(mId); + return display == null + ? new Info(context) + : new Info(context, display); + } + protected void handleOnChange() { Info oldInfo = mInfo; - Info info = new Info(mDisplayContext); + Info newInfo = createInfoForContext(mDisplayContext); int change = 0; - if (info.hasDifferentSize(oldInfo)) { + if (newInfo.hasDifferentSize(oldInfo)) { change |= CHANGE_SIZE; } - if (oldInfo.rotation != info.rotation) { + if (newInfo.rotation != oldInfo.rotation) { change |= CHANGE_ROTATION; } - if (info.singleFrameMs != oldInfo.singleFrameMs) { + if (newInfo.singleFrameMs != oldInfo.singleFrameMs) { change |= CHANGE_FRAME_DELAY; } if (change != 0) { - mInfo = info; + mInfo = newInfo; final int flags = change; MAIN_EXECUTOR.execute(() -> notifyChange(flags)); }