From 54b09dc41ffdbf1a5e0be3df99db5a798d4470c6 Mon Sep 17 00:00:00 2001 From: Federico Baron Date: Thu, 6 Feb 2025 18:58:16 +0000 Subject: [PATCH] Fix issue where turning off fixed landscape goes to default grid Bug: 390091751 Test: manually verified on device Flag: com.android.launcher3.one_grid_specs Change-Id: Id9de8cadc6fc1ee0ac0124638b2c487b8f8357bb --- .../android/launcher3/InvariantDeviceProfile.java | 12 +++++++++++- src/com/android/launcher3/LauncherPrefs.kt | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index e47a44ae15..add8a05dcb 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -20,6 +20,7 @@ import static com.android.launcher3.LauncherPrefs.DB_FILE; import static com.android.launcher3.LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE; import static com.android.launcher3.LauncherPrefs.FIXED_LANDSCAPE_MODE; import static com.android.launcher3.LauncherPrefs.GRID_NAME; +import static com.android.launcher3.LauncherPrefs.NON_FIXED_LANDSCAPE_GRID_NAME; import static com.android.launcher3.Utilities.dpiFromPx; import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE; import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY; @@ -93,6 +94,8 @@ public class InvariantDeviceProfile implements SafeCloseable { new MainThreadInitializedObject<>(InvariantDeviceProfile::new); public static final String GRID_NAME_PREFS_KEY = "idp_grid_name"; + public static final String NON_FIXED_LANDSCAPE_GRID_NAME_PREFS_KEY = + "idp_non_fixed_landscape_grid_name"; @Retention(RetentionPolicy.SOURCE) @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET}) @@ -268,7 +271,14 @@ public class InvariantDeviceProfile implements SafeCloseable { if (FIXED_LANDSCAPE_MODE.getSharedPrefKey().equals(key) && isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) { Trace.beginSection("InvariantDeviceProfile#setFixedLandscape"); - onConfigChanged(context); + if (isFixedLandscape) { + setCurrentGrid( + context, LauncherPrefs.get(context).get(NON_FIXED_LANDSCAPE_GRID_NAME)); + } else { + LauncherPrefs.get(context) + .put(NON_FIXED_LANDSCAPE_GRID_NAME, getCurrentGridName(context)); + onConfigChanged(context); + } Trace.endSection(); } else if (ENABLE_TWOLINE_ALLAPPS_TOGGLE.getSharedPrefKey().equals(key) && enableTwoLinesInAllApps != ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(context)) { diff --git a/src/com/android/launcher3/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt index 1120ec8b8d..2a5cd63752 100644 --- a/src/com/android/launcher3/LauncherPrefs.kt +++ b/src/com/android/launcher3/LauncherPrefs.kt @@ -21,6 +21,7 @@ import android.content.SharedPreferences import androidx.annotation.VisibleForTesting import com.android.launcher3.BuildConfig.WIDGET_ON_FIRST_SCREEN import com.android.launcher3.InvariantDeviceProfile.GRID_NAME_PREFS_KEY +import com.android.launcher3.InvariantDeviceProfile.NON_FIXED_LANDSCAPE_GRID_NAME_PREFS_KEY import com.android.launcher3.LauncherFiles.DEVICE_PREFERENCES_KEY import com.android.launcher3.LauncherFiles.SHARED_PREFERENCES_KEY import com.android.launcher3.dagger.ApplicationContext @@ -304,6 +305,16 @@ constructor(@ApplicationContext private val encryptedContext: Context) { @JvmField val FIXED_LANDSCAPE_MODE = backedUpItem(SettingsActivity.FIXED_LANDSCAPE_MODE, false) + @JvmField + val NON_FIXED_LANDSCAPE_GRID_NAME = + ConstantItem( + NON_FIXED_LANDSCAPE_GRID_NAME_PREFS_KEY, + isBackedUp = true, + defaultValue = null, + encryptionType = EncryptionType.ENCRYPTED, + type = String::class.java, + ) + // Preferences for widget configurations @JvmField val RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN =