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

Add support for server settings autodiscovery #3879

Closed
wants to merge 2 commits into from

Conversation

wiktor-k
Copy link
Contributor

@wiktor-k wiktor-k commented Jan 16, 2019

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 !

  • Follows our existing codestyle.
  • Does not break any unit tests. ✔️
  • Contains a reference to the issue that it fixes. ✔️
  • For cosmetic changes add one or multiple images, if possible. There is no UI, it either works or not very quickly

@wiktor-k wiktor-k changed the title WIP: Add support for server settings autodiscovery Add support for server settings autodiscovery Jan 28, 2019
@wiktor-k
Copy link
Contributor Author

wiktor-k commented Feb 6, 2019

Great, excellent feedback @cketti, thank you! I'll address your points as soon as possible.

@wiktor-k
Copy link
Contributor Author

Updated the HTTP code to use okhttp @cketti (funnily it seems on Android 8 even native HttpUrlConnection is internally using okhttp).

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.

@yoshimo

This comment has been minimized.

@wiktor-k

This comment has been minimized.

Copy link
Member

@cketti cketti left a 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/build.gradle Outdated Show resolved Hide resolved
class AccountDiscovery(private val discoverers: Array<ConnectionSettingsDiscoverer>) {

fun discover(email: String, callback: (settings: ConnectionSettings?) -> Unit) {
launch(UI) {
Copy link
Member

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.

Copy link
Contributor Author

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?

@wiktor-k
Copy link
Contributor Author

We need to move away from fetching server settings and actually testing these settings in different activities.

I don't know if I understood you correctly but the settings that are fetched are tested just like manual settings (and settings from providers.xml). If they're incorrect the user is provided with the standard "correct"/"continue anyway" dialog. There is a "manual setup" button that will well enter manual setup without autodetecting so broken settings will not lock out anyone.

@cketti
Copy link
Member

cketti commented Feb 28, 2019

I don't know if I understood you correctly but the settings that are fetched are tested just like manual settings (and settings from providers.xml). If they're incorrect the user is provided with the standard "correct"/"continue anyway" dialog. There is a "manual setup" button that will well enter manual setup without autodetecting so broken settings will not lock out anyone.

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.

@wiktor-k
Copy link
Contributor Author

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 providers.xml worked. I am afraid doing it the way you described would also need some tweaks to the UI of account setup.

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
@wiktor-k
Copy link
Contributor Author

wiktor-k commented Mar 1, 2019

Okay, fixed all mentioned issues (though I'm not sure what you think about AsyncTask)...

Thanks for taking the time to review this @cketti, I really appreciate it.

@cketti
Copy link
Member

cketti commented Mar 9, 2019

An AsyncTask is not going to work. It'll hold on to the wrong Activity instance e.g. in the case of an orientation change.

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.

@cketti
Copy link
Member

cketti commented Mar 22, 2019

Superseded by #3980

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

Successfully merging this pull request may close these issues.

Feature Request: Support Mozilla autoconfig
3 participants