Skip to content

Commit

Permalink
Added the 'testDirectory' to our scanning process, as on API level 33…
Browse files Browse the repository at this point in the history
…, 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.
  • Loading branch information
MohitMaliDeveloper committed Mar 18, 2024
1 parent 787672b commit 0c78b54
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c78b54

Please sign in to comment.