Removing some unnecessary LauncherProvider overrides

Change-Id: Ia07919309bd4fe942af152881642fe24de9b00ee
This commit is contained in:
Sunny Goyal 2020-01-16 14:54:36 -08:00
parent 9be1cfde79
commit c0e9df6dd6
3 changed files with 23 additions and 70 deletions

View File

@ -23,12 +23,14 @@ import static org.junit.Assert.assertTrue;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.util.LauncherModelHelper; import com.android.launcher3.util.LauncherModelHelper;
import com.android.launcher3.util.LauncherRoboTestRunner; import com.android.launcher3.util.LauncherRoboTestRunner;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.LooperMode; import org.robolectric.annotation.LooperMode;
/** /**
@ -44,7 +46,8 @@ public class BackupRestoreTest {
@Before @Before
public void setUp() { public void setUp() {
mModelHelper = new LauncherModelHelper(); mModelHelper = new LauncherModelHelper();
mDb = mModelHelper.provider.getDbWithRestoreDbTask(); RestoreDbTask.setPending(RuntimeEnvironment.application, true);
mDb = mModelHelper.provider.getDb();
} }
@Test @Test

View File

@ -28,6 +28,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri; import android.net.Uri;
import android.provider.Settings; import android.provider.Settings;
@ -276,6 +277,8 @@ public class LauncherModelHelper {
Context context = RuntimeEnvironment.application; Context context = RuntimeEnvironment.application;
LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.call(context.getContentResolver(),
LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB); LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB);
LauncherSettings.Settings.call(context.getContentResolver(),
LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG);
int[][][] ids = new int[typeArray.length][][]; int[][][] ids = new int[typeArray.length][][];
for (int i = 0; i < typeArray.length; i++) { 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.numRows = idp.numColumns = idp.numHotseatIcons = DEFAULT_GRID_SIZE;
idp.iconBitmapSize = DEFAULT_BITMAP_SIZE; idp.iconBitmapSize = DEFAULT_BITMAP_SIZE;
provider.setAllowLoadDefaultFavorites(true);
Settings.Secure.putString(context.getContentResolver(), Settings.Secure.putString(context.getContentResolver(),
"launcher3.layout.provider", TEST_PROVIDER_AUTHORITY); "launcher3.layout.provider", TEST_PROVIDER_AUTHORITY);
@ -340,4 +342,20 @@ public class LauncherModelHelper {
filter.addCategory(Intent.CATEGORY_DEFAULT); filter.addCategory(Intent.CATEGORY_DEFAULT);
spm.addIntentFilterForActivity(cn, filter); 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();
}
}
} }

View File

@ -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) { }
}
}