Add bandwidth limit to file download and upload functions #1667
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
The Nextcloud Android client does not currently feature any way to limit bandwidth of the auto upload feature like the desktop client does. To add this feature this library would need to offer an API to limit the download and upload speed.
Why:
A client side limit is useful for cases where network bandwidth is limited and where the router the client is using is not smart enough to throttle invididual devices and insteads results in the entire network hanging (don't ask me how I know :P).
How:
This PR replaces the buffered input and output streams in DownloadFileRemoteOperation and FileRequestEntity with sources and sinks from okio which is a part of okhttp which is already included in the dependancies and then using a Throttler also from okio to then limit bandwidth. I dont know if this is the best approach and im not all that familiar with buffers and the like in Java. This PR also modifies the example app to demonstrate that the limit works and does not impact performance too badly, I ran some basic tests by uploading and downloading files using the sample client and on my setup upload and download speeds were within 5% of the original speed.
I have left in the comments and testing results for now but ill remove those later once everone is happy.
Related issue here.