From 1c12348cea2bedf81015f9c7573044ea68a4b2b6 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Fri, 23 Jun 2023 12:49:46 +0600 Subject: [PATCH] 1303-Pass_hardcoded_value_when_externalCacheDir_return_null issue: https://gitlab.e.foundation/e/os/backlog/-/issues/1303 sometimes `externalCacheDir` returns null/empty. On that case, we used to pass empty string. but we need externalCacheDir to let downloadManager to download & save file. downloadManager doesn't have access to `cacheDir`, so can't save file in it. On this case, we pass hardcoded externalCacheDir path value. --- .../main/java/foundation/e/apps/di/CommonUtilsModule.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/di/CommonUtilsModule.kt b/app/src/main/java/foundation/e/apps/di/CommonUtilsModule.kt index f868f978a..134d0edaa 100644 --- a/app/src/main/java/foundation/e/apps/di/CommonUtilsModule.kt +++ b/app/src/main/java/foundation/e/apps/di/CommonUtilsModule.kt @@ -35,6 +35,7 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent +import foundation.e.apps.BuildConfig import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob @@ -74,16 +75,18 @@ object CommonUtilsModule { } /** - * Path to application's external cache directory + * Path to application's external cache directory. + * ExternalCacheDir is required because we use downloadManager to download & save file. + * DownloadManager doesn't have access to cacheDir (which is app private). * @param context [Context] - * @return absolute path to cache directory or empty string if not available + * @return absolute path to cache directory or hardcoded string (/storage/emulated/0/Android/data//cache) if not available */ @Singleton @Provides @Named("cacheDir") fun provideCacheDir(@ApplicationContext context: Context): String { return context.externalCacheDir?.absolutePath.let { - if (it.isNullOrBlank()) "" else it + if (it.isNullOrBlank()) "/storage/emulated/0/Android/data/${BuildConfig.APPLICATION_ID}/cache" else it } } -- GitLab