Skip to content

Commit

Permalink
Disable manual storage scanning
Browse files Browse the repository at this point in the history
Closes #28

When there are more than a few files on the SD Card, this can lead to a busy media scanner situation where any further calls to scan a file are scheduled to be executed after the initial scan is complete. As a result, simple actions like rename (which trigger a rescan) can take a long time to complete.

Originally added in SimpleMobileTools/Simple-File-Manager@4cca280 to fix issues related to stale SD Card stats but it doesn't seem necessary as per my testing.
  • Loading branch information
naveensingh committed Mar 15, 2024
1 parent 1a422ae commit 1966808
Showing 1 changed file with 0 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.app.usage.StorageStatsManager
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.media.MediaScannerConnection
import android.os.Handler
import android.os.Looper
import android.os.storage.StorageManager
Expand All @@ -33,7 +32,6 @@ import org.fossify.filemanager.extensions.getAllVolumeNames
import org.fossify.filemanager.helpers.*
import org.fossify.filemanager.interfaces.ItemOperationsListener
import org.fossify.filemanager.models.ListItem
import java.io.File
import java.util.Locale

class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment<MyViewPagerFragment.StorageInnerBinding>(context, attributeSet),
Expand Down Expand Up @@ -299,11 +297,6 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
volumeName = storageVolume.uuid!!.lowercase(Locale.US)
totalStorageSpace = file.totalSpace
freeStorageSpace = file.freeSpace
post {
ensureBackgroundThread {
scanVolume(volumeName, file)
}
}
}

post {
Expand All @@ -326,22 +319,6 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
}

private fun scanVolume(volumeName: String, root: File) {
val paths = mutableListOf<String>()
if (context.isPathOnSD(root.path)) {
File(context.sdCardPath).walkBottomUp().forEach {
paths.add(it.path)
}
}
var callbackCount = 0
MediaScannerConnection.scanFile(context, paths.toTypedArray(), null) { _, _ ->
callbackCount++
if (callbackCount == paths.size) {
getSizes(volumeName)
}
}
}

override fun searchQueryChanged(text: String) {
lastSearchedText = text
binding.apply {
Expand Down

0 comments on commit 1966808

Please sign in to comment.