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

BugFix - NetworkOnMainThreadException: FileDataStorageManager.saveFileWithParent #14268

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alperozturk96
Copy link
Collaborator

@alperozturk96 alperozturk96 commented Dec 30, 2024

  • Tests written, or not not needed

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

Attention: Patch coverage is 39.28571% with 17 lines in your changes missing coverage. Please review.

Project coverage is 25.27%. Comparing base (d12464a) to head (0faedb3).

Files with missing lines Patch % Lines
...loud/android/datamodel/FileDataStorageManager.java 39.28% 15 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master   #14268       +/-   ##
=============================================
+ Coverage          0   25.27%   +25.27%     
- Complexity        0     3429     +3429     
=============================================
  Files             0      689      +689     
  Lines             0    50649    +50649     
  Branches          0     6821     +6821     
=============================================
+ Hits              0    12804    +12804     
- Misses            0    35866    +35866     
- Partials          0     1979     +1979     
Files with missing lines Coverage Δ
...loud/android/datamodel/FileDataStorageManager.java 56.93% <39.28%> (ø)

... and 688 files with indirect coverage changes

@tobiasKaminsky
Copy link
Member

I think FileDataStorageManager shall not handle this.
Instead, as seen in the linked bug, the root cause is that requestUploadOfFilesFromFileSystem() from FileDisplayActivity runs on MainThread.

Copy link
Member

@tobiasKaminsky tobiasKaminsky left a comment

Choose a reason for hiding this comment

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

Please fix in FileDisplayActivity

Signed-off-by: alperozturk <[email protected]>
Signed-off-by: alperozturk <[email protected]>
@alperozturk96 alperozturk96 force-pushed the bugfix/NetworkOnMainThreadException-saveFileWithParent branch from 0faedb3 to 5562792 Compare January 7, 2025 09:00
Copy link

github-actions bot commented Jan 7, 2025

Codacy

Lint

TypemasterPR
Warnings5656
Errors33

SpotBugs

CategoryBaseNew
Bad practice6565
Correctness5858
Dodgy code296296
Experimental11
Internationalization77
Malicious code vulnerability11
Multithreaded correctness77
Performance5353
Security1818
Total506506

@alperozturk96
Copy link
Collaborator Author

I think FileDataStorageManager shall not handle this. Instead, as seen in the linked bug, the root cause is that requestUploadOfFilesFromFileSystem() from FileDisplayActivity runs on MainThread.

After your comment, I checked again, and the actual issue is with the method:

void isNetworkAndServerAvailable(@NonNull GenericCallback<Boolean> callback);

This callback runs on the main thread, which is necessary for some cases. However, in other cases, like this one, it must run on a background thread instead of the main thread.

Current Usage of isNetworkAndServerAvailable:

Must run on a background thread:
• fileOperationsHelper?.removeFiles
• fileDataStorageManager.addRemoveFileOfflineOperation
• FileUploadHelper.Companion.instance().uploadNewFiles
• fileDataStorageManager.addCreateFileOfflineOperation

Must run on the main thread:
• DisplayUtils.showSnackMessage
• ocFileListFragment.setEmptyListMessage
• fileDisplayActivity.refreshCurrentDirectory

To address this, it would be better to create a new PR. Before proceeding, I want to inform you because this PR will touch multiple files. While it won’t be a large PR, it will require careful testing.

What do you think? Is it okay for you?

@alperozturk96 alperozturk96 marked this pull request as draft January 8, 2025 13:34
@alperozturk96 alperozturk96 removed the request for review from ZetaTom January 8, 2025 13:34
@alperozturk96
Copy link
Collaborator Author

@tobiasKaminsky How are we going to proceed? I explained earlier I have to change multiple files to fix this issue. Shall I create a PR for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NetworkOnMainThreadException: FileDataStorageManager.saveFileWithParent
2 participants