summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2023-05-09 19:06:45 +0000
committerSunny Goyal <sunnygoyal@google.com>2023-05-10 17:49:16 +0000
commitbca4e694f07ad76be5df639f52f345b0bb49d8ef (patch)
treeba35cb838a93c88bf15b9b8f018061fb8ce0c1e0 /tests
parentfb085e63934b1e3ffd1a71457a07e3a2c9ce8773 (diff)
downloadLauncher3-bca4e694f07ad76be5df639f52f345b0bb49d8ef.tar.gz
Revert "Revert "Revert "Revert "Changing GridMigrationTask to use ModelDbController directly""""
This reverts commit 3772b246c2971d93f1b64755dd9249efe4828af1. Reason for revert: Fixed the test failure Change-Id: Ibdc9e184fcb32c7caa4ab25d8753a46fa322b703
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/model/DbDowngradeHelperTest.java5
-rw-r--r--tests/src/com/android/launcher3/model/GridSizeMigrationUtilTest.kt275
-rw-r--r--tests/src/com/android/launcher3/model/LoaderCursorTest.java3
-rw-r--r--tests/src/com/android/launcher3/provider/LauncherDbUtilsTest.java6
-rw-r--r--tests/src/com/android/launcher3/provider/RestoreDbTaskTest.java84
-rw-r--r--tests/src/com/android/launcher3/util/LauncherModelHelper.java8
6 files changed, 226 insertions, 155 deletions
diff --git a/tests/src/com/android/launcher3/model/DbDowngradeHelperTest.java b/tests/src/com/android/launcher3/model/DbDowngradeHelperTest.java
index 0a1a9ba6a9..cea95e5a50 100644
--- a/tests/src/com/android/launcher3/model/DbDowngradeHelperTest.java
+++ b/tests/src/com/android/launcher3/model/DbDowngradeHelperTest.java
@@ -39,6 +39,7 @@ import androidx.test.platform.app.InstrumentationRegistry;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.R;
+import com.android.launcher3.pm.UserCache;
import org.junit.Before;
import org.junit.Test;
@@ -222,7 +223,9 @@ public class DbDowngradeHelperTest {
private class MyDatabaseHelper extends DatabaseHelper {
MyDatabaseHelper() {
- super(mContext, DB_FILE, false);
+ super(mContext, DB_FILE,
+ UserCache.INSTANCE.get(mContext)::getSerialNumberForUser,
+ () -> { });
}
@Override
diff --git a/tests/src/com/android/launcher3/model/GridSizeMigrationUtilTest.kt b/tests/src/com/android/launcher3/model/GridSizeMigrationUtilTest.kt
index f24f0dab76..63dbaa752d 100644
--- a/tests/src/com/android/launcher3/model/GridSizeMigrationUtilTest.kt
+++ b/tests/src/com/android/launcher3/model/GridSizeMigrationUtilTest.kt
@@ -15,6 +15,7 @@
*/
package com.android.launcher3.model
+import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.database.Cursor
@@ -23,6 +24,7 @@ import android.graphics.Point
import android.os.Process
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
+import androidx.test.platform.app.InstrumentationRegistry
import com.android.launcher3.InvariantDeviceProfile
import com.android.launcher3.LauncherPrefs
import com.android.launcher3.LauncherPrefs.Companion.WORKSPACE_SIZE
@@ -31,10 +33,7 @@ import com.android.launcher3.config.FeatureFlags
import com.android.launcher3.model.GridSizeMigrationUtil.DbReader
import com.android.launcher3.pm.UserCache
import com.android.launcher3.provider.LauncherDbUtils
-import com.android.launcher3.util.LauncherModelHelper
-import com.android.launcher3.util.LauncherModelHelper.*
import com.google.common.truth.Truth.assertThat
-import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -43,11 +42,12 @@ import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
class GridSizeMigrationUtilTest {
- private lateinit var modelHelper: LauncherModelHelper
+
private lateinit var context: Context
- private lateinit var db: SQLiteDatabase
private lateinit var validPackages: Set<String>
private lateinit var idp: InvariantDeviceProfile
+ private lateinit var dbHelper: DatabaseHelper
+ private lateinit var db: SQLiteDatabase
private val testPackage1 = "com.android.launcher3.validpackage1"
private val testPackage2 = "com.android.launcher3.validpackage2"
private val testPackage3 = "com.android.launcher3.validpackage3"
@@ -61,13 +61,17 @@ class GridSizeMigrationUtilTest {
@Before
fun setUp() {
- modelHelper = LauncherModelHelper()
- context = modelHelper.sandboxContext
- db = modelHelper.provider.db
+ context = InstrumentationRegistry.getInstrumentation().targetContext
+ dbHelper =
+ DatabaseHelper(
+ context,
+ null,
+ UserCache.INSTANCE.get(context)::getSerialNumberForUser
+ ) {}
+ db = dbHelper.writableDatabase
validPackages =
setOf(
- TEST_PACKAGE,
testPackage1,
testPackage2,
testPackage3,
@@ -86,11 +90,6 @@ class GridSizeMigrationUtilTest {
addTableToDb(db, userSerial, false, TMP_TABLE)
}
- @After
- fun tearDown() {
- modelHelper.destroy()
- }
-
/**
* Old migration logic, should be modified once [FeatureFlags.ENABLE_NEW_MIGRATION_LOGIC] is not
* needed anymore
@@ -99,26 +98,26 @@ class GridSizeMigrationUtilTest {
@Throws(Exception::class)
fun testMigration() {
// Src Hotseat icons
- modelHelper.addItem(APP_ICON, 0, HOTSEAT, 0, 0, testPackage1, 1, TMP_CONTENT_URI)
- modelHelper.addItem(SHORTCUT, 1, HOTSEAT, 0, 0, testPackage2, 2, TMP_CONTENT_URI)
- modelHelper.addItem(SHORTCUT, 3, HOTSEAT, 0, 0, testPackage3, 3, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 4, HOTSEAT, 0, 0, testPackage4, 4, TMP_CONTENT_URI)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_HOTSEAT, 0, 0, testPackage1, 1, TMP_TABLE)
+ addItem(ITEM_TYPE_SHORTCUT, 1, CONTAINER_HOTSEAT, 0, 0, testPackage2, 2, TMP_TABLE)
+ addItem(ITEM_TYPE_SHORTCUT, 3, CONTAINER_HOTSEAT, 0, 0, testPackage3, 3, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 4, CONTAINER_HOTSEAT, 0, 0, testPackage4, 4, TMP_TABLE)
// Src grid icons
// _ _ _ _ _
// _ _ _ _ 5
// _ _ 6 _ 7
// _ _ 8 _ 9
// _ _ _ _ _
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 4, 1, testPackage5, 5, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 2, 2, testPackage6, 6, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 4, 2, testPackage7, 7, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 2, 3, testPackage8, 8, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 4, 3, testPackage9, 9, TMP_CONTENT_URI)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 4, 1, testPackage5, 5, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 2, 2, testPackage6, 6, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 4, 2, testPackage7, 7, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 2, 3, testPackage8, 8, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 4, 3, testPackage9, 9, TMP_TABLE)
// Dest hotseat icons
- modelHelper.addItem(SHORTCUT, 1, HOTSEAT, 0, 0, testPackage2)
+ addItem(ITEM_TYPE_SHORTCUT, 1, CONTAINER_HOTSEAT, 0, 0, testPackage2)
// Dest grid icons
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 2, 2, testPackage10)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 2, 2, testPackage10)
idp.numDatabaseHotseatIcons = 4
idp.numColumns = 4
@@ -126,8 +125,7 @@ class GridSizeMigrationUtilTest {
val srcReader = DbReader(db, TMP_TABLE, context, validPackages)
val destReader = DbReader(db, TABLE_NAME, context, validPackages)
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
srcReader,
destReader,
idp.numDatabaseHotseatIcons,
@@ -138,12 +136,13 @@ class GridSizeMigrationUtilTest {
// Check hotseat items
var c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(SCREEN, INTENT),
"container=$CONTAINER_HOTSEAT",
null,
SCREEN,
+ null,
null
)
?: throw IllegalStateException()
@@ -168,12 +167,13 @@ class GridSizeMigrationUtilTest {
// Check workspace items
c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(CELLX, CELLY, INTENT),
"container=$CONTAINER_DESKTOP",
null,
null,
+ null,
null
)
?: throw IllegalStateException()
@@ -209,30 +209,30 @@ class GridSizeMigrationUtilTest {
fun testMigrationBackAndForth() {
// Hotseat items in grid A
// 1 2 _ 3 4
- modelHelper.addItem(APP_ICON, 0, HOTSEAT, 0, 0, testPackage1, 1, TMP_CONTENT_URI)
- modelHelper.addItem(SHORTCUT, 1, HOTSEAT, 0, 0, testPackage2, 2, TMP_CONTENT_URI)
- modelHelper.addItem(SHORTCUT, 3, HOTSEAT, 0, 0, testPackage3, 3, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 4, HOTSEAT, 0, 0, testPackage4, 4, TMP_CONTENT_URI)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_HOTSEAT, 0, 0, testPackage1, 1, TMP_TABLE)
+ addItem(ITEM_TYPE_SHORTCUT, 1, CONTAINER_HOTSEAT, 0, 0, testPackage2, 2, TMP_TABLE)
+ addItem(ITEM_TYPE_SHORTCUT, 3, CONTAINER_HOTSEAT, 0, 0, testPackage3, 3, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 4, CONTAINER_HOTSEAT, 0, 0, testPackage4, 4, TMP_TABLE)
// Workspace items in grid A
// _ _ _ _ _
// _ _ _ _ 5
// _ _ 6 _ 7
// _ _ 8 _ _
// _ _ _ _ _
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 4, 1, testPackage5, 5, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 2, 2, testPackage6, 6, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 4, 2, testPackage7, 7, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 2, 3, testPackage8, 8, TMP_CONTENT_URI)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 4, 1, testPackage5, 5, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 2, 2, testPackage6, 6, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 4, 2, testPackage7, 7, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 2, 3, testPackage8, 8, TMP_TABLE)
// Hotseat items in grid B
// 2 _ _ _
- modelHelper.addItem(SHORTCUT, 0, HOTSEAT, 0, 0, testPackage2)
+ addItem(ITEM_TYPE_SHORTCUT, 0, CONTAINER_HOTSEAT, 0, 0, testPackage2)
// Workspace items in grid B
// _ _ _ _
// _ _ _ 10
// _ _ _ _
// _ _ _ _
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 1, 3, testPackage10)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 1, 3, testPackage10)
idp.numDatabaseHotseatIcons = 4
idp.numColumns = 4
@@ -241,8 +241,7 @@ class GridSizeMigrationUtilTest {
val readerGridB = DbReader(db, TABLE_NAME, context, validPackages)
// migrate from A -> B
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
readerGridA,
readerGridB,
idp.numDatabaseHotseatIcons,
@@ -253,12 +252,13 @@ class GridSizeMigrationUtilTest {
// Check hotseat items in grid B
var c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(SCREEN, INTENT),
"container=$CONTAINER_HOTSEAT",
null,
SCREEN,
+ null,
null
)
?: throw IllegalStateException()
@@ -272,12 +272,13 @@ class GridSizeMigrationUtilTest {
// Check workspace items in grid B
c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(SCREEN, CELLX, CELLY, INTENT),
"container=$CONTAINER_DESKTOP",
null,
null,
+ null,
null
)
?: throw IllegalStateException()
@@ -294,12 +295,11 @@ class GridSizeMigrationUtilTest {
assertThat(locMap[testPackage8]).isEqualTo(Triple(0, 3, 1))
// add item in B
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 0, 2, testPackage9)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 0, 2, testPackage9)
// migrate from B -> A
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
readerGridB,
readerGridA,
5,
@@ -309,12 +309,13 @@ class GridSizeMigrationUtilTest {
)
// Check hotseat items in grid A
c =
- context.contentResolver.query(
- TMP_CONTENT_URI,
+ db.query(
+ TMP_TABLE,
arrayOf(SCREEN, INTENT),
"container=$CONTAINER_HOTSEAT",
null,
SCREEN,
+ null,
null
)
?: throw IllegalStateException()
@@ -328,12 +329,13 @@ class GridSizeMigrationUtilTest {
// Check workspace items in grid A
c =
- context.contentResolver.query(
- TMP_CONTENT_URI,
+ db.query(
+ TMP_TABLE,
arrayOf(SCREEN, CELLX, CELLY, INTENT),
"container=$CONTAINER_DESKTOP",
null,
null,
+ null,
null
)
?: throw IllegalStateException()
@@ -354,12 +356,11 @@ class GridSizeMigrationUtilTest {
assertThat(locMap[testPackage9]).isEqualTo(Triple(0, 0, 2))
// remove item from B
- modelHelper.deleteItem(7, TMP_TABLE)
+ db.delete(TMP_TABLE, "$_ID=7", null)
// migrate from A -> B
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
readerGridA,
readerGridB,
idp.numDatabaseHotseatIcons,
@@ -370,12 +371,13 @@ class GridSizeMigrationUtilTest {
// Check hotseat items in grid B
c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(SCREEN, INTENT),
"container=$CONTAINER_HOTSEAT",
null,
SCREEN,
+ null,
null
)
?: throw IllegalStateException()
@@ -389,12 +391,13 @@ class GridSizeMigrationUtilTest {
// Check workspace items in grid B
c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(SCREEN, CELLX, CELLY, INTENT),
"container=$CONTAINER_DESKTOP",
null,
null,
+ null,
null
)
?: throw IllegalStateException()
@@ -443,10 +446,28 @@ class GridSizeMigrationUtilTest {
fun migrateToLargerHotseat() {
val srcHotseatItems =
intArrayOf(
- modelHelper.addItem(APP_ICON, 0, HOTSEAT, 0, 0, testPackage1, 1, TMP_CONTENT_URI),
- modelHelper.addItem(SHORTCUT, 1, HOTSEAT, 0, 0, testPackage2, 2, TMP_CONTENT_URI),
- modelHelper.addItem(APP_ICON, 2, HOTSEAT, 0, 0, testPackage3, 3, TMP_CONTENT_URI),
- modelHelper.addItem(SHORTCUT, 3, HOTSEAT, 0, 0, testPackage4, 4, TMP_CONTENT_URI)
+ addItem(
+ ITEM_TYPE_APPLICATION,
+ 0,
+ CONTAINER_HOTSEAT,
+ 0,
+ 0,
+ testPackage1,
+ 1,
+ TMP_TABLE
+ ),
+ addItem(ITEM_TYPE_SHORTCUT, 1, CONTAINER_HOTSEAT, 0, 0, testPackage2, 2, TMP_TABLE),
+ addItem(
+ ITEM_TYPE_APPLICATION,
+ 2,
+ CONTAINER_HOTSEAT,
+ 0,
+ 0,
+ testPackage3,
+ 3,
+ TMP_TABLE
+ ),
+ addItem(ITEM_TYPE_SHORTCUT, 3, CONTAINER_HOTSEAT, 0, 0, testPackage4, 4, TMP_TABLE)
)
val numSrcDatabaseHotseatIcons = srcHotseatItems.size
idp.numDatabaseHotseatIcons = 6
@@ -455,8 +476,7 @@ class GridSizeMigrationUtilTest {
val srcReader = DbReader(db, TMP_TABLE, context, validPackages)
val destReader = DbReader(db, TABLE_NAME, context, validPackages)
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
srcReader,
destReader,
idp.numDatabaseHotseatIcons,
@@ -467,12 +487,13 @@ class GridSizeMigrationUtilTest {
// Check hotseat items
val c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(SCREEN, INTENT),
"container=$CONTAINER_HOTSEAT",
null,
SCREEN,
+ null,
null
)
?: throw IllegalStateException()
@@ -501,11 +522,11 @@ class GridSizeMigrationUtilTest {
@Test
fun migrateFromLargerHotseat() {
- modelHelper.addItem(APP_ICON, 0, HOTSEAT, 0, 0, testPackage1, 1, TMP_CONTENT_URI)
- modelHelper.addItem(SHORTCUT, 2, HOTSEAT, 0, 0, testPackage2, 2, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 3, HOTSEAT, 0, 0, testPackage3, 3, TMP_CONTENT_URI)
- modelHelper.addItem(SHORTCUT, 4, HOTSEAT, 0, 0, testPackage4, 4, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 5, HOTSEAT, 0, 0, testPackage5, 5, TMP_CONTENT_URI)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_HOTSEAT, 0, 0, testPackage1, 1, TMP_TABLE)
+ addItem(ITEM_TYPE_SHORTCUT, 2, CONTAINER_HOTSEAT, 0, 0, testPackage2, 2, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 3, CONTAINER_HOTSEAT, 0, 0, testPackage3, 3, TMP_TABLE)
+ addItem(ITEM_TYPE_SHORTCUT, 4, CONTAINER_HOTSEAT, 0, 0, testPackage4, 4, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 5, CONTAINER_HOTSEAT, 0, 0, testPackage5, 5, TMP_TABLE)
idp.numDatabaseHotseatIcons = 4
idp.numColumns = 4
@@ -513,8 +534,7 @@ class GridSizeMigrationUtilTest {
val srcReader = DbReader(db, TMP_TABLE, context, validPackages)
val destReader = DbReader(db, TABLE_NAME, context, validPackages)
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
srcReader,
destReader,
idp.numDatabaseHotseatIcons,
@@ -525,12 +545,13 @@ class GridSizeMigrationUtilTest {
// Check hotseat items
val c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(SCREEN, INTENT),
"container=$CONTAINER_HOTSEAT",
null,
SCREEN,
+ null,
null
)
?: throw IllegalStateException()
@@ -568,11 +589,11 @@ class GridSizeMigrationUtilTest {
enableNewMigrationLogic("4,4")
// Setup src grid
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 2, 2, testPackage1, 5, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 2, 3, testPackage2, 6, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 1, DESKTOP, 3, 1, testPackage3, 7, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 1, DESKTOP, 3, 2, testPackage4, 8, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 2, DESKTOP, 3, 3, testPackage5, 9, TMP_CONTENT_URI)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 2, 2, testPackage1, 5, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 2, 3, testPackage2, 6, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 1, CONTAINER_DESKTOP, 3, 1, testPackage3, 7, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 1, CONTAINER_DESKTOP, 3, 2, testPackage4, 8, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 2, CONTAINER_DESKTOP, 3, 3, testPackage5, 9, TMP_TABLE)
idp.numDatabaseHotseatIcons = 4
idp.numColumns = 6
@@ -581,8 +602,7 @@ class GridSizeMigrationUtilTest {
val srcReader = DbReader(db, TMP_TABLE, context, validPackages)
val destReader = DbReader(db, TABLE_NAME, context, validPackages)
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
srcReader,
destReader,
idp.numDatabaseHotseatIcons,
@@ -593,12 +613,13 @@ class GridSizeMigrationUtilTest {
// Get workspace items
val c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(INTENT, SCREEN),
"container=$CONTAINER_DESKTOP",
null,
null,
+ null,
null
)
?: throw IllegalStateException()
@@ -630,11 +651,11 @@ class GridSizeMigrationUtilTest {
enableNewMigrationLogic("2,2")
// Setup src grid
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 0, 1, testPackage1, 5, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 1, 1, testPackage2, 6, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 1, DESKTOP, 0, 0, testPackage3, 7, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 1, DESKTOP, 1, 0, testPackage4, 8, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 2, DESKTOP, 0, 0, testPackage5, 9, TMP_CONTENT_URI)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 0, 1, testPackage1, 5, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 1, 1, testPackage2, 6, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 1, CONTAINER_DESKTOP, 0, 0, testPackage3, 7, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 1, CONTAINER_DESKTOP, 1, 0, testPackage4, 8, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 2, CONTAINER_DESKTOP, 0, 0, testPackage5, 9, TMP_TABLE)
idp.numDatabaseHotseatIcons = 4
idp.numColumns = 5
@@ -642,8 +663,7 @@ class GridSizeMigrationUtilTest {
val srcReader = DbReader(db, TMP_TABLE, context, validPackages)
val destReader = DbReader(db, TABLE_NAME, context, validPackages)
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
srcReader,
destReader,
idp.numDatabaseHotseatIcons,
@@ -654,12 +674,13 @@ class GridSizeMigrationUtilTest {
// Get workspace items
val c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(INTENT, SCREEN),
"container=$CONTAINER_DESKTOP",
null,
null,
+ null,
null
)
?: throw IllegalStateException()
@@ -691,11 +712,11 @@ class GridSizeMigrationUtilTest {
enableNewMigrationLogic("5,5")
// Setup src grid
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 0, 1, testPackage1, 5, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 0, DESKTOP, 1, 1, testPackage2, 6, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 1, DESKTOP, 0, 0, testPackage3, 7, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 1, DESKTOP, 1, 0, testPackage4, 8, TMP_CONTENT_URI)
- modelHelper.addItem(APP_ICON, 2, DESKTOP, 0, 0, testPackage5, 9, TMP_CONTENT_URI)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 0, 1, testPackage1, 5, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 0, CONTAINER_DESKTOP, 1, 1, testPackage2, 6, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 1, CONTAINER_DESKTOP, 0, 0, testPackage3, 7, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 1, CONTAINER_DESKTOP, 1, 0, testPackage4, 8, TMP_TABLE)
+ addItem(ITEM_TYPE_APPLICATION, 2, CONTAINER_DESKTOP, 0, 0, testPackage5, 9, TMP_TABLE)
idp.numDatabaseHotseatIcons = 4
idp.numColumns = 4
@@ -703,8 +724,7 @@ class GridSizeMigrationUtilTest {
val srcReader = DbReader(db, TMP_TABLE, context, validPackages)
val destReader = DbReader(db, TABLE_NAME, context, validPackages)
GridSizeMigrationUtil.migrate(
- context,
- db,
+ dbHelper,
srcReader,
destReader,
idp.numDatabaseHotseatIcons,
@@ -715,12 +735,13 @@ class GridSizeMigrationUtilTest {
// Get workspace items
val c =
- context.contentResolver.query(
- CONTENT_URI,
+ db.query(
+ TABLE_NAME,
arrayOf(INTENT, SCREEN),
"container=$CONTAINER_DESKTOP",
null,
null,
+ null,
null
)
?: throw IllegalStateException()
@@ -747,4 +768,48 @@ class GridSizeMigrationUtilTest {
private fun enableNewMigrationLogic(srcGridSize: String) {
LauncherPrefs.get(context).putSync(WORKSPACE_SIZE.to(srcGridSize))
}
+
+ private fun addItem(
+ type: Int,
+ screen: Int,
+ container: Int,
+ x: Int,
+ y: Int,
+ packageName: String?
+ ): Int {
+ return addItem(
+ type,
+ screen,
+ container,
+ x,
+ y,
+ packageName,
+ dbHelper.generateNewItemId(),
+ TABLE_NAME
+ )
+ }
+
+ private fun addItem(
+ type: Int,
+ screen: Int,
+ container: Int,
+ x: Int,
+ y: Int,
+ packageName: String?,
+ id: Int,
+ tableName: String
+ ): Int {
+ val values = ContentValues()
+ values.put(_ID, id)
+ values.put(CONTAINER, container)
+ values.put(SCREEN, screen)
+ values.put(CELLX, x)
+ values.put(CELLY, y)
+ values.put(SPANX, 1)
+ values.put(SPANY, 1)
+ values.put(ITEM_TYPE, type)
+ values.put(INTENT, Intent(Intent.ACTION_MAIN).setPackage(packageName).toUri(0))
+ db.insert(tableName, null, values)
+ return id
+ }
}
diff --git a/tests/src/com/android/launcher3/model/LoaderCursorTest.java b/tests/src/com/android/launcher3/model/LoaderCursorTest.java
index d192be408c..78812c0778 100644
--- a/tests/src/com/android/launcher3/model/LoaderCursorTest.java
+++ b/tests/src/com/android/launcher3/model/LoaderCursorTest.java
@@ -59,7 +59,6 @@ import androidx.test.filters.SmallTest;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
-import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.util.Executors;
@@ -102,7 +101,7 @@ public class LoaderCursorTest {
});
UserManagerState ums = new UserManagerState();
- mLoaderCursor = new LoaderCursor(mCursor, Favorites.CONTENT_URI, mApp, ums);
+ mLoaderCursor = new LoaderCursor(mCursor, mApp, ums);
ums.allUsers.put(0, Process.myUserHandle());
}
diff --git a/tests/src/com/android/launcher3/provider/LauncherDbUtilsTest.java b/tests/src/com/android/launcher3/provider/LauncherDbUtilsTest.java
index 2b6f9ff193..54b8489134 100644
--- a/tests/src/com/android/launcher3/provider/LauncherDbUtilsTest.java
+++ b/tests/src/com/android/launcher3/provider/LauncherDbUtilsTest.java
@@ -45,6 +45,7 @@ import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.R;
import com.android.launcher3.model.DatabaseHelper;
import com.android.launcher3.model.DbDowngradeHelper;
+import com.android.launcher3.pm.UserCache;
import com.android.launcher3.settings.SettingsActivity;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.IOUtils;
@@ -165,12 +166,11 @@ public class LauncherDbUtilsTest {
private class MyDatabaseHelper extends DatabaseHelper {
MyDatabaseHelper() {
- super(mContext, null, false);
+ super(mContext, null, UserCache.INSTANCE.get(mContext)::getSerialNumberForUser,
+ () -> { });
}
@Override
protected void handleOneTimeDataUpgrade(SQLiteDatabase db) { }
-
- protected void onEmptyDbCreated() { }
}
}
diff --git a/tests/src/com/android/launcher3/provider/RestoreDbTaskTest.java b/tests/src/com/android/launcher3/provider/RestoreDbTaskTest.java
index 67de1f5fb1..73bb5865ee 100644
--- a/tests/src/com/android/launcher3/provider/RestoreDbTaskTest.java
+++ b/tests/src/com/android/launcher3/provider/RestoreDbTaskTest.java
@@ -45,8 +45,11 @@ import androidx.test.filters.SmallTest;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings.Favorites;
-import com.android.launcher3.model.DatabaseHelper;
+import com.android.launcher3.model.ModelDbController;
+import com.android.launcher3.util.LauncherModelHelper;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -61,15 +64,29 @@ public class RestoreDbTaskTest {
private final UserHandle mWorkUser = UserHandle.getUserHandleForUid(PER_USER_RANGE);
+ private LauncherModelHelper mModelHelper;
+ private Context mContext;
+
+ @Before
+ public void setup() {
+ mModelHelper = new LauncherModelHelper();
+ mContext = mModelHelper.sandboxContext;
+ }
+
+ @After
+ public void teardown() {
+ mModelHelper.destroy();
+ }
+
@Test
public void testGetProfileId() throws Exception {
- SQLiteDatabase db = new MyDatabaseHelper(23).getWritableDatabase();
+ SQLiteDatabase db = new MyModelDbController(23).getDb();
assertEquals(23, new RestoreDbTask().getDefaultProfileId(db));
}
@Test
public void testMigrateProfileId() throws Exception {
- SQLiteDatabase db = new MyDatabaseHelper(42).getWritableDatabase();
+ SQLiteDatabase db = new MyModelDbController(42).getDb();
// Add some mock data
for (int i = 0; i < 5; i++) {
ContentValues values = new ContentValues();
@@ -89,7 +106,7 @@ public class RestoreDbTaskTest {
@Test
public void testChangeDefaultColumn() throws Exception {
- SQLiteDatabase db = new MyDatabaseHelper(42).getWritableDatabase();
+ SQLiteDatabase db = new MyModelDbController(42).getDb();
// Add some mock data
for (int i = 0; i < 5; i++) {
ContentValues values = new ContentValues();
@@ -112,28 +129,27 @@ public class RestoreDbTaskTest {
@Test
public void testSanitizeDB_bothProfiles() throws Exception {
- Context context = getInstrumentation().getTargetContext();
UserHandle myUser = myUserHandle();
- long myProfileId = context.getSystemService(UserManager.class)
+ long myProfileId = mContext.getSystemService(UserManager.class)
.getSerialNumberForUser(myUser);
long myProfileId_old = myProfileId + 1;
long workProfileId = myProfileId + 2;
long workProfileId_old = myProfileId + 3;
- MyDatabaseHelper helper = new MyDatabaseHelper(myProfileId);
- SQLiteDatabase db = helper.getWritableDatabase();
- BackupManager bm = spy(new BackupManager(context));
+ MyModelDbController controller = new MyModelDbController(myProfileId);
+ SQLiteDatabase db = controller.getDb();
+ BackupManager bm = spy(new BackupManager(mContext));
doReturn(myUserHandle()).when(bm).getUserForAncestralSerialNumber(eq(myProfileId_old));
doReturn(mWorkUser).when(bm).getUserForAncestralSerialNumber(eq(workProfileId_old));
- helper.users.put(workProfileId, mWorkUser);
+ controller.users.put(workProfileId, mWorkUser);
- addIconsBulk(helper, 10, 1, myProfileId_old);
- addIconsBulk(helper, 6, 2, workProfileId_old);
+ addIconsBulk(controller, 10, 1, myProfileId_old);
+ addIconsBulk(controller, 6, 2, workProfileId_old);
assertEquals(10, getItemCountForProfile(db, myProfileId_old));
assertEquals(6, getItemCountForProfile(db, workProfileId_old));
RestoreDbTask task = new RestoreDbTask();
- task.sanitizeDB(context, helper, helper.getWritableDatabase(), bm);
+ task.sanitizeDB(mContext, controller, controller.getDb(), bm);
// All the data has been migrated to the new user ids
assertEquals(0, getItemCountForProfile(db, myProfileId_old));
@@ -144,27 +160,26 @@ public class RestoreDbTaskTest {
@Test
public void testSanitizeDB_workItemsRemoved() throws Exception {
- Context context = getInstrumentation().getTargetContext();
UserHandle myUser = myUserHandle();
- long myProfileId = context.getSystemService(UserManager.class)
+ long myProfileId = mContext.getSystemService(UserManager.class)
.getSerialNumberForUser(myUser);
long myProfileId_old = myProfileId + 1;
long workProfileId_old = myProfileId + 3;
- MyDatabaseHelper helper = new MyDatabaseHelper(myProfileId);
- SQLiteDatabase db = helper.getWritableDatabase();
- BackupManager bm = spy(new BackupManager(context));
+ MyModelDbController controller = new MyModelDbController(myProfileId);
+ SQLiteDatabase db = controller.getDb();
+ BackupManager bm = spy(new BackupManager(mContext));
doReturn(myUserHandle()).when(bm).getUserForAncestralSerialNumber(eq(myProfileId_old));
// Work profile is not migrated
doReturn(null).when(bm).getUserForAncestralSerialNumber(eq(workProfileId_old));
- addIconsBulk(helper, 10, 1, myProfileId_old);
- addIconsBulk(helper, 6, 2, workProfileId_old);
+ addIconsBulk(controller, 10, 1, myProfileId_old);
+ addIconsBulk(controller, 6, 2, workProfileId_old);
assertEquals(10, getItemCountForProfile(db, myProfileId_old));
assertEquals(6, getItemCountForProfile(db, workProfileId_old));
RestoreDbTask task = new RestoreDbTask();
- task.sanitizeDB(context, helper, helper.getWritableDatabase(), bm);
+ task.sanitizeDB(mContext, controller, controller.getDb(), bm);
// All the data has been migrated to the new user ids
assertEquals(0, getItemCountForProfile(db, myProfileId_old));
@@ -173,12 +188,13 @@ public class RestoreDbTaskTest {
assertEquals(10, getCount(db, "select * from favorites"));
}
- private void addIconsBulk(DatabaseHelper helper, int count, int screen, long profileId) {
- int columns = LauncherAppState.getIDP(getInstrumentation().getTargetContext()).numColumns;
+ private void addIconsBulk(MyModelDbController controller,
+ int count, int screen, long profileId) {
+ int columns = LauncherAppState.getIDP(mContext).numColumns;
String packageName = getInstrumentation().getContext().getPackageName();
for (int i = 0; i < count; i++) {
ContentValues values = new ContentValues();
- values.put(LauncherSettings.Favorites._ID, helper.generateNewItemId());
+ values.put(LauncherSettings.Favorites._ID, controller.generateNewItemId());
values.put(LauncherSettings.Favorites.CONTAINER, CONTAINER_DESKTOP);
values.put(LauncherSettings.Favorites.SCREEN, screen);
values.put(LauncherSettings.Favorites.CELLX, i % columns);
@@ -189,11 +205,11 @@ public class RestoreDbTaskTest {
values.put(LauncherSettings.Favorites.ITEM_TYPE, ITEM_TYPE_APPLICATION);
values.put(LauncherSettings.Favorites.INTENT,
new Intent(Intent.ACTION_MAIN).setPackage(packageName).toUri(0));
- helper.getWritableDatabase().insert(TABLE_NAME, null, values);
+
+ controller.insert(TABLE_NAME, values);
}
}
-
@Test
public void testRemoveScreenIdGaps_firstScreenEmpty() {
runRemoveScreenIdGapsTest(
@@ -216,7 +232,7 @@ public class RestoreDbTaskTest {
}
private void runRemoveScreenIdGapsTest(int[] screenIds, int[] expectedScreenIds) {
- SQLiteDatabase db = new MyDatabaseHelper(42).getWritableDatabase();
+ SQLiteDatabase db = new MyModelDbController(42).getDb();
// Add some mock data
for (int i = 0; i < screenIds.length; i++) {
ContentValues values = new ContentValues();
@@ -254,13 +270,12 @@ public class RestoreDbTaskTest {
}
}
- private class MyDatabaseHelper extends DatabaseHelper {
+ private class MyModelDbController extends ModelDbController {
- public final LongSparseArray<UserHandle> users;
+ public final LongSparseArray<UserHandle> users = new LongSparseArray<>();
- MyDatabaseHelper(long profileId) {
- super(getInstrumentation().getTargetContext(), null, false);
- users = new LongSparseArray<>();
+ MyModelDbController(long profileId) {
+ super(mContext);
users.put(profileId, myUserHandle());
}
@@ -269,10 +284,5 @@ public class RestoreDbTaskTest {
int index = users.indexOfValue(user);
return index >= 0 ? users.keyAt(index) : -1;
}
-
- @Override
- protected void handleOneTimeDataUpgrade(SQLiteDatabase db) { }
-
- protected void onEmptyDbCreated() { }
}
}
diff --git a/tests/src/com/android/launcher3/util/LauncherModelHelper.java b/tests/src/com/android/launcher3/util/LauncherModelHelper.java
index bf31e39ccc..6fca965600 100644
--- a/tests/src/com/android/launcher3/util/LauncherModelHelper.java
+++ b/tests/src/com/android/launcher3/util/LauncherModelHelper.java
@@ -363,12 +363,6 @@ public class LauncherModelHelper {
sandboxContext.getContentResolver().insert(contentUri, values);
}
- public void deleteItem(int itemId, @NonNull final String tableName) {
- final Uri uri = Uri.parse("content://"
- + LauncherProvider.AUTHORITY + "/" + tableName + "/" + itemId);
- sandboxContext.getContentResolver().delete(uri, null, null);
- }
-
/**
* Sets up a mock provider to load the provided layout by default, next time the layout loads
*/
@@ -426,7 +420,7 @@ public class LauncherModelHelper {
}
public SQLiteDatabase getDb() {
- return getModelDbController().getDatabaseHelper().getWritableDatabase();
+ return getModelDbController().getDb();
}
}