-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[GSoC] Add preference to allow/warn if using metered connections #12121
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with two minor issues.
.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
cm.isActiveNetworkMetered | ||
} catch (e: Exception) { | ||
Timber.w(e, "Exception obtaining metered connection - assuming metered connection") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am very much against it.
I prefer that we use an enum with three values, yes, no, unknown.
I'll admit that in any case, we will never get real valid information, and that's a shame. So we should never be assertive one way or another.
This is requiring the user to grasp a concept that is not necessarily straighforward. I prefer that we are able to tell them honestly when we can't know instead of mixing it with the case where we are sure.
I agree it makes sense to behave in the same way in both case, and ask for confirmation. However, I hope we can have different warning messages
I'm not sure for JS how to transform it. I'd consider using two boolean function, except that I would not want that each card do the request twice. Is there an easy way to send an enum to JS? Otherwise, I'd want the function to be
isConnectionNotMetered
with 0
meaning false, 1
true, and 2
"unknown". So that if a code just do if(!isConnectionNotMetered) {useNetwork}
it uses network only if it is certain it's okay to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually just copied and pasted the method, a 100% straight extraction. It wasn't my goal to refactor it on this PR.
But I agree if your points. Looking on the source code, I only expect it to return an error in the case there isn't a specific permission on the manifest. AnkiDroid's manifest has it, so I don't think that the try catch is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't realize on first read that you were extracting a method. Then I guess fine.
I still believes my remarks make sense, but it can wait then.
) | ||
) | ||
) | ||
val shouldFetchMedia = preferences.getBoolean("syncFetchesMedia", true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd appreciate for a next time that you do this in multiple commit.
- Extracting variables in a commit,
- extracting doSync
- then taking into account whether it's metered
We can put it in a separate PR and squash it, but it would really help to review and save me time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doSync
is mostly only useful inside sync()
, so to reduce boilerplate, I've kept it as a nested function. Added a javadoc to make it more clear. Let me know if that is fine
Took a conflict just now, and I'm not sure what the state on it is? Is it ready for re-review from previous reviewers? |
Yes, it is ready for review. Just rebased to solve conflicts. Only the last 3 commits are new. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, my limited data friends (and myself on occasion - if I'm syncing a big deck) will appreciate this.
cm.isActiveNetworkMetered | ||
} catch (e: Exception) { | ||
Timber.w(e, "Exception obtaining metered connection - assuming metered connection") | ||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Arthur-Milchior in your review you wanted an enum, with this refactor here to a simple util method, I think this is clean and correct and just binary. The assertion it is correct is that from the perspective of consuming people's money (using metered data) defaulting to a cautious stance of assuming it is metered when we catch an (almost entirely impossible) exception is the right one.
So I think this may answer your review comments well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this commit does not change the slightest the actual code used. It just ensures that we remove the object
from the file.
If most people agree that as soon as we get an exception, we warn in the same way, fine by me I guess.
Anyway, this PR is already a great improvement, and if I can convince peolpe, the change can be done later easily.
One regret I have, but that always can be dealt with later too is that we should send a crash report. I'd love to know if it's something that actually occurs, hether it's related to specific version of the API or specific manufacturers. Also maybe what exceptions we actually get. So that maybe later we could get a better catching and warning
(By the way, this did not seems to require an extra commit. You could just have directly create the file without any enclosing "object NetworkUtils" when you created the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally approve.
I believe we could save two commits.
If we squash, feel free to squash.
If we don't, then feel free to merge as soon as the correction is done
.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
cm.isActiveNetworkMetered | ||
} catch (e: Exception) { | ||
Timber.w(e, "Exception obtaining metered connection - assuming metered connection") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't realize on first read that you were extracting a method. Then I guess fine.
I still believes my remarks make sense, but it can wait then.
// Check whether the option is selected, the user is signed in and last sync was AUTOMATIC_SYNC_TIME ago | ||
// (currently 10 minutes) | ||
// Check whether the option is selected, the user is signed in, last sync was AUTOMATIC_SYNC_TIME ago | ||
// (currently 10 minutes), and is not under a metered connection (if not allowed by preference) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the commint "Add preference to check if sync is on metered connection" except for his title
You're adding a permission request, that should be in the commit message.
Also, you are not adding adding a preference but taking it into account. I suggest it may be nice to indicates both fact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up. Changed the commit message to:
Add "Allow sync on metered connections" preference
If disabled, auto-sync isn't triggered on metered connections and the user is asked if they want to continue if they trigger a manual sync
If enabled, sync occurs normally
cm.isActiveNetworkMetered | ||
} catch (e: Exception) { | ||
Timber.w(e, "Exception obtaining metered connection - assuming metered connection") | ||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this commit does not change the slightest the actual code used. It just ensures that we remove the object
from the file.
If most people agree that as soon as we get an exception, we warn in the same way, fine by me I guess.
Anyway, this PR is already a great improvement, and if I can convince peolpe, the change can be done later easily.
One regret I have, but that always can be dealt with later too is that we should send a crash report. I'd love to know if it's something that actually occurs, hether it's related to specific version of the API or specific manufacturers. Also maybe what exceptions we actually get. So that maybe later we could get a better catching and warning
(By the way, this did not seems to require an extra commit. You could just have directly create the file without any enclosing "object NetworkUtils" when you created the file
3cc6fb9
to
844dcbf
Compare
for better organization
If disabled, auto-sync isn't triggered on metered connections and the user is asked if they want to continue if they trigger a manual sync If enabled, sync occurs normally
I think we are good to go with the standard rebase merge here? I'll do a strings run now |
Pull Request template
Purpose / Description
Internet may be expensive 💵💰💲💸
Fixes
Fixes #10706
Approach
How Has This Been Tested?
Screen_Recording_20220820-200646_AnkiDroid.mp4
Checklist
Please, go through these checks before submitting the PR.