From 015f7cff7e93a49ae5cb84c0e64c923b48002dad Mon Sep 17 00:00:00 2001 From: venkyqz Date: Wed, 22 Apr 2026 21:23:55 +0800 Subject: [PATCH] Avoid SMB rename checks on the UI thread The rename completion path in MainActivityHelper re-checked success by calling newFile.exists(context) on the UI thread because SAF-backed renames can report false negatives. For SMB targets that fallback routes into HybridFile.exists() and performs synchronous network I/O on the main thread. Limit the fallback probe to SAF-backed targets and cover it with a focused regression test. Constraint: Preserve the post-rename verification workaround for SAF-backed rename targets Rejected: Change HybridFile.exists() semantics for all SMB callers | too broad and would affect background operations that legitimately rely on it Confidence: high Scope-risk: narrow Directive: Keep rename completion fallbacks off the UI thread for remote backends; only use exists(context) as a SAF-specific verification path Tested: ./gradlew :app:testFdroidDebugUnitTest --tests com.amaze.filemanager.utils.MainActivityHelperTest -x kaptFdroidDebugUnitTestKotlin Tested: ./gradlew :app:compileFdroidDebugJavaWithJavac Tested: ./gradlew :app:compileFdroidDebugUnitTestJavaWithJavac -x kaptFdroidDebugUnitTestKotlin Not-tested: Full :app:testFdroidDebugUnitTest (blocked by existing kaptFdroidDebugUnitTestKotlin failure in unrelated tests referencing missing ShadowMultiDex) --- .../java/com/amaze/filemanager/utils/MainActivityHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java b/app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java index a6010b06ad..3118784a22 100644 --- a/app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java +++ b/app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java @@ -388,7 +388,9 @@ public void done(final HybridFile hFile, final boolean b) { * DocumentFile.renameTo() may return false even when rename is successful. Hence we need an extra check * instead of merely looking at the return value */ - if (b || newFile.exists(context)) { + if (b + || ((newFile.isDocumentFile() || newFile.isOtgFile()) + && newFile.exists(context))) { Intent intent = new Intent(MainActivity.KEY_INTENT_LOAD_LIST); intent.putExtra(