summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Federico Baron <fbaron@google.com> 2025-03-10 22:21:36 +0000
committer Federico Baron <fbaron@google.com> 2025-03-20 01:31:45 +0000
commitc7e8c4e8e7caea22a9ceebe3a1b3776a441cfbfc (patch)
tree999a65298a997834ed8c6c0b5de41d3deca505d2
parent2152c302fdc4859a5676c86b7034e73ec7fbb3b9 (diff)
Add logging for which type of migration occurs.
When upgrading from non one grid to one grid, we should do the row shift migration type, here we are logging data to make sure that is what happens on upgrade Flag: EXEMPT logging Test: n/a Bug: 393175684 Change-Id: Id09257094bc9bc44da757c73a4f63bf15987772c
-rw-r--r--src/com/android/launcher3/GridType.kt33
-rw-r--r--src/com/android/launcher3/InvariantDeviceProfile.java16
-rw-r--r--src/com/android/launcher3/LauncherPrefs.kt4
-rw-r--r--src/com/android/launcher3/logging/StatsLogManager.java6
-rw-r--r--src/com/android/launcher3/model/DeviceGridState.java20
-rw-r--r--src/com/android/launcher3/model/GridSizeMigrationDBController.java17
-rw-r--r--src/com/android/launcher3/model/GridSizeMigrationLogic.kt12
-rw-r--r--tests/multivalentTests/src/com/android/launcher3/model/gridmigration/ValidGridMigrationUnitTest.kt10
-rw-r--r--tests/src/com/android/launcher3/model/GridMigrationTest.kt40
9 files changed, 140 insertions, 18 deletions
diff --git a/src/com/android/launcher3/GridType.kt b/src/com/android/launcher3/GridType.kt
new file mode 100644
index 0000000000..d006b8f35f
--- /dev/null
+++ b/src/com/android/launcher3/GridType.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3
+
+import androidx.annotation.IntDef
+
+/** The type of grid. */
+@IntDef(GridType.GRID_TYPE_ONE_GRID, GridType.GRID_TYPE_NON_ONE_GRID, GridType.GRID_TYPE_ANY)
+@Retention(AnnotationRetention.SOURCE)
+annotation class GridType {
+ companion object {
+ /** These are grids that use one grid spec. */
+ const val GRID_TYPE_ONE_GRID = 1
+ /** These are grids that don't use one grid spec. */
+ const val GRID_TYPE_NON_ONE_GRID = 2
+ /** Any grid type. */
+ const val GRID_TYPE_ANY = GRID_TYPE_NON_ONE_GRID or GRID_TYPE_ONE_GRID
+ }
+}
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index f189549463..15a4fc4072 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -16,6 +16,9 @@
package com.android.launcher3;
+import static com.android.launcher3.GridType.GRID_TYPE_ANY;
+import static com.android.launcher3.GridType.GRID_TYPE_NON_ONE_GRID;
+import static com.android.launcher3.GridType.GRID_TYPE_ONE_GRID;
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;
@@ -241,6 +244,8 @@ public class InvariantDeviceProfile {
*/
public boolean isFixedLandscape = false;
+ @GridType
+ public int gridType;
public String dbFile;
public int defaultLayoutId;
public int demoModeLayoutId;
@@ -369,6 +374,7 @@ public class InvariantDeviceProfile {
numColumns = closestProfile.numColumns;
numSearchContainerColumns = closestProfile.numSearchContainerColumns;
dbFile = closestProfile.dbFile;
+ gridType = closestProfile.gridType;
defaultLayoutId = closestProfile.defaultLayoutId;
demoModeLayoutId = closestProfile.demoModeLayoutId;
@@ -936,10 +942,7 @@ public class InvariantDeviceProfile {
private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
- private static final int GRID_TYPE_ONE_GRID = 1 << 0;
- private static final int GRID_TYPE_NON_ONE_GRID = 1 << 1;
- private static final int GRID_TYPE_ALL = 1 << 2;
- private static final int DEVICE_CATEGORY_ALL =
+ private static final int DEVICE_CATEGORY_ANY =
DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
@@ -955,6 +958,7 @@ public class InvariantDeviceProfile {
public final int numColumns;
public final int numSearchContainerColumns;
public final int deviceCategory;
+ @GridType
public final int gridType;
private final int[] numFolderRows = new int[COUNT_SIZES];
@@ -1003,7 +1007,7 @@ public class InvariantDeviceProfile {
gridIconId = a.getResourceId(
R.styleable.GridDisplayOption_gridIconId, INVALID_RESOURCE_HANDLE);
deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
- DEVICE_CATEGORY_ALL);
+ DEVICE_CATEGORY_ANY);
mGridSizeSpecsId = a.getResourceId(
R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
@@ -1141,7 +1145,7 @@ public class InvariantDeviceProfile {
}
mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
- gridType = a.getInt(R.styleable.GridDisplayOption_gridType, GRID_TYPE_ALL);
+ gridType = a.getInt(R.styleable.GridDisplayOption_gridType, GRID_TYPE_ANY);
int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
DONT_INLINE_QSB);
diff --git a/src/com/android/launcher3/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt
index 7a04b0f950..30c4529613 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.GridType.Companion.GRID_TYPE_ANY
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
@@ -266,6 +267,9 @@ constructor(@ApplicationContext private val encryptedContext: Context) {
@JvmField
val DB_FILE = backedUpItem(DeviceGridState.KEY_DB_FILE, "", EncryptionType.ENCRYPTED)
@JvmField
+ val GRID_TYPE =
+ backedUpItem(DeviceGridState.KEY_GRID_TYPE, GRID_TYPE_ANY, EncryptionType.ENCRYPTED)
+ @JvmField
val SHOULD_SHOW_SMARTSPACE =
backedUpItem(
SHOULD_SHOW_SMARTSPACE_KEY,
diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java
index 44d2e266f7..40b597f838 100644
--- a/src/com/android/launcher3/logging/StatsLogManager.java
+++ b/src/com/android/launcher3/logging/StatsLogManager.java
@@ -890,6 +890,12 @@ public class StatsLogManager implements ResourceBasedOverride {
@UiEvent(doc = "Row shift grid migration occurred")
LAUNCHER_ROW_SHIFT_GRID_MIGRATION(2201),
+ @UiEvent(doc = "Do standard migration when upgrading to one grid")
+ LAUNCHER_STANDARD_ONE_GRID_MIGRATION(2205),
+
+ @UiEvent(doc = "Do row shift migration when upgrading to one grid")
+ LAUNCHER_ROW_SHIFT_ONE_GRID_MIGRATION(2206),
+
// ADD MORE
;
diff --git a/src/com/android/launcher3/model/DeviceGridState.java b/src/com/android/launcher3/model/DeviceGridState.java
index 96ce4c83db..32ea4b5fd7 100644
--- a/src/com/android/launcher3/model/DeviceGridState.java
+++ b/src/com/android/launcher3/model/DeviceGridState.java
@@ -19,6 +19,7 @@ package com.android.launcher3.model;
import static com.android.launcher3.InvariantDeviceProfile.DeviceType;
import static com.android.launcher3.LauncherPrefs.DB_FILE;
import static com.android.launcher3.LauncherPrefs.DEVICE_TYPE;
+import static com.android.launcher3.LauncherPrefs.GRID_TYPE;
import static com.android.launcher3.LauncherPrefs.HOTSEAT_COUNT;
import static com.android.launcher3.LauncherPrefs.WORKSPACE_SIZE;
@@ -41,17 +42,21 @@ public class DeviceGridState implements Comparable<DeviceGridState> {
public static final String KEY_HOTSEAT_COUNT = "migration_src_hotseat_count";
public static final String KEY_DEVICE_TYPE = "migration_src_device_type";
public static final String KEY_DB_FILE = "migration_src_db_file";
+ public static final String KEY_GRID_TYPE = "migration_src_grid_type";
private final String mGridSizeString;
private final int mNumHotseat;
private final @DeviceType int mDeviceType;
private final String mDbFile;
+ private final int mGridType;
- public DeviceGridState(int columns, int row, int numHotseat, int deviceType, String dbFile) {
+ public DeviceGridState(int columns, int row, int numHotseat, int deviceType, String dbFile,
+ int gridType) {
mGridSizeString = String.format(Locale.ENGLISH, "%d,%d", columns, row);
mNumHotseat = numHotseat;
mDeviceType = deviceType;
mDbFile = dbFile;
+ mGridType = gridType;
}
public DeviceGridState(InvariantDeviceProfile idp) {
@@ -59,6 +64,7 @@ public class DeviceGridState implements Comparable<DeviceGridState> {
mNumHotseat = idp.numDatabaseHotseatIcons;
mDeviceType = idp.deviceType;
mDbFile = idp.dbFile;
+ mGridType = idp.gridType;
}
public DeviceGridState(Context context) {
@@ -70,6 +76,7 @@ public class DeviceGridState implements Comparable<DeviceGridState> {
mNumHotseat = lp.get(HOTSEAT_COUNT);
mDeviceType = lp.get(DEVICE_TYPE);
mDbFile = lp.get(DB_FILE);
+ mGridType = lp.get(GRID_TYPE);
}
/**
@@ -94,6 +101,13 @@ public class DeviceGridState implements Comparable<DeviceGridState> {
}
/**
+ * Returns the grid type.
+ */
+ public int getGridType() {
+ return mGridType;
+ }
+
+ /**
* Stores the device state to shared preferences
*/
public void writeToPrefs(Context context) {
@@ -101,7 +115,9 @@ public class DeviceGridState implements Comparable<DeviceGridState> {
WORKSPACE_SIZE.to(mGridSizeString),
HOTSEAT_COUNT.to(mNumHotseat),
DEVICE_TYPE.to(mDeviceType),
- DB_FILE.to(mDbFile));
+ DB_FILE.to(mDbFile),
+ GRID_TYPE.to(mGridType));
+
}
/**
diff --git a/src/com/android/launcher3/model/GridSizeMigrationDBController.java b/src/com/android/launcher3/model/GridSizeMigrationDBController.java
index 3e4394373a..12ba07de4e 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationDBController.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationDBController.java
@@ -17,11 +17,16 @@
package com.android.launcher3.model;
import static com.android.launcher3.Flags.enableSmartspaceRemovalToggle;
+import static com.android.launcher3.GridType.GRID_TYPE_NON_ONE_GRID;
+import static com.android.launcher3.GridType.GRID_TYPE_ONE_GRID;
+import static com.android.launcher3.InvariantDeviceProfile.TYPE_TABLET;
import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.LauncherSettings.Favorites.TMP_TABLE;
import static com.android.launcher3.Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ROW_SHIFT_GRID_MIGRATION;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ROW_SHIFT_ONE_GRID_MIGRATION;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_STANDARD_GRID_MIGRATION;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_STANDARD_ONE_GRID_MIGRATION;
import static com.android.launcher3.model.LoaderTask.SMARTSPACE_ON_HOME_SCREEN;
import static com.android.launcher3.provider.LauncherDbUtils.copyTable;
import static com.android.launcher3.provider.LauncherDbUtils.dropTable;
@@ -157,6 +162,9 @@ public class GridSizeMigrationDBController {
// Save current configuration, so that the migration does not run again.
destDeviceState.writeToPrefs(context);
t.commit();
+ if (isOneGridMigration(srcDeviceState, destDeviceState)) {
+ statsLogManager.logger().log(LAUNCHER_ROW_SHIFT_ONE_GRID_MIGRATION);
+ }
statsLogManager.logger().log(LAUNCHER_ROW_SHIFT_GRID_MIGRATION);
return true;
}
@@ -169,6 +177,9 @@ public class GridSizeMigrationDBController {
destDeviceState.getNumHotseat(), targetSize, srcDeviceState, destDeviceState);
dropTable(t.getDb(), TMP_TABLE);
t.commit();
+ if (isOneGridMigration(srcDeviceState, destDeviceState)) {
+ statsLogManager.logger().log(LAUNCHER_STANDARD_ONE_GRID_MIGRATION);
+ }
statsLogManager.logger().log(LAUNCHER_STANDARD_GRID_MIGRATION);
return true;
} catch (Exception e) {
@@ -291,6 +302,12 @@ public class GridSizeMigrationDBController {
return true;
}
+ protected static boolean isOneGridMigration(DeviceGridState srcDeviceState,
+ DeviceGridState destDeviceState) {
+ return srcDeviceState.getDeviceType() != TYPE_TABLET
+ && srcDeviceState.getGridType() == GRID_TYPE_NON_ONE_GRID
+ && destDeviceState.getGridType() == GRID_TYPE_ONE_GRID;
+ }
/**
* Calculate the differences between {@code src} (denoted by A) and {@code dest}
* (denoted by B).
diff --git a/src/com/android/launcher3/model/GridSizeMigrationLogic.kt b/src/com/android/launcher3/model/GridSizeMigrationLogic.kt
index 2957e3c608..d88f6ccfc6 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationLogic.kt
+++ b/src/com/android/launcher3/model/GridSizeMigrationLogic.kt
@@ -32,8 +32,11 @@ import com.android.launcher3.config.FeatureFlags
import com.android.launcher3.logging.FileLog
import com.android.launcher3.logging.StatsLogManager
import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ROW_SHIFT_GRID_MIGRATION
+import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ROW_SHIFT_ONE_GRID_MIGRATION
import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_STANDARD_GRID_MIGRATION
+import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_STANDARD_ONE_GRID_MIGRATION
import com.android.launcher3.model.GridSizeMigrationDBController.DbReader
+import com.android.launcher3.model.GridSizeMigrationDBController.isOneGridMigration
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction
import com.android.launcher3.provider.LauncherDbUtils.copyTable
import com.android.launcher3.provider.LauncherDbUtils.dropTable
@@ -95,7 +98,12 @@ class GridSizeMigrationLogic {
// Save current configuration, so that the migration does not run again.
destDeviceState.writeToPrefs(context)
t.commit()
+
+ if (isOneGridMigration(srcDeviceState, destDeviceState)) {
+ statsLogManager.logger().log(LAUNCHER_ROW_SHIFT_ONE_GRID_MIGRATION)
+ }
statsLogManager.logger().log(LAUNCHER_ROW_SHIFT_GRID_MIGRATION)
+
return
}
@@ -125,6 +133,10 @@ class GridSizeMigrationLogic {
dropTable(t.db, TMP_TABLE)
t.commit()
+
+ if (isOneGridMigration(srcDeviceState, destDeviceState)) {
+ statsLogManager.logger().log(LAUNCHER_STANDARD_ONE_GRID_MIGRATION)
+ }
statsLogManager.logger().log(LAUNCHER_STANDARD_GRID_MIGRATION)
}
} catch (e: Exception) {
diff --git a/tests/multivalentTests/src/com/android/launcher3/model/gridmigration/ValidGridMigrationUnitTest.kt b/tests/multivalentTests/src/com/android/launcher3/model/gridmigration/ValidGridMigrationUnitTest.kt
index 1d1e7ebd1b..dd26ed234c 100644
--- a/tests/multivalentTests/src/com/android/launcher3/model/gridmigration/ValidGridMigrationUnitTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/model/gridmigration/ValidGridMigrationUnitTest.kt
@@ -27,6 +27,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import androidx.test.platform.app.InstrumentationRegistry
import com.android.launcher3.Flags
+import com.android.launcher3.GridType.Companion.GRID_TYPE_ANY
import com.android.launcher3.InvariantDeviceProfile
import com.android.launcher3.LauncherSettings.Favorites
import com.android.launcher3.celllayout.testgenerator.ValidGridMigrationTestCaseGenerator
@@ -46,7 +47,14 @@ import org.junit.runner.RunWith
private data class Grid(val tableName: String, val size: Point, val items: List<WorkspaceItem>) {
fun toGridState(): DeviceGridState =
- DeviceGridState(size.x, size.y, size.x, InvariantDeviceProfile.TYPE_PHONE, tableName)
+ DeviceGridState(
+ size.x,
+ size.y,
+ size.x,
+ InvariantDeviceProfile.TYPE_PHONE,
+ tableName,
+ GRID_TYPE_ANY,
+ )
}
@SmallTest
diff --git a/tests/src/com/android/launcher3/model/GridMigrationTest.kt b/tests/src/com/android/launcher3/model/GridMigrationTest.kt
index 380c2089da..eed373f23a 100644
--- a/tests/src/com/android/launcher3/model/GridMigrationTest.kt
+++ b/tests/src/com/android/launcher3/model/GridMigrationTest.kt
@@ -22,6 +22,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import androidx.test.platform.app.InstrumentationRegistry
import com.android.launcher3.Flags
+import com.android.launcher3.GridType.Companion.GRID_TYPE_ANY
import com.android.launcher3.InvariantDeviceProfile.TYPE_PHONE
import com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME
import com.android.launcher3.celllayout.board.CellLayoutBoard
@@ -192,15 +193,22 @@ class GridMigrationTest {
@Test
fun `5x5 to 3x3`() =
runTest(
- src = GridMigrationData(DB_FILE, DeviceGridState(5, 5, 5, TYPE_PHONE, DB_FILE)),
+ src =
+ GridMigrationData(
+ DB_FILE,
+ DeviceGridState(5, 5, 5, TYPE_PHONE, DB_FILE, GRID_TYPE_ANY),
+ ),
dst =
GridMigrationData(
null, // in memory db, to download a new db change null for
// the filename of the db name to store it. Do not use existing names.
- DeviceGridState(3, 3, 3, TYPE_PHONE, ""),
+ DeviceGridState(3, 3, 3, TYPE_PHONE, "", GRID_TYPE_ANY),
),
target =
- GridMigrationData("result5x5to3x3.db", DeviceGridState(3, 3, 3, TYPE_PHONE, "")),
+ GridMigrationData(
+ "result5x5to3x3.db",
+ DeviceGridState(3, 3, 3, TYPE_PHONE, "", GRID_TYPE_ANY),
+ ),
)
@JvmField
@@ -215,15 +223,22 @@ class GridMigrationTest {
@Test
fun `5x5 to 4x7`() =
runTest(
- src = GridMigrationData(DB_FILE, DeviceGridState(5, 5, 5, TYPE_PHONE, DB_FILE)),
+ src =
+ GridMigrationData(
+ DB_FILE,
+ DeviceGridState(5, 5, 5, TYPE_PHONE, DB_FILE, GRID_TYPE_ANY),
+ ),
dst =
GridMigrationData(
null, // in memory db, to download a new db change null for
// the filename of the db name to store it. Do not use existing names.
- DeviceGridState(4, 7, 4, TYPE_PHONE, ""),
+ DeviceGridState(4, 7, 4, TYPE_PHONE, "", GRID_TYPE_ANY),
),
target =
- GridMigrationData("result5x5to4x7.db", DeviceGridState(4, 7, 4, TYPE_PHONE, "")),
+ GridMigrationData(
+ "result5x5to4x7.db",
+ DeviceGridState(4, 7, 4, TYPE_PHONE, "", GRID_TYPE_ANY),
+ ),
)
@JvmField
@@ -238,16 +253,23 @@ class GridMigrationTest {
@Test
fun `5x5 to 5x8`() =
runTest(
- src = GridMigrationData(DB_FILE, DeviceGridState(5, 5, 5, TYPE_PHONE, DB_FILE)),
+ src =
+ GridMigrationData(
+ DB_FILE,
+ DeviceGridState(5, 5, 5, TYPE_PHONE, DB_FILE, GRID_TYPE_ANY),
+ ),
dst =
GridMigrationData(
null, // in memory db, to download a new db change null
// for
// the filename of the db name to store it. Do not use existing names.
- DeviceGridState(5, 8, 5, TYPE_PHONE, ""),
+ DeviceGridState(5, 8, 5, TYPE_PHONE, "", GRID_TYPE_ANY),
),
target =
- GridMigrationData("result5x5to5x8.db", DeviceGridState(5, 8, 5, TYPE_PHONE, "")),
+ GridMigrationData(
+ "result5x5to5x8.db",
+ DeviceGridState(5, 8, 5, TYPE_PHONE, "", GRID_TYPE_ANY),
+ ),
)
companion object {