[Android] Reset the aout setting when migrating from VLC 3 to VLC 4

Nicolas Pomepuy git at videolan.org
Fri Nov 18 12:29:45 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Oct 28 09:00:52 2022 +0200| [49138b20195ef5948b7e76e43bcccd113dcbea18] | committer: Nicolas Pomepuy

Reset the aout setting when migrating from VLC 3 to VLC 4

> https://code.videolan.org/videolan/vlc-android/commit/49138b20195ef5948b7e76e43bcccd113dcbea18
---

 .../src/main/java/org/videolan/tools/Settings.kt   |  1 +
 .../src/org/videolan/vlc/util/VersionMigration.kt  | 23 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index e72459aa3b..0830f4e12f 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -70,6 +70,7 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicat
 }
 
 const val KEY_CURRENT_SETTINGS_VERSION = "current_settings_version"
+const val KEY_CURRENT_MAJOR_VERSION = "key_current_major_version"
 
 // Keys
 const val KEY_ARTISTS_SHOW_ALL = "artists_show_all"
diff --git a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
index a5dcf65029..451f796b82 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
@@ -37,6 +37,7 @@ import org.videolan.resources.AndroidDevices
 import org.videolan.resources.util.getFromMl
 import org.videolan.tools.*
 import org.videolan.vlc.gui.onboarding.ONBOARDING_DONE_KEY
+import org.videolan.vlc.isVLC4
 import java.io.File
 import java.io.IOException
 
@@ -44,9 +45,12 @@ private const val CURRENT_VERSION = 10
 
 object VersionMigration {
 
+    val currentMajorVersion = if (isVLC4()) 4 else 3
+
     suspend fun migrateVersion(context: Context) {
         val settings = Settings.getInstance(context)
         val lastVersion = settings.getInt(KEY_CURRENT_SETTINGS_VERSION, 0)
+        val lastMajorVersion = settings.getInt(KEY_CURRENT_MAJOR_VERSION, 3)
         if (lastVersion < 1) {
             migrateToVersion1(settings)
         }
@@ -80,7 +84,13 @@ object VersionMigration {
             migrateToVersion10(settings)
         }
 
+        //Major version upgrade
+        if (lastMajorVersion == 3 && currentMajorVersion == 4) {
+            migrateToVlc4(settings)
+        }
+
         settings.putSingle(KEY_CURRENT_SETTINGS_VERSION, CURRENT_VERSION)
+        settings.putSingle(KEY_CURRENT_MAJOR_VERSION, currentMajorVersion)
     }
 
     private fun migrateToVersion1(settings: SharedPreferences) {
@@ -240,4 +250,17 @@ object VersionMigration {
                 }
             }
     }
+
+    /**
+     * Migration to vlc 4
+     * ⚠️⚠️⚠️ This should not be destructive! Any first install will run this.
+     */
+    private fun migrateToVlc4(settings: SharedPreferences) {
+        Log.i(this::class.java.simpleName, "Migration to VLC 4")
+
+        // Removing the aout preference to choose aaudio by default
+        if (settings.contains("aout")) settings.edit(true) {
+            remove("aout")
+        }
+    }
 }
\ No newline at end of file



More information about the Android mailing list