From 0ae61c8d2979569c5ca74593b8e4e48e825f86e2 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 21 Nov 2019 01:32:58 +0800 Subject: [PATCH] Invalidate snapshot of home if its UI is changed Snapshot may be enabled for home task when turning off screen. If home UI has changed after screen off, the snapshot should not be used to avoid ugly visual effect. Bug: 140811348 Test: Lock/unlock device while home is on top with 4 cases: 1. All apps is shown. 2. Overview is shown. 3. Options menu is shown. 4. Quick search bar is active. The expected result should be no starting window when unlocking because the snapshot is dropped. Change-Id: I4bd9926b6f9332ac16b1b3a25ffdd44706015a33 --- .../launcher3/BaseQuickstepLauncher.java | 7 ++++++ src/com/android/launcher3/Launcher.java | 22 +++++++++++++++++++ .../launcher3/LauncherStateManager.java | 9 ++++++++ 3 files changed, 38 insertions(+) diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java index 9ea13c640c..62e88a17ef 100644 --- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java @@ -49,6 +49,7 @@ import com.android.quickstep.SysUINavigationMode.NavigationModeChangeListener; import com.android.quickstep.SystemUiProxy; import com.android.quickstep.util.RemoteFadeOutAnimationListener; import com.android.quickstep.util.ShelfPeekAnim; +import com.android.systemui.shared.system.ActivityManagerWrapper; import java.util.stream.Stream; @@ -143,6 +144,12 @@ public abstract class BaseQuickstepLauncher extends Launcher RecentsModel.INSTANCE.get(this).onTrimMemory(level); } + @Override + protected void onUiChangedWhileSleeping() { + // Remove the snapshot because the content view may have obvious changes. + ActivityManagerWrapper.getInstance().invalidateHomeTaskSnapshot(this); + } + @Override public void startIntentSenderForResult(IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) { diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index cb8fe05c0e..3c302da224 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -932,6 +932,9 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, @Override protected void onStop() { + final boolean wasActive = isUserActive(); + final LauncherState origState = getStateManager().getState(); + final int origDragLayerChildCount = mDragLayer.getChildCount(); super.onStop(); if (mDeferOverlayCallbacks) { @@ -949,6 +952,20 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, // Workaround for b/78520668, explicitly trim memory once UI is hidden onTrimMemory(TRIM_MEMORY_UI_HIDDEN); + + if (wasActive) { + // The expected condition is that this activity is stopped because the device goes to + // sleep and the UI may have noticeable changes. + mDragLayer.post(() -> { + if ((!getStateManager().isInStableState(origState) + // The drag layer may be animating (e.g. dismissing QSB). + || mDragLayer.getAlpha() < 1 + // Maybe an ArrowPopup is closed. + || mDragLayer.getChildCount() != origDragLayerChildCount)) { + onUiChangedWhileSleeping(); + } + }); + } } @Override @@ -1343,11 +1360,16 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, // Reset AllApps to its initial state only if we are not in the middle of // processing a multi-step drop if (mPendingRequestArgs == null) { + if (!isInState(NORMAL)) { + onUiChangedWhileSleeping(); + } mStateManager.goToState(NORMAL); } } }; + protected void onUiChangedWhileSleeping() { } + public void updateNotificationDots(Predicate updatedDots) { mWorkspace.updateNotificationDots(updatedDots); mAppsView.getAppsStore().updateNotificationDots(updatedDots); diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java index daf270bfa1..810aff652e 100644 --- a/src/com/android/launcher3/LauncherStateManager.java +++ b/src/com/android/launcher3/LauncherStateManager.java @@ -163,6 +163,15 @@ public class LauncherStateManager { return !mLauncher.isForceInvisible() && mLauncher.isStarted(); } + /** + * @return {@code true} if the state matches the current state and there is no active + * transition to different state. + */ + public boolean isInStableState(LauncherState state) { + return mState == state && mCurrentStableState == state + && (mConfig.mTargetState == null || mConfig.mTargetState == state); + } + /** * @see #goToState(LauncherState, boolean, Runnable) */