You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SyncBroadcastReceiver in FileDisplayActivity Triggers Multiple Times Causing Repeated Directory Listing #14855
changed the title [-]SyncBroadcastReceiver in FileDisplayActivity Triggers Multiple Times Causing Repeated Directory Listing and UI Issues[/-][+]SyncBroadcastReceiver in FileDisplayActivity Triggers Multiple Times Causing Repeated Directory Listing[/+]on May 2, 2025
Given that we already have access to the current list of files in the local directory, we can calculate and compare the hash codes of both local and remote file lists. If the hash codes match, we can safely skip the synchronization process. If they differ, we proceed with the update.
This approach would result in a significant performance improvement. Even a single unnecessary folder update currently triggers a full directory listing, including database queries, thumbnail cache checks, and redundant rendering of thumbnails for each file.
Implementation Steps
Convert FileDisplayActivity.SyncBroadcastReceiver to Kotlin (First PR)
Refactor the logic for better readability, maintainability and performance.
**Introduce Hash Code Comparison (Second PR)**Implement the hash code comparison logic within FileDisplayActivity.SyncBroadcastReceiver.
Analyze SyncBroadcastReceiver Usage (Third PR)
Review the usage of FileDisplayActivity.SyncBroadcastReceiver throughout the codebase. Identify and remove any redundant or unnecessary triggers if it exists.
Better OCFileListAdapter implementation - this is big one and should be discussed in different issue
These steps will bring the Android implementation more in line with iOS in terms of performance and state management, and it's a noticeable user experience improvement.
For each change, we must validate the following functional areas:
Folder and file listing behavior
"Favorites", "Shared with you", "Personal", and "On-device files" filters.
General sync behavior such as folder sync, file download.
I believe we should prioritize this task.
@tobiasKaminsky@ZetaTom Please let me know if this approach is acceptable. I can start working on the first pull request.
As mentioned in #15081, these broadcast events may also cause other side effects. In the FileDisplayActivity, currentDir is sometimes null when rapidly switching between tabs (Files, Favourites and Media). This causes can cause issues, for example #15103.
Investigating this issue and minimising broadcast events should increase overall reliability and decrease and the number of UI glitches and edge cases we have to handle.
The listDirectory function inside OCFileListFragment is being called multiple times unnecessarily, even for the same directory. This results in the entire list being recreated over and over again.
There are many entry points triggering listDirectory, including:
onResume in FileDisplayActivity
onActivityCreated in OCFileListFragment
Broadcast receivers for download and upload completion
Sync receiver after a folder refresh operation
File deletion events, and others
I tried several approaches to prevent these redundant calls, but none have worked so far:
Comparing eTags: I compared the locally stored eTag with the result from CheckEtagOperation, but it always reports the eTag as changed. This might be caused by some database writes to OCFile that unintentionally affect the stored eTag.
Using OCFile.hashCode(): This also didn’t help. Even small changes (e.g., marking a file as favorite) modify a field in OCFile, which should be reflected in the UI. That means the entire list needs to be compared carefully, and missing even one field can lead to incorrect UI state.
Debouncing listDirectory calls: This approach feels unsafe. It could ignore legitimate user actions (like taps) and is too fragile to rely on as a solution.
Activity
[-]SyncBroadcastReceiver in FileDisplayActivity Triggers Multiple Times Causing Repeated Directory Listing and UI Issues[/-][+]SyncBroadcastReceiver in FileDisplayActivity Triggers Multiple Times Causing Repeated Directory Listing[/+]alperozturk96 commentedon Jun 6, 2025
Currently, the following code retrieves the path of the remote folder that needs to be synchronized:
String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);Subsequently, we fetch the list of remote files inside that folder with:
RemoteOperationResult synchResult = (RemoteOperationResult) DataHolderUtil.getInstance().retrieve(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));Given that we already have access to the current list of files in the local directory, we can calculate and compare the hash codes of both local and remote file lists. If the hash codes match, we can safely skip the synchronization process. If they differ, we proceed with the update.
This approach would result in a significant performance improvement. Even a single unnecessary folder update currently triggers a full directory listing, including database queries, thumbnail cache checks, and redundant rendering of thumbnails for each file.
Implementation Steps
Convert FileDisplayActivity.SyncBroadcastReceiver to Kotlin (First PR)
Refactor the logic for better readability, maintainability and performance.
**Introduce Hash Code Comparison (Second PR)**Implement the hash code comparison logic within FileDisplayActivity.SyncBroadcastReceiver.Analyze SyncBroadcastReceiver Usage (Third PR)
Review the usage of FileDisplayActivity.SyncBroadcastReceiver throughout the codebase. Identify and remove any redundant or unnecessary triggers if it exists.
Better OCFileListAdapter implementation - this is big one and should be discussed in different issue
These steps will bring the Android implementation more in line with iOS in terms of performance and state management, and it's a noticeable user experience improvement.
For each change, we must validate the following functional areas:
I believe we should prioritize this task.
@tobiasKaminsky @ZetaTom Please let me know if this approach is acceptable. I can start working on the first pull request.
alperozturk96 commentedon Jun 12, 2025
To prevent unnecessary calls, the following broadcast events should be reviewed.
After eliminating any redundant event triggers, we can explore alternative solutions if the issue persists.
alperozturk96 commentedon Jun 13, 2025
In the FileSyncAdapter.onPerformSync method, we currently send two broadcast events:
EVENT_FULL_SYNC_START is used to set mSyncInProgress boolean variables.
ZetaTom commentedon Jul 9, 2025
As mentioned in #15081, these broadcast events may also cause other side effects. In the
FileDisplayActivity,currentDiris sometimesnullwhen rapidly switching between tabs (Files, Favourites and Media). This causes can cause issues, for example #15103.Investigating this issue and minimising broadcast events should increase overall reliability and decrease and the number of UI glitches and edge cases we have to handle.
alperozturk96 commentedon Jul 10, 2025
Steps to reproduce the null
currentDirscenario:alperozturk96 commentedon Apr 20, 2026
The
listDirectoryfunction insideOCFileListFragmentis being called multiple times unnecessarily, even for the same directory. This results in the entire list being recreated over and over again.There are many entry points triggering
listDirectory, including:onResumeinFileDisplayActivityonActivityCreatedinOCFileListFragmentI tried several approaches to prevent these redundant calls, but none have worked so far:
Comparing eTags: I compared the locally stored eTag with the result from
CheckEtagOperation, but it always reports the eTag as changed. This might be caused by some database writes toOCFilethat unintentionally affect the stored eTag.Using
OCFile.hashCode(): This also didn’t help. Even small changes (e.g., marking a file as favorite) modify a field inOCFile, which should be reflected in the UI. That means the entire list needs to be compared carefully, and missing even one field can lead to incorrect UI state.Debouncing
listDirectorycalls: This approach feels unsafe. It could ignore legitimate user actions (like taps) and is too fragile to rely on as a solution.