diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 22fd33e3e3f08c8611e9397b0a00548be3ebbafd..203c43b7a92f79fc4933415f7acb597eb6e1fc83 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -12,8 +12,8 @@ plugins { // Manifest version information val versionMajor = 1 -val versionMinor = 11 -val versionPatch = 0 +val versionMinor = 12 +val versionPatch = 2 val localProps = Properties() val localPropsFile = project.rootProject.file("local.properties") diff --git a/app/src/main/java/foundation/e/blisslauncher/core/Preferences.java b/app/src/main/java/foundation/e/blisslauncher/core/Preferences.java index 70e6db98d6bb7b0056677ac7f057090596476862..11e74fa80d1281da88307cba9c9b985bbdcdad0e 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/Preferences.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/Preferences.java @@ -54,6 +54,8 @@ public class Preferences { private static final String ADDED_ECLOUD_WIDGET = "added_ecloud_widget"; private static final String ADDED_PRIVACY_WIDGET = "added_privacy_widget"; + private static final String AP_MIGRATION_1 = "ap_migration_1"; + private Preferences() { } @@ -406,6 +408,18 @@ public class Preferences { getPrefs(context).edit().putBoolean(ADDED_PRIVACY_WIDGET, true).apply(); } + public static void setRemovedPrivacyWidget(Context context) { + getPrefs(context).edit().putBoolean(ADDED_PRIVACY_WIDGET, false).apply(); + } + + public static void setApMigration1Status(Context context, boolean status) { + getPrefs(context).edit().putBoolean(AP_MIGRATION_1, status).apply(); + } + + public static boolean getApMigration1Status(Context context) { + return getPrefs(context).getBoolean(AP_MIGRATION_1, false); + } + public static boolean getAddedPrivacyWidget(Context context) { return getPrefs(context).getBoolean(ADDED_PRIVACY_WIDGET, false); } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/tasks/LoadDatabaseTask.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/tasks/LoadDatabaseTask.java index 6225da2e85a36d3164be3dc9b3d61245384a12bf..640b1a2ae3f6e31a638b247421d02fbb7f716616 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/tasks/LoadDatabaseTask.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/tasks/LoadDatabaseTask.java @@ -5,6 +5,8 @@ import foundation.e.blisslauncher.core.database.LauncherDB; import foundation.e.blisslauncher.core.database.model.LauncherItem; import foundation.e.blisslauncher.core.migrate.Migration; import foundation.e.blisslauncher.features.launcher.AppProvider; +import foundation.e.blisslauncher.features.widgets.WidgetMigration; + import java.util.List; public class LoadDatabaseTask extends AsyncTask> { @@ -22,6 +24,7 @@ public class LoadDatabaseTask extends AsyncTask> @Override protected List doInBackground(Void... voids) { Migration.migrateSafely(mAppProvider.getContext()); + WidgetMigration.migrateAdvancedPrivacy(mAppProvider.getContext()); return LauncherDB.getDatabase(mAppProvider.getContext()).launcherDao().getAllItems(); } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetMigration.kt b/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetMigration.kt new file mode 100644 index 0000000000000000000000000000000000000000..6b3eedaca2646644f841acec8dc72a56a2992f6a --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/features/widgets/WidgetMigration.kt @@ -0,0 +1,50 @@ +package foundation.e.blisslauncher.features.widgets + +import android.appwidget.AppWidgetManager +import android.content.ComponentName +import android.content.Context +import foundation.e.blisslauncher.core.Preferences +import foundation.e.blisslauncher.core.database.LauncherDB +import foundation.e.blisslauncher.features.widgets.DefaultWidgets.privacyWidget +import timber.log.Timber + +object WidgetMigration { + @JvmStatic + fun migrateAdvancedPrivacy(context: Context) { + Timber.tag(TAG).d("Starting widget migration for Advanced Privacy") + val addedAp = Preferences.getAddedPrivacyWidget(context) + val oldComponent = + ComponentName("foundation.e.advancedprivacy", "foundation.e.privacycentralapp.Widget") + + val shouldMigrate = migrate(context, addedAp, oldComponent) + Timber.tag(TAG).d("Should migrate?: $shouldMigrate") + + if (shouldMigrate && !Preferences.getApMigration1Status(context)) { + Preferences.setRemovedPrivacyWidget(context) + Preferences.setApMigration1Status(context, true) + } + } + + private fun migrate(context: Context, isAdded: Boolean, oldComponent: ComponentName): Boolean { + val widgetDao = LauncherDB.getDatabase(context).widgetDao() + var containsInDB = false + + for (widget in widgetDao.all) { + val info = AppWidgetManager.getInstance(context).getAppWidgetInfo(widget.id) + Timber.tag(TAG).d("Widget Id: ${widget.id} | Widget info: $info") + + if (info != null && (info.provider == oldComponent || info.provider == privacyWidget)) { + Timber.tag(TAG).d("Migrating widget ${info.provider}") + containsInDB = true + } + } + + if (containsInDB && isAdded) { + Preferences.setApMigration1Status(context, true) + } + + return !containsInDB && isAdded + } + + private const val TAG = "WidgetMigration" +}