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

Commit 20b2df0e authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Fix auto-config not working issue

issue: e/backlog#5522

Auto-config in release build did not work previously because of:
- strickpolicy disabled in release mode, so network call was not
  possible in main thread
- proguard-rules.pro guard did not has rules for retrofit2 & simpleXml.

This commit does the following:
- Move automatic account creation code under IO thread using kotlin
  coroutine.
- Add new place-holder loading layout for messageList to show when
  loading accounts in the background thread.
- Add missing proguard rules.
parent 06e39f66
Loading
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -49,3 +49,46 @@

# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform

# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod

# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations

# Keep annotation default values (e.g., retrofit2.http.Field.encoded).
-keepattributes AnnotationDefault

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*

# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>

# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response

# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

-keep class org.simpleframework.xml.** { *; }

-keep class com.fsck.k9.activity.setup.accountmanager.** { *; }
 No newline at end of file
+63 −44
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

import android.accounts.AccountManager
@@ -28,6 +44,7 @@ import androidx.drawerlayout.widget.DrawerLayout.DrawerListener
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import com.fsck.k9.Account
import com.fsck.k9.Account.SortType
import com.fsck.k9.K9
@@ -74,6 +91,8 @@ import com.fsck.k9.view.ViewSwitcher
import com.fsck.k9.view.ViewSwitcher.OnSwitchCompleteListener
import com.google.android.material.snackbar.Snackbar
import com.mikepenz.materialdrawer.util.getOptimalDrawerWidth
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.component.KoinComponent
@@ -142,17 +161,17 @@ open class MessageList :

    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLayout(R.layout.message_list_loading)

        var accounts = preferences.accounts
        val accounts = preferences.accounts
        deleteIncompleteAccounts(accounts)

        accountManager = AccountManager.get(this)

// TODO remove old accounts automatically
        if (addNewAccountsAutomatically(accounts)) {
            accounts = preferences.accounts
        addNewAccountsAutomatically(accounts, savedInstanceState)
    }

    private fun onAccountConfigurationFinish(savedInstanceState: Bundle?) {
        val accounts = preferences.accounts
        val hasAccountSetup = accounts.any { it.isFinishedSetup }
        if (!hasAccountSetup) {
            AccountSetupBasics.actionNewAccount(this)
@@ -1679,11 +1698,11 @@ open class MessageList :
        val messageViewOnly: Boolean = false
    )

    private fun addNewAccountsAutomatically(accounts: List<Account>): Boolean {
        return try {
    private fun addNewAccountsAutomatically(accounts: List<Account>, savedInstanceState: Bundle?) {
        lifecycleScope.launch(Dispatchers.IO) {
            try {
                val eeloAccounts: Array<android.accounts.Account> = getEeloAccountsOnDevice()
                val googleAccounts: Array<android.accounts.Account> = getGoogleAccountsOnDevice()
            var accountWasAdded = false
                for (eeloAccount in eeloAccounts) {
                    val emailId: String = accountManager.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY)
                    if (!emailId.contains("@")) continue
@@ -1696,8 +1715,7 @@ open class MessageList :
                    }
                    if (!accountIsSignedIn) {
                        val password: String = accountManager.getPassword(eeloAccount)
                    EeloAccountCreator.createAccount(this, emailId, password, false)
                    accountWasAdded = true
                        EeloAccountCreator.createAccount(applicationContext, emailId, password, false)
                    }
                }

@@ -1709,21 +1727,22 @@ open class MessageList :
                        if (emailId == account.email) {
                            if (account.name == null) { // we need to fix an old bug
                                account.name = emailId
                            Preferences.getPreferences(this).saveAccount(account)
                                Preferences.getPreferences(applicationContext).saveAccount(account)
                            }
                            accountIsSignedIn = true
                            break
                        }
                    }
                    if (!accountIsSignedIn) {
                    EeloAccountCreator.createAccount(this, emailId, "", true)
                    accountWasAdded = true
                        EeloAccountCreator.createAccount(applicationContext, emailId, "", true)
                    }
                }
            return accountWasAdded
            } catch (e: SecurityException) {
            e.printStackTrace()
            false
                Timber.e(e)
            }
            lifecycleScope.launch(Dispatchers.Main) {
                onAccountConfigurationFinish(savedInstanceState)
            }
        }
    }

+27 −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 org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;


@Root(name = "emailProvider", strict = false)
public class EeloMailAutoConfigEmailProvider {

@@ -18,6 +32,17 @@ public class EeloMailAutoConfigEmailProvider {
    @Element
    private EeloMailAutoConfigIncomingServer incomingServer;

    public EeloMailAutoConfigEmailProvider() {
    }

    public EeloMailAutoConfigEmailProvider(String id,
            EeloMailAutoConfigOutgoingServer outgoingServer,
            EeloMailAutoConfigIncomingServer incomingServer) {
        this.id = id;
        this.outgoingServer = outgoingServer;
        this.incomingServer = incomingServer;
    }

    public String getId() {
        return id;
    }
+36 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ 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/>.
  -->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" />

    <com.google.android.material.progressindicator.CircularProgressIndicator
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminate="true"
        app:indicatorColor="@color/color_default_accent" />
</RelativeLayout>
 No newline at end of file