From 0c78b54fcad83cf00ecd10600f7e98c7ed332538 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 18 Mar 2024 22:17:54 +0530 Subject: [PATCH] Added the 'testDirectory' to our scanning process, as on API level 33, the app-specific path is occasionally treated as READ_ONLY. Additionally, for certain test cases where we need to load the zim file in the LocalLibraryScreen, we've included the test directory in our scanning process, as it will be automatically handled by the OS. --- .../nav/destination/library/LocalLibraryTest.kt | 8 ++------ .../java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt | 7 ++----- .../java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt | 7 +++++++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt index 89d662880c..6c52365b61 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt @@ -18,7 +18,7 @@ package org.kiwix.kiwixmobile.nav.destination.library -import androidx.core.content.ContextCompat +import android.content.Context import androidx.core.content.edit import androidx.lifecycle.Lifecycle import androidx.preference.PreferenceManager @@ -86,11 +86,7 @@ class LocalLibraryTest : BaseActivityTest() { // load a zim file to test, After downloading zim file library list is visible or not val loadFileStream = LocalLibraryTest::class.java.classLoader.getResourceAsStream("testzim.zim") - val zimFile = - File( - ContextCompat.getExternalFilesDirs(context, null)[0], - "testzim.zim" - ) + val zimFile = File(context.getDir("testDir", Context.MODE_PRIVATE), "testzim.zim") if (zimFile.exists()) zimFile.delete() zimFile.createNewFile() loadFileStream.use { inputStream -> diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt index 4cb3b98fb3..94d20a9790 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt @@ -18,7 +18,7 @@ package org.kiwix.kiwixmobile.note -import androidx.core.content.ContextCompat +import android.content.Context import androidx.core.content.edit import androidx.core.net.toUri import androidx.lifecycle.Lifecycle @@ -92,10 +92,7 @@ class NoteFragmentTest : BaseActivityTest() { val loadFileStream = NoteFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim") - val zimFile = File( - ContextCompat.getExternalFilesDirs(context, null)[0], - "testzim.zim" - ) + val zimFile = File(context.getDir("testDir", Context.MODE_PRIVATE), "testzim.zim") if (zimFile.exists()) zimFile.delete() zimFile.createNewFile() loadFileStream.use { inputStream -> 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 d950840a19..53685d45cf 100644 --- a/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt +++ b/core/src/main/java/eu/mhutti1/utils/storage/StorageDeviceUtils.kt @@ -44,6 +44,10 @@ 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)) + + // added test directory to show the ZIM files stored in the test directory + // so that we can view and delete zim files inside this directory. + add(testDirectory(context)) } return validate(storageDevices, false) } @@ -77,6 +81,9 @@ object StorageDeviceUtils { Environment.isExternalStorageEmulated() ) + private fun testDirectory(context: Context) = + StorageDevice(context.getDir("testDir", Context.MODE_PRIVATE), true) + // Remove app specific path from directories so that we can search them from the top private fun generalisePath(path: String, writable: Boolean) = if (writable) path