[Android] Automatically delete the auto update APK file on startup

Nicolas Pomepuy git at videolan.org
Wed Jul 10 09:58:32 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jul  8 08:01:37 2024 +0200| [6ae8a7bb4dde46b01e7dcf09e29636ec266e74c4] | committer: Duncan McNamara

Automatically delete the auto update APK file on startup

> https://code.videolan.org/videolan/vlc-android/commit/6ae8a7bb4dde46b01e7dcf09e29636ec266e74c4
---

 .../src/main/java/org/videolan/television/ui/MainTvActivity.kt   | 1 +
 application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt | 1 +
 application/vlc-android/src/org/videolan/vlc/util/AutoUpdate.kt  | 9 +++++++++
 3 files changed, 11 insertions(+)

diff --git a/application/television/src/main/java/org/videolan/television/ui/MainTvActivity.kt b/application/television/src/main/java/org/videolan/television/ui/MainTvActivity.kt
index b45ce2d285..3eeabc68b8 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MainTvActivity.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MainTvActivity.kt
@@ -80,6 +80,7 @@ class MainTvActivity : BaseTvActivity(), StoragePermissionsDelegate.CustomAction
         browseFragment = fragmentManager.findFragmentById(R.id.browse_fragment) as MainTvFragment
         progressBar = findViewById(R.id.tv_main_progress)
         lifecycleScope.launch {
+            AutoUpdate.clean(this at MainTvActivity.application)
             if (!Settings.getInstance(this at MainTvActivity).getBoolean(KEY_SHOW_UPDATE, true)) return at launch
             AutoUpdate.checkUpdate(this at MainTvActivity.application) {url, date ->
                 val updateDialog = UpdateDialog().apply {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
index 8c10b9d4ca..d577d34a82 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
@@ -123,6 +123,7 @@ class MainActivity : ContentActivity(),
         }
 
         lifecycleScope.launch {
+            AutoUpdate.clean(this at MainActivity.application)
             if (!settings.getBoolean(KEY_SHOW_UPDATE, true)) return at launch
             AutoUpdate.checkUpdate(this at MainActivity.application) {url, date ->
                 val updateDialog = UpdateDialog().apply {
diff --git a/application/vlc-android/src/org/videolan/vlc/util/AutoUpdate.kt b/application/vlc-android/src/org/videolan/vlc/util/AutoUpdate.kt
index 4b09cb312d..05858637cb 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/AutoUpdate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/AutoUpdate.kt
@@ -178,5 +178,14 @@ object AutoUpdate {
         }
     }
 
+    suspend fun clean(context: Application) = withContext(Dispatchers.IO) {
+        try {
+            val downloadedFile = File(context.getCacheDir(), "update.apk")
+            if (downloadedFile.exists()) downloadedFile.delete() else { }
+        } catch (e: Exception) {
+            Log.e(TAG, e.message, e)
+        }
+    }
+
 
 }
\ No newline at end of file



More information about the Android mailing list