From 980c089d2f72e3369efb88cd793f071e75a4b0b5 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 8 Dec 2020 19:19:56 -0800 Subject: [PATCH] [DO NOT MERGE] Keeping Launcher in overview UI if activity is restarting due to UI mode changes Test: Verified Launcher behavior locally Bug: 148988542 Change-Id: Id83e5e0892666af1420e8f8c711b83f1ea355188 (cherry picked from commit 6c0c61acd8e81be312e1edda5f9a3c85a0718746) --- src/com/android/launcher3/Launcher.java | 18 +++++++++++++++++- .../statemanager/StatefulActivity.java | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index e1f2b325f3..ae89deda47 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -18,6 +18,7 @@ package com.android.launcher3; import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; +import static android.content.pm.ActivityInfo.CONFIG_UI_MODE; import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; import static com.android.launcher3.AbstractFloatingView.TYPE_ALL; @@ -1103,7 +1104,11 @@ public class Launcher extends StatefulActivity implements Launche int stateOrdinal = savedState.getInt(RUNTIME_STATE, NORMAL.ordinal); LauncherState[] stateValues = LauncherState.values(); LauncherState state = stateValues[stateOrdinal]; - if (!state.shouldDisableRestore()) { + + NonConfigInstance lastInstance = (NonConfigInstance) getLastNonConfigurationInstance(); + boolean forceRestore = lastInstance != null + && (lastInstance.config.diff(mOldConfig) & CONFIG_UI_MODE) != 0; + if (forceRestore || !state.shouldDisableRestore()) { mStateManager.goToState(state, false /* animated */); } @@ -1343,6 +1348,13 @@ public class Launcher extends StatefulActivity implements Launche closeContextMenu(); } + @Override + public Object onRetainNonConfigurationInstance() { + NonConfigInstance instance = new NonConfigInstance(); + instance.config = new Configuration(mOldConfig); + return instance; + } + public AllAppsTransitionController getAllAppsController() { return mAllAppsController; } @@ -2745,4 +2757,8 @@ public class Launcher extends StatefulActivity implements Launche void onLauncherResume(); } + + private static class NonConfigInstance { + public Configuration config; + } } diff --git a/src/com/android/launcher3/statemanager/StatefulActivity.java b/src/com/android/launcher3/statemanager/StatefulActivity.java index dbe5f42e31..601e117f1c 100644 --- a/src/com/android/launcher3/statemanager/StatefulActivity.java +++ b/src/com/android/launcher3/statemanager/StatefulActivity.java @@ -121,7 +121,9 @@ public abstract class StatefulActivity> final int origDragLayerChildCount = dragLayer.getChildCount(); super.onStop(); - getStateManager().moveToRestState(); + if (!isChangingConfigurations()) { + getStateManager().moveToRestState(); + } // Workaround for b/78520668, explicitly trim memory once UI is hidden onTrimMemory(TRIM_MEMORY_UI_HIDDEN);