mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 08:16:49 +00:00
Removing all usage of LauncherProvider
Also fixing a race condition in model when an item update/delete task gets queued and executed after the model has reloaded (making the old data obsolete) Bug: 277345535 Bug: 263079498 Test: Presubmit Flag: N/A Change-Id: Ibd4bdbb3eece05b38b73a22a4be5f368df3754f0
This commit is contained in:
@@ -37,7 +37,6 @@ import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
@@ -85,6 +84,7 @@ public class ModelDbController {
|
||||
private static final String TAG = "LauncherProvider";
|
||||
|
||||
private static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED";
|
||||
public static final String EXTRA_DB_NAME = "db_name";
|
||||
|
||||
protected DatabaseHelper mOpenHelper;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class ModelDbController {
|
||||
table, projection, selection, selectionArgs, null, null, sortOrder);
|
||||
|
||||
final Bundle extra = new Bundle();
|
||||
extra.putString(LauncherSettings.Settings.EXTRA_DB_NAME, mOpenHelper.getDatabaseName());
|
||||
extra.putString(EXTRA_DB_NAME, mOpenHelper.getDatabaseName());
|
||||
result.setExtras(extra);
|
||||
return result;
|
||||
}
|
||||
@@ -161,28 +161,6 @@ public class ModelDbController {
|
||||
return rowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to insert but for adding multiple values in a transaction.
|
||||
*/
|
||||
@WorkerThread
|
||||
public int bulkInsert(String table, ContentValues[] values) {
|
||||
createDbIfNotExists();
|
||||
|
||||
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
try (SQLiteTransaction t = new SQLiteTransaction(db)) {
|
||||
int numValues = values.length;
|
||||
for (int i = 0; i < numValues; i++) {
|
||||
addModifiedTime(values[i]);
|
||||
if (mOpenHelper.dbInsertAndCheck(db, table, values[i]) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
onAddOrDeleteOp(db);
|
||||
t.commit();
|
||||
}
|
||||
return values.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refer {@link SQLiteDatabase#delete(String, String, String[])}
|
||||
*/
|
||||
@@ -191,10 +169,6 @@ public class ModelDbController {
|
||||
createDbIfNotExists();
|
||||
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
|
||||
if (Binder.getCallingPid() != Process.myPid()
|
||||
&& Favorites.TABLE_NAME.equalsIgnoreCase(table)) {
|
||||
mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
|
||||
}
|
||||
int count = db.delete(table, selection, selectionArgs);
|
||||
if (count > 0) {
|
||||
onAddOrDeleteOp(db);
|
||||
@@ -250,6 +224,7 @@ public class ModelDbController {
|
||||
public void createEmptyDB() {
|
||||
createDbIfNotExists();
|
||||
mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
|
||||
LauncherPrefs.get(mContext).putSync(getEmptyDbCreatedKey().to(true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,6 +279,10 @@ public class ModelDbController {
|
||||
*/
|
||||
private boolean migrateGridIfNeeded() {
|
||||
createDbIfNotExists();
|
||||
if (LauncherPrefs.get(mContext).get(getEmptyDbCreatedKey())) {
|
||||
// If we have already create a new DB, ignore migration
|
||||
return false;
|
||||
}
|
||||
InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
|
||||
if (!GridSizeMigrationUtil.needsToMigrate(mContext, idp)) {
|
||||
return true;
|
||||
@@ -374,7 +353,7 @@ public class ModelDbController {
|
||||
}
|
||||
|
||||
private void clearFlagEmptyDbCreated() {
|
||||
LauncherPrefs.get(mContext).removeSync(getEmptyDbCreatedKey(mOpenHelper.getDatabaseName()));
|
||||
LauncherPrefs.get(mContext).removeSync(getEmptyDbCreatedKey());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,7 +367,7 @@ public class ModelDbController {
|
||||
public synchronized void loadDefaultFavoritesIfNecessary() {
|
||||
createDbIfNotExists();
|
||||
|
||||
if (LauncherPrefs.get(mContext).get(getEmptyDbCreatedKey(mOpenHelper.getDatabaseName()))) {
|
||||
if (LauncherPrefs.get(mContext).get(getEmptyDbCreatedKey())) {
|
||||
Log.d(TAG, "loading default workspace");
|
||||
|
||||
LauncherWidgetHolder widgetHolder = mOpenHelper.newLauncherWidgetHolder();
|
||||
@@ -507,6 +486,10 @@ public class ModelDbController {
|
||||
mOpenHelper, mContext.getResources(), defaultLayout);
|
||||
}
|
||||
|
||||
private ConstantItem<Boolean> getEmptyDbCreatedKey() {
|
||||
return getEmptyDbCreatedKey(mOpenHelper.getDatabaseName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-composite given key in respect to database. If the current db is
|
||||
* {@link LauncherFiles#LAUNCHER_DB}, return the key as-is. Otherwise append the db name to
|
||||
|
||||
Reference in New Issue
Block a user