From 3aca12437258b50557d00b4b4a7e0bf116890cbb Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 19 Nov 2022 16:24:38 +0100 Subject: [PATCH] fix updater issues --- .../com/github/libretube/services/UpdateService.kt | 11 ++++++++--- .../java/com/github/libretube/util/DownloadHelper.kt | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/services/UpdateService.kt b/app/src/main/java/com/github/libretube/services/UpdateService.kt index 8b3e566de..cc25c9e43 100644 --- a/app/src/main/java/com/github/libretube/services/UpdateService.kt +++ b/app/src/main/java/com/github/libretube/services/UpdateService.kt @@ -11,6 +11,7 @@ import android.os.Environment import android.os.IBinder import android.widget.Toast import com.github.libretube.R +import com.github.libretube.util.DownloadHelper import java.io.File class UpdateService : Service() { @@ -28,9 +29,7 @@ class UpdateService : Service() { } private fun downloadApk(downloadUrl: String) { - val dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) - // val dir = applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) - file = File(dir, "release.apk") + file = File(getDownloadDirectory(), "release.apk") val request: DownloadManager.Request = DownloadManager.Request(Uri.parse(downloadUrl)) @@ -80,6 +79,12 @@ class UpdateService : Service() { } } + private fun getDownloadDirectory(): File { + val downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + if (!downloadsDir.canWrite()) return DownloadHelper.getOfflineStorageDir(this) + return downloadsDir + } + override fun onDestroy() { unregisterReceiver(onDownloadComplete) super.onDestroy() diff --git a/app/src/main/java/com/github/libretube/util/DownloadHelper.kt b/app/src/main/java/com/github/libretube/util/DownloadHelper.kt index f5cb6e7a2..041452811 100644 --- a/app/src/main/java/com/github/libretube/util/DownloadHelper.kt +++ b/app/src/main/java/com/github/libretube/util/DownloadHelper.kt @@ -11,7 +11,7 @@ object DownloadHelper { const val METADATA_DIR = "metadata" const val THUMBNAIL_DIR = "thumbnail" - private fun getOfflineStorageDir(context: Context): File { + fun getOfflineStorageDir(context: Context): File { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return context.filesDir return try {