diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 5becddeed7..dddc43f913 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -16,6 +16,7 @@ package com.android.launcher3; +import static com.android.launcher3.LauncherPrefs.DB_FILE; import static com.android.launcher3.LauncherPrefs.FIXED_LANDSCAPE_MODE; import static com.android.launcher3.LauncherPrefs.GRID_NAME; import static com.android.launcher3.Utilities.dpiFromPx; @@ -53,6 +54,7 @@ import androidx.core.content.res.ResourcesCompat; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.icons.DotRenderer; +import com.android.launcher3.logging.FileLog; import com.android.launcher3.model.DeviceGridState; import com.android.launcher3.provider.RestoreDbTask; import com.android.launcher3.testing.shared.ResourceUtils; @@ -86,6 +88,8 @@ public class InvariantDeviceProfile implements SafeCloseable { public static final MainThreadInitializedObject INSTANCE = new MainThreadInitializedObject<>(InvariantDeviceProfile::new); + public static final String GRID_NAME_PREFS_KEY = "idp_grid_name"; + @Retention(RetentionPolicy.SOURCE) @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET}) public @interface DeviceType { @@ -241,8 +245,11 @@ public class InvariantDeviceProfile implements SafeCloseable { @TargetApi(23) private InvariantDeviceProfile(Context context) { String gridName = getCurrentGridName(context); + FileLog.d(TAG, "New InvariantDeviceProfile, before initGrid(): " + + "gridName:" + gridName + + ", LauncherPrefs GRID_NAME:" + LauncherPrefs.get(context).get(GRID_NAME) + + ", LauncherPrefs DB_FILE:" + LauncherPrefs.get(context).get(DB_FILE)); initGrid(context, gridName); - DisplayController.INSTANCE.get(context).setPriorityListener( (displayContext, info, flags) -> { if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS @@ -371,6 +378,10 @@ public class InvariantDeviceProfile implements SafeCloseable { } initGrid(context, displayInfo, displayOption); + FileLog.d(TAG, "initGrid: " + + "gridName:" + gridName + + ", LauncherPrefs GRID_NAME:" + LauncherPrefs.get(context).get(GRID_NAME) + + ", LauncherPrefs DB_FILE:" + LauncherPrefs.get(context).get(DB_FILE)); return displayOption.grid.name; } diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index 01d0a740d7..a53238da3a 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -20,8 +20,12 @@ import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_RESOURC import static android.content.Context.RECEIVER_EXPORTED; import static com.android.launcher3.Flags.enableSmartspaceRemovalToggle; +import static com.android.launcher3.InvariantDeviceProfile.GRID_NAME_PREFS_KEY; +import static com.android.launcher3.LauncherPrefs.DB_FILE; +import static com.android.launcher3.LauncherPrefs.GRID_NAME; import static com.android.launcher3.LauncherPrefs.ICON_STATE; import static com.android.launcher3.LauncherPrefs.THEMED_ICONS; +import static com.android.launcher3.model.DeviceGridState.KEY_DB_FILE; import static com.android.launcher3.model.LoaderTask.SMARTSPACE_ON_HOME_SCREEN; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; @@ -47,6 +51,7 @@ import com.android.launcher3.icons.IconCache; import com.android.launcher3.icons.IconProvider; import com.android.launcher3.icons.LauncherIconProvider; import com.android.launcher3.icons.LauncherIcons; +import com.android.launcher3.logging.FileLog; import com.android.launcher3.model.ModelLauncherCallbacks; import com.android.launcher3.model.WidgetsFilterDataProvider; import com.android.launcher3.notification.NotificationListener; @@ -70,6 +75,7 @@ import java.util.Objects; public class LauncherAppState implements SafeCloseable { + public static final String TAG = "LauncherAppState"; public static final String ACTION_FORCE_ROLOAD = "force-reload-launcher"; // We do not need any synchronization for this variable as its only written on UI thread. @@ -293,6 +299,12 @@ public class LauncherAppState implements SafeCloseable { if (Themes.KEY_THEMED_ICONS.equals(key)) { mIconProvider.setIconThemeSupported(Themes.isThemedIconEnabled(mContext)); verifyIconChanged(); + } else if (GRID_NAME_PREFS_KEY.equals(key)) { + FileLog.d(TAG, "onPrefChanged GRID_NAME changed: " + + LauncherPrefs.get(mContext).get(GRID_NAME)); + } else if (KEY_DB_FILE.equals(key)) { + FileLog.d(TAG, "onPrefChanged DB_FILE changed: " + + LauncherPrefs.get(mContext).get(DB_FILE)); } } } diff --git a/src/com/android/launcher3/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt index 712c56c3c6..5b9c2fa3a4 100644 --- a/src/com/android/launcher3/LauncherPrefs.kt +++ b/src/com/android/launcher3/LauncherPrefs.kt @@ -20,6 +20,7 @@ import android.content.Context.MODE_PRIVATE 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.LauncherFiles.DEVICE_PREFERENCES_KEY import com.android.launcher3.LauncherFiles.SHARED_PREFERENCES_KEY import com.android.launcher3.model.DeviceGridState @@ -138,7 +139,7 @@ abstract class LauncherPrefs : SafeCloseable { @JvmField val GRID_NAME = ConstantItem( - "idp_grid_name", + GRID_NAME_PREFS_KEY, isBackedUp = true, defaultValue = null, encryptionType = EncryptionType.ENCRYPTED, diff --git a/src/com/android/launcher3/provider/RestoreDbTask.java b/src/com/android/launcher3/provider/RestoreDbTask.java index 8db981f26a..f56888beee 100644 --- a/src/com/android/launcher3/provider/RestoreDbTask.java +++ b/src/com/android/launcher3/provider/RestoreDbTask.java @@ -124,11 +124,13 @@ public class RestoreDbTask { LauncherPrefs.get(context).removeSync(RESTORE_DEVICE); DeviceGridState deviceGridState = new DeviceGridState(context); + FileLog.d(TAG, "restoreIfNeeded: deviceGridState from context: " + deviceGridState); String oldPhoneFileName = deviceGridState.getDbFile(); List previousDbs = existingDbs(context); removeOldDBs(context, oldPhoneFileName); // The idp before this contains data about the old phone, after this it becomes the idp // of the current phone. + FileLog.d(TAG, "Resetting IDP to default for restore dest device"); idp.reset(context); trySettingPreviousGridAsCurrent(context, idp, oldPhoneFileName, previousDbs); } @@ -144,17 +146,24 @@ public class RestoreDbTask { context, oldPhoneDbFileName); // The grid option could be null if current phone doesn't support the previous db. if (oldPhoneGridOption != null) { + FileLog.d(TAG, "trySettingPreviousGridAsCurrent:" + + ", oldPhoneDbFileName: " + oldPhoneDbFileName + + ", oldPhoneGridOption: " + oldPhoneGridOption + + ", previousDbs: " + previousDbs); /* If the user only used the default db on the previous phone and the new default db is * bigger than or equal to the previous one, then keep the new default db */ if (previousDbs.size() == 1 && oldPhoneGridOption.numColumns <= idp.numColumns && oldPhoneGridOption.numRows <= idp.numRows) { /* Keep the user in default grid */ + FileLog.d(TAG, "Keeping default db from restore as current grid"); return; } /* * Here we are setting the previous db as the current one. */ + FileLog.d(TAG, "Setting grid from old device as current grid: " + + "oldPhoneGridOption:" + oldPhoneGridOption.name); idp.setCurrentGrid(context, oldPhoneGridOption.name); } }