From c0e9df6dd6f50aae681b5d403ec836951e17446d Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 16 Jan 2020 14:54:36 -0800 Subject: [PATCH] Removing some unnecessary LauncherProvider overrides Change-Id: Ia07919309bd4fe942af152881642fe24de9b00ee --- .../launcher3/model/BackupRestoreTest.java | 5 +- .../launcher3/util/LauncherModelHelper.java | 20 +++++- .../launcher3/util/TestLauncherProvider.java | 68 ------------------- 3 files changed, 23 insertions(+), 70 deletions(-) delete mode 100644 robolectric_tests/src/com/android/launcher3/util/TestLauncherProvider.java diff --git a/robolectric_tests/src/com/android/launcher3/model/BackupRestoreTest.java b/robolectric_tests/src/com/android/launcher3/model/BackupRestoreTest.java index 83b85994b1..6223760309 100644 --- a/robolectric_tests/src/com/android/launcher3/model/BackupRestoreTest.java +++ b/robolectric_tests/src/com/android/launcher3/model/BackupRestoreTest.java @@ -23,12 +23,14 @@ import static org.junit.Assert.assertTrue; import android.database.sqlite.SQLiteDatabase; +import com.android.launcher3.provider.RestoreDbTask; import com.android.launcher3.util.LauncherModelHelper; import com.android.launcher3.util.LauncherRoboTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.LooperMode; /** @@ -44,7 +46,8 @@ public class BackupRestoreTest { @Before public void setUp() { mModelHelper = new LauncherModelHelper(); - mDb = mModelHelper.provider.getDbWithRestoreDbTask(); + RestoreDbTask.setPending(RuntimeEnvironment.application, true); + mDb = mModelHelper.provider.getDb(); } @Test diff --git a/robolectric_tests/src/com/android/launcher3/util/LauncherModelHelper.java b/robolectric_tests/src/com/android/launcher3/util/LauncherModelHelper.java index 655055c9cf..e8b7157125 100644 --- a/robolectric_tests/src/com/android/launcher3/util/LauncherModelHelper.java +++ b/robolectric_tests/src/com/android/launcher3/util/LauncherModelHelper.java @@ -28,6 +28,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager.NameNotFoundException; +import android.database.sqlite.SQLiteDatabase; import android.net.Uri; import android.provider.Settings; @@ -276,6 +277,8 @@ public class LauncherModelHelper { Context context = RuntimeEnvironment.application; LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB); + LauncherSettings.Settings.call(context.getContentResolver(), + LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG); int[][][] ids = new int[typeArray.length][][]; for (int i = 0; i < typeArray.length; i++) { @@ -312,7 +315,6 @@ public class LauncherModelHelper { idp.numRows = idp.numColumns = idp.numHotseatIcons = DEFAULT_GRID_SIZE; idp.iconBitmapSize = DEFAULT_BITMAP_SIZE; - provider.setAllowLoadDefaultFavorites(true); Settings.Secure.putString(context.getContentResolver(), "launcher3.layout.provider", TEST_PROVIDER_AUTHORITY); @@ -340,4 +342,20 @@ public class LauncherModelHelper { filter.addCategory(Intent.CATEGORY_DEFAULT); spm.addIntentFilterForActivity(cn, filter); } + + /** + * An extension of LauncherProvider backed up by in-memory database. + */ + public static class TestLauncherProvider extends LauncherProvider { + + @Override + public boolean onCreate() { + return true; + } + + public SQLiteDatabase getDb() { + createDbIfNotExists(); + return mOpenHelper.getWritableDatabase(); + } + } } diff --git a/robolectric_tests/src/com/android/launcher3/util/TestLauncherProvider.java b/robolectric_tests/src/com/android/launcher3/util/TestLauncherProvider.java deleted file mode 100644 index 8ae65281de..0000000000 --- a/robolectric_tests/src/com/android/launcher3/util/TestLauncherProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.android.launcher3.util; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; - -import com.android.launcher3.LauncherProvider; -import com.android.launcher3.provider.RestoreDbTask; - -/** - * An extension of LauncherProvider backed up by in-memory database. - */ -public class TestLauncherProvider extends LauncherProvider { - - private boolean mAllowLoadDefaultFavorites; - - @Override - public boolean onCreate() { - return true; - } - - @Override - protected synchronized void createDbIfNotExists() { - if (mOpenHelper == null) { - mOpenHelper = new MyDatabaseHelper(getContext(), mAllowLoadDefaultFavorites); - } - } - - public void setAllowLoadDefaultFavorites(boolean allowLoadDefaultFavorites) { - mAllowLoadDefaultFavorites = allowLoadDefaultFavorites; - } - - public SQLiteDatabase getDb() { - createDbIfNotExists(); - return mOpenHelper.getWritableDatabase(); - } - - public SQLiteDatabase getDbWithRestoreDbTask() { - RestoreDbTask.setPending(getContext(), true); - super.createDbIfNotExists(); - return mOpenHelper.getWritableDatabase(); - } - - private static class MyDatabaseHelper extends DatabaseHelper { - - private final boolean mAllowLoadDefaultFavorites; - - MyDatabaseHelper(Context context, boolean allowLoadDefaultFavorites) { - super(context, null); - mAllowLoadDefaultFavorites = allowLoadDefaultFavorites; - initIds(); - } - - @Override - public long getDefaultUserSerial() { - return 0; - } - - @Override - protected void onEmptyDbCreated() { - if (mAllowLoadDefaultFavorites) { - super.onEmptyDbCreated(); - } - } - - @Override - protected void handleOneTimeDataUpgrade(SQLiteDatabase db) { } - } -}