Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c149051 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Merge branch '5522-Enable_autoConfig_for_basic_account_setup' into 'main'

5522-Enable_autoConfig_for_basic_account_setup

See merge request !85
parents 5c274e0d 41bd52b0
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ dependencies {

    implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}"
    implementation "com.squareup.retrofit2:converter-simplexml:${versions.retrofit}"

    implementation "com.github.fahim44:FullScreenLoadingDialog:1.0.6"
}

android {
+48 −21
Original line number Diff line number Diff line
/*
 * Copyright ECORP SAS 2022
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package com.fsck.k9.activity.setup;


import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@@ -18,16 +30,16 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleOwner;
import com.fsck.k9.Account;
import com.fsck.k9.Core;
import com.fsck.k9.DI;
import com.fsck.k9.EmailAddressValidator;
import com.fsck.k9.Preferences;
import com.fsck.k9.account.AccountCreator;
import com.fsck.k9.mail.oauth.OAuth2Provider;
import com.fsck.k9.preferences.AccountManager;
import com.fsck.k9.ui.base.K9Activity;
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
import com.fsck.k9.activity.setup.accountmanager.MailAutoConfigDiscoveryHelper;
import com.fsck.k9.autodiscovery.api.DiscoveredServerSettings;
import com.fsck.k9.autodiscovery.api.DiscoveryResults;
import com.fsck.k9.autodiscovery.api.DiscoveryTarget;
@@ -35,14 +47,17 @@ import com.fsck.k9.autodiscovery.providersxml.ProvidersXmlDiscovery;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.oauth.OAuth2Provider;
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator;
import com.fsck.k9.ui.R;
import com.fsck.k9.ui.ConnectionSettings;
import com.fsck.k9.ui.R;
import com.fsck.k9.ui.base.K9Activity;
import com.fsck.k9.ui.settings.ExtraAccountDiscovery;
import com.fsck.k9.view.ClientCertificateSpinner;
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.lamonjush.fullscreenloadingdialog.FullScreenLoadingDialog;
import timber.log.Timber;

/**
@@ -318,22 +333,34 @@ public class AccountSetupBasics extends K9Activity
        if(provider != null && provider.toString().trim().equals("GMAIL")){
            Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
            startActivity(intent);
            return;
        }
        else {

        ConnectionSettings extraConnectionSettings = ExtraAccountDiscovery.discover(email);
        if (extraConnectionSettings != null) {
            finishAutoSetup(extraConnectionSettings);
            return;
        }

            ConnectionSettings connectionSettings = providersXmlDiscoveryDiscover(email, DiscoveryTarget.INCOMING_AND_OUTGOING);
        ConnectionSettings connectionSettings =
                providersXmlDiscoveryDiscover(email, DiscoveryTarget.INCOMING_AND_OUTGOING);
        if (connectionSettings != null) {
            finishAutoSetup(connectionSettings);
            } else {
                // We don't have default settings for this account, start the manual setup process.
                onManualSetup();
            return;
        }
        // We don't have predefine configuration, try to retrieve it by api call
        FullScreenLoadingDialog.getInstance()
                .setSpinKitColor(R.color.color_default_accent)
                .show(this);
        MailAutoConfigDiscoveryHelper.INSTANCE.retrieveConfiguration(email, this, config -> {
            FullScreenLoadingDialog.getInstance().dismiss();
            if (config != null) {
                finishAutoSetup(config);
                return;
            }
            // We can't find default settings for this account, start the manual setup process.
            onManualSetup();
        });
    }

    @Override
+17 −2
Original line number Diff line number Diff line
package com.fsck.k9.activity.setup.accountmanager;
/*
 * Copyright ECORP SAS 2022
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package com.fsck.k9.activity.setup.accountmanager;

import android.content.Context;

@@ -38,7 +53,7 @@ public class EeloAccountCreator {
        ConnectionSettings connectionSettings = providersXmlDiscoveryDiscover(emailId);
        if (connectionSettings == null) {
            // connection details not predefined in the xml. Try to load from the api
            connectionSettings = EeloMailAutoConfigDiscovery.retrieveConfigFromApi(emailId);
            connectionSettings = MailAutoConfigDiscovery.retrieveConfigFromApi(emailId);
        }
        // providers.xml doesn't have the connection details & can't retrieve details from api
        // & it is google account, meaning custom domain for google account is used.
+21 −6
Original line number Diff line number Diff line
package com.fsck.k9.activity.setup.accountmanager;
/*
 * Copyright ECORP SAS 2022
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package com.fsck.k9.activity.setup.accountmanager;

import androidx.annotation.Nullable;
import com.fsck.k9.autodiscovery.api.DiscoveredServerSettings;
import com.fsck.k9.helper.EmailHelper;
import com.fsck.k9.helper.Utility;
@@ -14,15 +30,14 @@ import retrofit2.Retrofit;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
import timber.log.Timber;


public class EeloMailAutoConfigDiscovery {
public class MailAutoConfigDiscovery {

    /**
     * Try to retrieve /e/ cloud mail info from the api
     * Try to retrieve mail info from the api
     *
     * @param email retrieved from accountManager for /e/ cloud account
     * @return mail's incoming & outgoing connection detail, null if failed to retrieve
     */
    @Nullable
    public static ConnectionSettings retrieveConfigFromApi(String email) {
        String domain = EmailHelper.getDomainFromEmailAddress(email);
        if (domain == null) {
@@ -170,6 +185,6 @@ public class EeloMailAutoConfigDiscovery {
        return getAutoConfigSettings(response.getEmailProvider().getOutgoingServer());
    }

    private EeloMailAutoConfigDiscovery() {
    private MailAutoConfigDiscovery() {
    }
}
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright ECORP SAS 2022
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package com.fsck.k9.activity.setup.accountmanager

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.fsck.k9.ui.ConnectionSettings
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 * We can't use lifecycleScope from Java class directly.
 * The main requirement of this class is to use lifecycleScope from java class
 */
object MailAutoConfigDiscoveryHelper {

    fun retrieveConfiguration(email: String, lifecycleOwner: LifecycleOwner, callback: ConfigureLoaderCallback) {
        lifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
            val config = MailAutoConfigDiscovery.retrieveConfigFromApi(email)
            lifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
                callback.onConfigureLoaded(config)
            }
        }
    }

    interface ConfigureLoaderCallback {

        fun onConfigureLoaded(connectionSettings: ConnectionSettings?)
    }
}
 No newline at end of file