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

Commit 873452ea authored by Amit Kumar's avatar Amit Kumar
Browse files

Add database migration to prevent crashes which occures if package has been...

Add database migration to prevent crashes which occures if package has been removed/replaced at boot-time or with an ota update.
parent 5e459f72
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,8 @@ public class Preferences {


    private static final String ACTION_USAGE = "foundation.e.blisslauncher.ACTION_USAGE";
    private static final String ACTION_USAGE = "foundation.e.blisslauncher.ACTION_USAGE";


    private static final String CURRENT_MIGRATION_VERSION = "current_migration_version";

    private Preferences() {
    private Preferences() {
    }
    }


@@ -338,6 +340,14 @@ public class Preferences {
        getPrefs(context).edit().putBoolean(NOTIFICATION_ACCESS, false).apply();
        getPrefs(context).edit().putBoolean(NOTIFICATION_ACCESS, false).apply();
    }
    }


    public static int getCurrentMigrationVersion(Context context){
        return getPrefs(context).getInt(CURRENT_MIGRATION_VERSION, 0);
    }

    public static void setCurrentMigrationVersion(Context context, int version){
        getPrefs(context).edit().putInt(CURRENT_MIGRATION_VERSION, version).apply();
    }

    public static SharedPreferences getPrefs(Context context) {
    public static SharedPreferences getPrefs(Context context) {
        return context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
        return context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    }
    }
+10 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,8 @@ public class Preferences {


    private static final String ACTION_USAGE = "foundation.e.blisslauncher.ACTION_USAGE";
    private static final String ACTION_USAGE = "foundation.e.blisslauncher.ACTION_USAGE";


    private static final String CURRENT_MIGRATION_VERSION = "current_migration_version";

    private Preferences() {
    private Preferences() {
    }
    }


@@ -338,6 +340,14 @@ public class Preferences {
        getPrefs(context).edit().putBoolean(NOTIFICATION_ACCESS, false).apply();
        getPrefs(context).edit().putBoolean(NOTIFICATION_ACCESS, false).apply();
    }
    }


    public static int getCurrentMigrationVersion(Context context){
        return getPrefs(context).getInt(CURRENT_MIGRATION_VERSION, 0);
    }

    public static void setCurrentMigrationVersion(Context context, int version){
        getPrefs(context).edit().putInt(CURRENT_MIGRATION_VERSION, version).apply();
    }

    public static SharedPreferences getPrefs(Context context) {
    public static SharedPreferences getPrefs(Context context) {
        return context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
        return context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    }
    }
+19 −0
Original line number Original line Diff line number Diff line
{
  "currentVersion": 1,
  "migrate_infos": [
    {
      "startVersion": 0,
      "endVersion": 1,
      "components": [
        {
          "old_component_name": "org.thoughtcrime.securesms/org.thoughtcrime.securesms.RoutingActivity",
          "new_component_name": "com.moez.QKSMS/com.moez.QKSMS.feature.main.MainActivity"
        },
        {
          "old_component_name": "org.lineageos.jelly/org.lineageos.jelly.MainActivity",
          "new_component_name": "foundation.e.browser/com.google.android.apps.chrome.Main"
        }
      ]
    }
  ]
}
 No newline at end of file
+8 −1
Original line number Original line Diff line number Diff line
@@ -100,4 +100,11 @@ public class DatabaseManager {
        mAppExecutors.diskIO().execute(
        mAppExecutors.diskIO().execute(
                () -> LauncherDB.getDatabase(mContext).launcherDao().deleteShortcut(name));
                () -> LauncherDB.getDatabase(mContext).launcherDao().deleteShortcut(name));
    }
    }

    // Already invoked in a disk io thread, so no need to execute in separate thread here.
    public void migrateComponent(String old_component_name, String new_component_name) {
        LauncherDB.getDatabase(mContext).launcherDao().delete(new_component_name);
        LauncherDB.getDatabase(mContext).launcherDao().updateComponent(old_component_name,
                new_component_name);
    }
}
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -28,4 +28,7 @@ public interface LauncherDao {
    @Query("DELETE FROM launcher_items WHERE title = :name and item_type = "
    @Query("DELETE FROM launcher_items WHERE title = :name and item_type = "
            + Constants.ITEM_TYPE_SHORTCUT)
            + Constants.ITEM_TYPE_SHORTCUT)
    void deleteShortcut(String name);
    void deleteShortcut(String name);

    @Query("UPDATE launcher_items SET item_id = :newComponentName WHERE item_id = :id")
    int updateComponent(String id, String newComponentName);
}
}
Loading