Files
Lawnchair/tests/src/com/android/launcher3/model/FactitiousDbController.kt
T
Stefan Andonian e8b86db34d Robustly fixed issue where migration from different versions of DB data
tables was causing crashes upon grid size switching.

Bug: 304687723
Test: Verified behavior through unit test. Also manually tested that
factory resetting device -> adding shortcuts to the workspace ->
changing the grid size didn't cause any issues and resulted in normal
behavior.

Change-Id: I1945004d2c9a2d6f2b74d9597b39763ed4962e7b
2023-10-31 20:27:26 +00:00

61 lines
1.6 KiB
Kotlin

package com.android.launcher3.model
import android.content.Context
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import androidx.test.platform.app.InstrumentationRegistry
import java.io.BufferedReader
import java.io.InputStreamReader
private val All_COLUMNS =
arrayOf(
"_id",
"title",
"intent",
"container",
"screen",
"cellX",
"cellY",
"spanX",
"spanY",
"itemType",
"appWidgetId",
"icon",
"appWidgetProvider",
"modified",
"restored",
"profileId",
"rank",
"options",
"appWidgetSource"
)
class FactitiousDbController(context: Context, insertFile: String) : ModelDbController(context) {
val inMemoryDb: SQLiteDatabase by lazy {
SQLiteDatabase.createInMemory(SQLiteDatabase.OpenParams.Builder().build()).also { db ->
BufferedReader(
InputStreamReader(
InstrumentationRegistry.getInstrumentation().context.assets.open(insertFile)
)
)
.lines()
.forEach { sqlStatement -> db.execSQL(sqlStatement) }
}
}
override fun query(
table: String,
projection: Array<out String>?,
selection: String?,
selectionArgs: Array<out String>?,
sortOrder: String?
): Cursor {
return inMemoryDb.query(table, All_COLUMNS, selection, selectionArgs, null, null, sortOrder)
}
override fun loadDefaultFavoritesIfNecessary() {
// No-Op
}
}