Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18698d09 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Mohammed Althaf T
Browse files

feat: Use existing dbhelper

parent a1cb5777
Loading
Loading
Loading
Loading
+2 −15
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ import android.os.UserHandle
import android.os.UserManager
import com.android.launcher3.InvariantDeviceProfile
import com.android.launcher3.LauncherProvider
import com.android.launcher3.LauncherSettings
import com.android.launcher3.LauncherSettings.Favorites.INTENT
import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT
@@ -44,20 +43,18 @@ object BlissDbUtils {
    private const val folderType = 2

    @JvmStatic
    fun migrateDataFromDb(context: Context): Boolean {
    fun migrateDataFromDb(context: Context, dbHelper: LauncherProvider.DatabaseHelper): Boolean {
        // Check if old database exists
        val oldFile = context.getDatabasePath(oldDbName)
        if (!oldFile.exists()) return false

        // Current database details
        val currentDbName = InvariantDeviceProfile.INSTANCE[context].dbFile
        val rowCount = InvariantDeviceProfile.INSTANCE[context].numRows
        val columnCount = InvariantDeviceProfile.INSTANCE[context].numColumns
        val numFolderRows = InvariantDeviceProfile.INSTANCE[context].numFolderRows
        val numFolderColumns = InvariantDeviceProfile.INSTANCE[context].numFolderColumns

        // Init database helper classes
        val dbHelper = LauncherProvider.DatabaseHelper(context, currentDbName, false)
        val oldDbHelper = BlissDbHelper(context, oldDbName)

        // Retrieve data from the old table
@@ -218,18 +215,10 @@ object BlissDbUtils {
            }
        }

        dbHelper.close()

        // Rename the database to old
        val newFile = context.getDatabasePath(oldDbName + "_old")
        oldFile.renameTo(newFile)

        // Update item id after migrating
        LauncherSettings.Settings.call(
            context.contentResolver,
            LauncherSettings.Settings.METHOD_UPDATE_ITEM_ID
        )

        return true
    }

@@ -265,14 +254,12 @@ object BlissDbUtils {
                        val widgetInfo = appWidgetManager.getAppWidgetInfo(id)

                        if (widgetInfo != null) {
                            var provider: ComponentName = widgetInfo.provider

                            widgetsInfoList.add(
                                WidgetItems(
                                    id,
                                    height,
                                    order,
                                    provider,
                                    widgetInfo.provider,
                                )
                            )
                        }
+2 −5
Original line number Diff line number Diff line
@@ -392,10 +392,6 @@ public class LauncherProvider extends ContentProvider {
                        mOpenHelper.generateNewItemId());
                return result;
            }
            case LauncherSettings.Settings.METHOD_UPDATE_ITEM_ID: {
                mOpenHelper.updateItemId();
                return null;
            }
            case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: {
                Bundle result = new Bundle();
                result.putInt(LauncherSettings.Settings.EXTRA_VALUE,
@@ -532,9 +528,10 @@ public class LauncherProvider extends ContentProvider {
    synchronized private void loadDefaultFavoritesIfNecessary() {
        SharedPreferences sp = LauncherPrefs.getPrefs(getContext());

        if (BlissDbUtils.migrateDataFromDb(getContext())) {
        if (BlissDbUtils.migrateDataFromDb(getContext(), mOpenHelper)) {
            copyTable(mOpenHelper.getReadableDatabase(), Favorites.TABLE_NAME_ALL,
                    mOpenHelper.getWritableDatabase(),Favorites.TABLE_NAME, getContext());
            mOpenHelper.updateItemId();
            clearFlagEmptyDbCreated();
            return;
        }
+0 −3
Original line number Diff line number Diff line
@@ -419,9 +419,6 @@ public class LauncherSettings {
        public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";

        public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id";

        public static final String METHOD_UPDATE_ITEM_ID = "update_item_id";

        public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";

        public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";