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
Add support for server settings autodiscovery #3879
Conversation
5c7acf0
to
6c0425d
Compare
app/ui/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java
Outdated
Show resolved
Hide resolved
app/ui/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java
Outdated
Show resolved
Hide resolved
app/ui/src/main/java/com/fsck/k9/activity/setup/AccountDiscovery.kt
Outdated
Show resolved
Hide resolved
app/ui/src/main/java/com/fsck/k9/activity/setup/AccountDiscovery.kt
Outdated
Show resolved
Hide resolved
app/ui/src/main/java/com/fsck/k9/activity/setup/AccountDiscovery.kt
Outdated
Show resolved
Hide resolved
app/ui/src/test/java/com/fsck/k9/activity/setup/AccountDiscoveryTest.kt
Outdated
Show resolved
Hide resolved
Great, excellent feedback @cketti, thank you! I'll address your points as soon as possible. |
6c0425d
to
c8f01ca
Compare
c8f01ca
to
10e0e12
Compare
Updated the HTTP code to use Okhttp required new proguard rules and changing java version level to 1.8 (as okhttp is using static interface methods, a similar issue is reported here: JakeWharton/butterknife#1416) but otherwise the code is almost identical. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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've thought about this some more. The current approach is probably too simple and doesn't lead to a great user experience when things go wrong (e.g. when we retrieve server settings that don't actually work). We need to move away from fetching server settings and actually testing these settings in different activities. I'll try to write up my thoughts on a proper design for automatically detecting server settings next week.
But I guess we can merge this as interim solution once the comments are addressed.
app/ui/src/main/java/com/fsck/k9/activity/setup/discovery/AccountDiscovery.kt
Outdated
Show resolved
Hide resolved
class AccountDiscovery(private val discoverers: Array<ConnectionSettingsDiscoverer>) { | ||
|
||
fun discover(email: String, callback: (settings: ConnectionSettings?) -> Unit) { | ||
launch(UI) { |
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 like us to split code like this into two parts. Most of the time the "business logic" part doesn't have to be concerned about the main thread at all. It should assume it is running in a background thread. To make the feature available to UI code, create a class that starts the work in a background thread and delivers the result in the main thread. Ideally, the business code also supports cancellation. It's then the job of the "UI wrapper" class to cancel the work at the appropriate times (user closes the activity etc). Often such code could live in an androidx.lifecycle.ViewModel
class.
Also, lets avoid passing callbacks from Activities to long-running code in a background thread.
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.
Yep, I agree the code looked bad.
I did a quick look on classes using androidx.lifecycle.ViewModel
but it seems to be aimed at things that can change more than once (like accounts).
I modified the discover
method to just do the background work, without any UI dependencies. And in UI (AccountSetupBasic
) I wrapped the call in an AsyncTask
. AsyncTask supports cancellation in principle but I didn't implement it (it should check and break the for loop).
Do you think AsyncTask is good enough for the job or should I rework it to a ViewModel?
app/ui/src/main/java/com/fsck/k9/activity/setup/discovery/ConnectionSettingsDiscoverer.kt
Outdated
Show resolved
Hide resolved
app/ui/src/main/java/com/fsck/k9/activity/setup/discovery/ThunderbirdAutoconfigFetcher.kt
Outdated
Show resolved
Hide resolved
I don't know if I understood you correctly but the settings that are fetched are tested just like manual settings (and settings from |
That's true. But especially once we add more methods to retrieve server settings chances increase that one method returns outdated or plain wrong results. Right now the loop stops as soon as any server settings are retrieved. Checking the server settings is a second step. If that fails there's no going back to try additional server settings retrieved using different methods. It's not really an issue now. But it's not a future proof design either. |
Agreed. Making it more flexible, like you described checking autodiscover settings in succession would be more complex from the UX perspective currently. The design we have now (one settings) works well as this is just an extension of how That being said I hope having at least one autodiscovery would solve majority of "add me to providers.xml" PRs :) |
This change makes account setup query mail provider's HTTPS server and fills in appropriate settings for store and transport settings. If there is no such file or the file is malformed the account setup proceeds as usual with the manual setup. If the user doesn't want to automatically discover server settings they can initiate manual setup by pressing "Manual Setup" button on the first screen. Currently implemented autodiscovery scheme is Thunderbird Autoconfig but this can be extended to additional methods (e.g. DNS or autodiscover). Resolves thunderbird#865. See: https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
Okay, fixed all mentioned issues (though I'm not sure what you think about Thanks for taking the time to review this @cketti, I really appreciate it. |
An This PR is already quite big. We should break this down and do it step by step. I'll create a series of smaller PRs to get us to what I have in mind. I'll pick up your Thunderbird Autoconfig changes after some initial "infrastructure" changes. |
Superseded by #3980 |
This change makes account setup query mail provider's HTTPS server and fills in appropriate settings for store and transport settings.
If there is no such file or the file is malformed the account setup proceeds as usual with the manual setup.
If the user doesn't want to automatically discover server settings they can initiate manual setup by pressing "Manual Setup" button on the first screen.
Currently implemented autodiscovery scheme is Thunderbird Autoconfig but this can be extended to additional methods (e.g. DNS or autodiscover).
Resolves #865.
See: https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
Please ensure that your pull request meets the following requirements - thanks !