mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-02 17:06:49 +00:00
add metrics for when db grid migration fails
Flag: ACONFIG enable_launcher_br_metrics TEAMFOOD Test: locally verified Bug: 307527314 Change-Id: Iab84a337d76d63bb3bc2ed81fdf4b6fd50dc5661
This commit is contained in:
@@ -19,6 +19,7 @@ import static android.util.Base64.NO_PADDING;
|
||||
import static android.util.Base64.NO_WRAP;
|
||||
|
||||
import static com.android.launcher3.DefaultLayoutParser.RES_PARTNER_DEFAULT_LAYOUT;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.addTableToDb;
|
||||
import static com.android.launcher3.LauncherSettings.Settings.LAYOUT_DIGEST_KEY;
|
||||
import static com.android.launcher3.LauncherSettings.Settings.LAYOUT_DIGEST_LABEL;
|
||||
@@ -48,6 +49,7 @@ import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.launcher3.AutoInstallsLayout;
|
||||
@@ -62,6 +64,7 @@ import com.android.launcher3.LauncherPrefs;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger;
|
||||
import com.android.launcher3.logging.FileLog;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.provider.LauncherDbUtils;
|
||||
@@ -86,6 +89,7 @@ public class ModelDbController {
|
||||
private static final String TAG = "LauncherProvider";
|
||||
|
||||
private static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED";
|
||||
private static final String RESTORE_ERROR_GRID_MIGRATION_FAILURE = "grid_migration_failed";
|
||||
public static final String EXTRA_DB_NAME = "db_name";
|
||||
|
||||
protected DatabaseHelper mOpenHelper;
|
||||
@@ -261,8 +265,12 @@ public class ModelDbController {
|
||||
/**
|
||||
* Migrates the DB if needed. If the migration failed, it clears the DB.
|
||||
*/
|
||||
public void tryMigrateDB() {
|
||||
public void tryMigrateDB(@Nullable LauncherRestoreEventLogger restoreEventLogger) {
|
||||
|
||||
if (!migrateGridIfNeeded()) {
|
||||
if (restoreEventLogger != null) {
|
||||
sendMetricsForFailedMigration(restoreEventLogger, getDb());
|
||||
}
|
||||
FileLog.d(TAG, "Migration failed: resetting launcher database");
|
||||
createEmptyDB();
|
||||
LauncherPrefs.get(mContext).putSync(
|
||||
@@ -312,6 +320,30 @@ public class ModelDbController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In case of migration failure, report metrics for the count of each itemType in the DB.
|
||||
* @param restoreEventLogger logger used to report Launcher restore metrics
|
||||
*/
|
||||
private void sendMetricsForFailedMigration(LauncherRestoreEventLogger restoreEventLogger,
|
||||
SQLiteDatabase db) {
|
||||
try (Cursor cursor = db.rawQuery(
|
||||
"SELECT itemType, COUNT(*) AS count FROM favorites GROUP BY itemType",
|
||||
null
|
||||
)) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
restoreEventLogger.logFavoritesItemsRestoreFailed(
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(ITEM_TYPE)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow("count")),
|
||||
RESTORE_ERROR_GRID_MIGRATION_FAILURE
|
||||
);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e(TAG, "sendMetricsForFailedDb: Error reading from database", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the underlying model database
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user