From e309dde0c5e55abaa7f74aa4f5cf85c7595d76e1 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 30 Dec 2024 11:57:45 +0530 Subject: [PATCH] Improved the scanning of ZIM files in the Play Store variant. * Excluded the scanning of other directories in the Play Store variant, as only app-specific directories can be accessed, making it unnecessary to include other directories in the scan. --- .../eu/mhutti1/utils/storage/StorageDeviceUtils.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt b/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt index b0d40ec6d..e2b56964d 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt @@ -22,6 +22,7 @@ import android.content.Context import android.content.ContextWrapper import android.os.Environment import androidx.core.content.ContextCompat +import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import java.io.File import java.io.FileFilter import java.io.RandomAccessFile @@ -34,10 +35,9 @@ object StorageDeviceUtils { @JvmStatic fun getReadableStorage(context: Context): List { + var sharedPreferenceUtil: SharedPreferenceUtil? = SharedPreferenceUtil(context) val storageDevices = ArrayList().apply { add(environmentDevices(context)) - addAll(externalMountPointDevices()) - addAll(externalFilesDirsDevices(context, false)) addAll(externalMediaFilesDirsDevices(context)) // Scan the app-specific directory as well because we have limitations in scanning // all directories on Android 11 and above in the Play Store variant. @@ -47,6 +47,15 @@ object StorageDeviceUtils { // Therefore, we need to explicitly include the app-specific directory for scanning. // See https://github.com/kiwix/kiwix-android/issues/3579 addAll(externalFilesDirsDevices(context, true)) + // Do not scan storage directories in the Play Store build on Android 11 and above. + // In the Play Store variant, we can only access app-specific directories, + // so scanning other directories is unnecessary, wastes resources, + // and increases the scanning time. + if (sharedPreferenceUtil?.isNotPlayStoreBuildWithAndroid11OrAbove() == true) { + addAll(externalMountPointDevices()) + addAll(externalFilesDirsDevices(context, false)) + } + sharedPreferenceUtil = null } return validate(storageDevices, false) }