Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cleanup requirement for storage permission #2442

Merged
merged 1 commit into from Nov 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -43,24 +43,6 @@ internal class LeakDirectoryProvider constructor(
) {
private val context: Context = context.applicationContext

fun listFiles(filter: FilenameFilter): MutableList<File> {
if (!hasStoragePermission() && requestExternalStoragePermission()) {
requestWritePermissionNotification()
}
val files = ArrayList<File>()

val externalFiles = externalStorageDirectory().listFiles(filter)
if (externalFiles != null) {
files.addAll(externalFiles)
}

val appFiles = appStorageDirectory().listFiles(filter)
if (appFiles != null) {
files.addAll(appFiles)
}
return files
}

fun newHeapDumpFile(): File? {
cleanupOldHeapDumps()

Expand Down Expand Up @@ -147,7 +129,7 @@ internal class LeakDirectoryProvider constructor(
}

private fun cleanupOldHeapDumps() {
val hprofFiles = listFiles { _, name ->
val hprofFiles = listWritableFiles { _, name ->
name.endsWith(
HPROF_SUFFIX
)
Expand Down Expand Up @@ -177,6 +159,24 @@ internal class LeakDirectoryProvider constructor(
}
}

private fun listWritableFiles(filter: FilenameFilter): MutableList<File> {
val files = ArrayList<File>()

val externalStorageDirectory = externalStorageDirectory()
if (externalStorageDirectory.exists() && externalStorageDirectory.canWrite()) {
val externalFiles = externalStorageDirectory.listFiles(filter)
if (externalFiles != null) {
files.addAll(externalFiles)
}
}

val appFiles = appStorageDirectory().listFiles(filter)
if (appFiles != null) {
files.addAll(appFiles)
}
return files
}

companion object {
@Volatile private var writeExternalStorageGranted: Boolean = false
@Volatile private var permissionNotificationDisplayed: Boolean = false
Expand Down