Reland "Handle uiMode changes in QuickstepLauncher"
- Added uiMode in handled configChanges for QuickstepLauncher, NexusLauncherActivity
- RecentsActivity will be handled separately in b/382072029
- This avoids Launcher from being recreated when swithching from an app in driving mode (e.g. Maps), which causes massive jank
- Launcher layout is unaffected when driving mode changes, so a recreation is unnecessary
- When Light/dark mode changes, BaseActivity.updateTheme will still causes activity to be recreated. Launcher will mark a boolean in saved staete so next recreate will restore previous state even if state has FLAG_DISABLE_RESTORE (e.g. Overview), similar to the existing check that force restore when UI_MODE changes
Relanded changes: /q/submissionid:27627108-b/339747262
Fix: 339747262
Test: Swtich from driving mode app to another or home in 1p and 3p laucnher
Test: Switch light/dark mode and Launcher is updated correctly and stay in previous state
Flag: EXEMPT bugfix
Change-Id: I5a62b1bcd19eed9d232f30db94aa0e032f4541bd
diff --git a/quickstep/AndroidManifest-launcher.xml b/quickstep/AndroidManifest-launcher.xml
index c6e2d8c..80d8154 100644
--- a/quickstep/AndroidManifest-launcher.xml
+++ b/quickstep/AndroidManifest-launcher.xml
@@ -48,7 +48,7 @@
android:stateNotNeeded="true"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="unspecified"
- android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize"
+ android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:resizeableActivity="true"
android:resumeWhilePausing="true"
android:taskAffinity=""
diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java
index 50e78ac..3b93cf4 100644
--- a/src/com/android/launcher3/BaseDraggingActivity.java
+++ b/src/com/android/launcher3/BaseDraggingActivity.java
@@ -80,12 +80,16 @@
updateTheme();
}
- protected void updateTheme() {
+ private void updateTheme() {
if (mThemeRes != Themes.getActivityThemeRes(this)) {
- recreate();
+ recreateToUpdateTheme();
}
}
+ protected void recreateToUpdateTheme() {
+ recreate();
+ }
+
@Override
public void onActionModeStarted(ActionMode mode) {
super.onActionModeStarted(mode);
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 8981024..7932531 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -46,6 +46,7 @@
import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.RUNTIME_STATE_PENDING_ACTIVITY_RESULT;
import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.RUNTIME_STATE_PENDING_REQUEST_ARGS;
import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.RUNTIME_STATE_PENDING_REQUEST_CODE;
+import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.RUNTIME_STATE_RECREATE_TO_UPDATE_THEME;
import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.RUNTIME_STATE_WIDGET_PANEL;
import static com.android.launcher3.LauncherConstants.TraceEvents.COLD_STARTUP_TRACE_COOKIE;
import static com.android.launcher3.LauncherConstants.TraceEvents.COLD_STARTUP_TRACE_METHOD_NAME;
@@ -422,6 +423,8 @@
private final SettingsCache.OnChangeListener mNaturalScrollingChangedListener =
enabled -> mIsNaturalScrollingEnabled = enabled;
+ private boolean mRecreateToUpdateTheme = false;
+
public static Launcher getLauncher(Context context) {
return fromContext(context);
}
@@ -1352,7 +1355,8 @@
NonConfigInstance lastInstance = (NonConfigInstance) getLastNonConfigurationInstance();
boolean forceRestore = lastInstance != null
- && (lastInstance.config.diff(mOldConfig) & CONFIG_UI_MODE) != 0;
+ && ((lastInstance.config.diff(mOldConfig) & CONFIG_UI_MODE) != 0
+ || savedState.getBoolean(RUNTIME_STATE_RECREATE_TO_UPDATE_THEME));
if (forceRestore || !state.shouldDisableRestore()) {
mStateManager.goToState(state, false /* animated */);
}
@@ -1747,6 +1751,12 @@
}
@Override
+ protected void recreateToUpdateTheme() {
+ mRecreateToUpdateTheme = true;
+ super.recreateToUpdateTheme();
+ }
+
+ @Override
public void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
IntSet synchronouslyBoundPages = mModelCallbacks.getSynchronouslyBoundPages();
@@ -1791,6 +1801,8 @@
outState.putParcelable(RUNTIME_STATE_PENDING_ACTIVITY_RESULT, mPendingActivityResult);
}
+ outState.putBoolean(RUNTIME_STATE_RECREATE_TO_UPDATE_THEME, mRecreateToUpdateTheme);
+
super.onSaveInstanceState(outState);
}
diff --git a/src/com/android/launcher3/LauncherConstants.java b/src/com/android/launcher3/LauncherConstants.java
index 445fb41..0ed239d 100644
--- a/src/com/android/launcher3/LauncherConstants.java
+++ b/src/com/android/launcher3/LauncherConstants.java
@@ -67,5 +67,8 @@
static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
// Type int[]
static final String RUNTIME_STATE_CURRENT_SCREEN_IDS = "launcher.current_screen_ids";
+ // Type: boolean
+ static final String RUNTIME_STATE_RECREATE_TO_UPDATE_THEME =
+ "launcher.recreate_to_update_theme";
}
}