Skip to content

GenericCopyUtil improvements#4577

Open
TranceLove wants to merge 2 commits intoTeamAmaze:release/4.0from
TranceLove:feature/generic-copy-util-improvements
Open

GenericCopyUtil improvements#4577
TranceLove wants to merge 2 commits intoTeamAmaze:release/4.0from
TranceLove:feature/generic-copy-util-improvements

Conversation

@TranceLove
Copy link
Collaborator

Description

  • Convert to Kotlin for cleaner code
  • Removed use of deprecated @Theory in tests
  • Not limiting SDK versions, i.e. tests are run on all SDK versions
  • Bigger buffer size (1MB) for copy from/to OTG storage to increase robustness

Automatic tests

  • Added test cases

Manual tests

  • Done

Build tasks success

Successfully running following tasks on local:

  • ./gradlew assembledebug
  • ./gradlew spotlessCheck

@TranceLove TranceLove requested a review from Copilot March 1, 2026 16:31
@TranceLove TranceLove force-pushed the feature/generic-copy-util-improvements branch from a123ebc to 0cb5abf Compare March 1, 2026 16:33
@TranceLove TranceLove marked this pull request as ready for review March 1, 2026 16:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes GenericCopyUtil by migrating it (and its tests) from Java to Kotlin, while improving copy robustness/performance via larger transfer quanta and batched progress callbacks. It also replaces deprecated JUnit @Theory-based tests with explicit Kotlin test cases and adds new coverage for cancellation and progress batching.

Changes:

  • Replaced GenericCopyUtil Java implementation with a Kotlin version using FileChannel.transferTo for file-to-file copies and batched progress updates.
  • Replaced Java unit/instrumentation tests with Kotlin tests (no deprecated @Theory), adding more scenarios (empty file, cancellation, batching).
  • Increased transfer buffer quantum (1MB) for OTG/DocumentFile paths and channel-based copies.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
app/src/main/java/com/amaze/filemanager/filesystem/files/GenericCopyUtil.kt Kotlin rewrite; adds transferTo fast path + progress batching + 1MB transfer quantum.
app/src/main/java/com/amaze/filemanager/filesystem/files/GenericCopyUtil.java Removes old Java implementation.
app/src/test/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilTest.kt New Robolectric unit tests replacing @Theory, adding batching/cancellation coverage.
app/src/test/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilTest.java Removes old Java unit tests.
app/src/androidTest/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilEspressoTest.kt New instrumented tests in Kotlin, including batching/cancellation scenarios.
app/src/androidTest/java/com/amaze/filemanager/filesystem/files/GenericCopyUtilEspressoTest.java Removes old Java instrumented tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +422 to +429
while (position < size && !progressHandler.cancelled) {
val transferred = from.transferTo(position, DEFAULT_TRANSFER_QUANTUM.toLong(), to)
position += transferred
pendingProgress += transferred
if (pendingProgress >= PROGRESS_UPDATE_THRESHOLD) {
updatePosition.updatePosition(pendingProgress)
pendingProgress = 0L
}
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileChannel.transferTo() can legally return 0 even when position < size (e.g., platform/FS limitations). In the current loop this would leave position unchanged and can cause an infinite loop/hang. Add a guard for transferred <= 0 (break + fallback to the ByteBuffer path or throw an IOException) to guarantee progress.

Copilot uses AI. Check for mistakes.
@TranceLove TranceLove force-pushed the feature/generic-copy-util-improvements branch 4 times, most recently from 52dfe14 to 0368390 Compare March 3, 2026 23:43
- Convert to Kotlin
- More tests
- Bigger buffer size for copy from/to OTG storage
@TranceLove TranceLove force-pushed the feature/generic-copy-util-improvements branch from 0368390 to df0d36d Compare March 4, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants