From 6fc2328475f4cad6be72166e26e4ba61e7dd639b Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sun, 10 Nov 2024 22:49:59 +0800 Subject: [PATCH] Fix false positive download failures on API 28 --- app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt b/app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt index 1fdb0e797..736635b9d 100644 --- a/app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt +++ b/app/src/main/kotlin/com/hippo/files/AndroidFileSystem.kt @@ -2,6 +2,7 @@ package com.hippo.files import android.content.Context import android.net.Uri +import android.os.Build import android.os.ParcelFileDescriptor import android.provider.DocumentsContract import android.provider.DocumentsContract.Document @@ -32,7 +33,13 @@ class AndroidFileSystem(context: Context) : FileSystem() { source.runCatching { DocumentsContract.renameDocument(contentResolver, toUri(), target.name) - }.getOrNull() ?: throw IOException("Failed to move $source to $target") + }.onFailure { + // ExternalStorageProvider always throw exception when renameDocument on API 28 + // https://android.googlesource.com/platform/frameworks/base/+/7bf90408e36613a84dc2a665905fde2c83cfa797 + if (Build.VERSION.SDK_INT != Build.VERSION_CODES.P) { + throw IOException("Failed to move $source to $target") + } + } } override fun canonicalize(path: Path): Path {