diff --git a/app/src/main/java/eu/faircode/email/AdapterAccount.java b/app/src/main/java/eu/faircode/email/AdapterAccount.java index 5bb2f958d1..2e7fdb61c4 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAccount.java +++ b/app/src/main/java/eu/faircode/email/AdapterAccount.java @@ -19,6 +19,7 @@ package eu.faircode.email; Copyright 2018-2022 by Marcel Bokhorst (M66B) */ +import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL; import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD; import android.annotation.TargetApi; @@ -202,6 +203,8 @@ public class AdapterAccount extends RecyclerView.Adapter getAccounts(String user, int protocol, int[] auth_type); + List getAccounts(String user, int protocol); @Query("SELECT * FROM account WHERE `primary`") EntityAccount getPrimaryAccount(); @@ -220,10 +219,10 @@ public interface DaoAccount { int setAccountColor(long id, Integer color); @Query("UPDATE account" + - " SET password = :password, auth_type = :auth_type" + + " SET password = :password, auth_type = :auth_type, provider = :provider" + " WHERE id = :id" + - " AND NOT (password IS :password AND auth_type = :auth_type)") - int setAccountPassword(long id, String password, int auth_type); + " AND NOT (password IS :password AND auth_type = :auth_type AND provider = :provider)") + int setAccountPassword(long id, String password, int auth_type, String provider); @Query("UPDATE account" + " SET fingerprint = :fingerprint" + diff --git a/app/src/main/java/eu/faircode/email/DaoIdentity.java b/app/src/main/java/eu/faircode/email/DaoIdentity.java index 79ae814e60..72048cd74c 100644 --- a/app/src/main/java/eu/faircode/email/DaoIdentity.java +++ b/app/src/main/java/eu/faircode/email/DaoIdentity.java @@ -116,12 +116,12 @@ public interface DaoIdentity { int setIdentityPassword(long account, String user, String password, int auth_type, String domain); @Query("UPDATE identity" + - " SET password = :password, auth_type = :new_auth_type" + + " SET password = :password, auth_type = :new_auth_type, provider = :provider" + " WHERE account = :account" + " AND user = :user" + " AND auth_type = :auth_type" + - " AND NOT (password IS :password AND auth_type IS :new_auth_type)") - int setIdentityPassword(long account, String user, String password, int auth_type, int new_auth_type); + " AND NOT (password IS :password AND auth_type IS :new_auth_type AND provider = :provider)") + int setIdentityPassword(long account, String user, String password, int auth_type, int new_auth_type, String provider); @Query("UPDATE identity" + " SET fingerprint = :fingerprint" + diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index aca31c2d5a..32053d7a03 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -356,8 +356,8 @@ public class EmailService implements AutoCloseable { public void onPasswordChanged(Context context, String newPassword) { DB db = DB.getInstance(context); account.password = newPassword; - int accounts = db.account().setAccountPassword(account.id, account.password, account.auth_type); - int identities = db.identity().setIdentityPassword(account.id, account.user, account.password, account.auth_type, account.auth_type); + int accounts = db.account().setAccountPassword(account.id, account.password, account.auth_type, account.provider); + int identities = db.identity().setIdentityPassword(account.id, account.user, account.password, account.auth_type, account.auth_type, account.provider); EntityLog.log(context, EntityLog.Type.Account, account, "token refreshed=" + accounts + "/" + identities); } diff --git a/app/src/main/java/eu/faircode/email/FragmentGmail.java b/app/src/main/java/eu/faircode/email/FragmentGmail.java index 94037b05a7..a957bd5b93 100644 --- a/app/src/main/java/eu/faircode/email/FragmentGmail.java +++ b/app/src/main/java/eu/faircode/email/FragmentGmail.java @@ -23,7 +23,6 @@ import static android.accounts.AccountManager.newChooseAccountIntent; import static android.app.Activity.RESULT_OK; import static eu.faircode.email.GmailState.TYPE_GOOGLE; import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL; -import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD; import android.Manifest; import android.accounts.Account; @@ -504,10 +503,7 @@ public class FragmentGmail extends FragmentBase { db.beginTransaction(); if (args.getBoolean("update")) { - List accounts = - db.account().getAccounts(user, - protocol, - new int[]{AUTH_TYPE_GMAIL, AUTH_TYPE_PASSWORD}); + List accounts = db.account().getAccounts(user, protocol); if (accounts != null && accounts.size() == 1) update = accounts.get(0); } @@ -596,8 +592,8 @@ public class FragmentGmail extends FragmentBase { args.putLong("account", update.id); EntityLog.log(context, "Gmail update account=" + update.name); db.account().setAccountSynchronize(update.id, true); - db.account().setAccountPassword(update.id, password, AUTH_TYPE_GMAIL); - db.identity().setIdentityPassword(update.id, update.user, password, update.auth_type, AUTH_TYPE_GMAIL); + db.account().setAccountPassword(update.id, password, AUTH_TYPE_GMAIL, null); + db.identity().setIdentityPassword(update.id, update.user, password, update.auth_type, AUTH_TYPE_GMAIL, null); } db.setTransactionSuccessful(); @@ -605,12 +601,8 @@ public class FragmentGmail extends FragmentBase { db.endTransaction(); } - if (update == null) - ServiceSynchronize.eval(context, "Gmail"); - else { - args.putBoolean("updated", true); - ServiceSynchronize.reload(context, update.id, true, "Gmail"); - } + ServiceSynchronize.eval(context, "Gmail"); + args.putBoolean("updated", update != null); return null; } diff --git a/app/src/main/java/eu/faircode/email/FragmentOAuth.java b/app/src/main/java/eu/faircode/email/FragmentOAuth.java index 4d89f5fffd..7e41e6ba6a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOAuth.java +++ b/app/src/main/java/eu/faircode/email/FragmentOAuth.java @@ -21,7 +21,6 @@ package eu.faircode.email; import static android.app.Activity.RESULT_OK; import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH; -import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD; import android.content.ActivityNotFoundException; import android.content.Context; @@ -804,10 +803,7 @@ public class FragmentOAuth extends FragmentBase { db.beginTransaction(); if (args.getBoolean("update")) { - List accounts = - db.account().getAccounts(username, - protocol, - new int[]{AUTH_TYPE_OAUTH, AUTH_TYPE_PASSWORD}); + List accounts = db.account().getAccounts(username, protocol); if (accounts != null && accounts.size() == 1) update = accounts.get(0); } @@ -906,8 +902,8 @@ public class FragmentOAuth extends FragmentBase { args.putLong("account", update.id); EntityLog.log(context, "OAuth update account=" + update.name); db.account().setAccountSynchronize(update.id, true); - db.account().setAccountPassword(update.id, state, AUTH_TYPE_OAUTH); - db.identity().setIdentityPassword(update.id, update.user, state, update.auth_type, AUTH_TYPE_OAUTH); + db.account().setAccountPassword(update.id, state, AUTH_TYPE_OAUTH, provider.id); + db.identity().setIdentityPassword(update.id, update.user, state, update.auth_type, AUTH_TYPE_OAUTH, provider.id); } db.setTransactionSuccessful(); @@ -915,12 +911,8 @@ public class FragmentOAuth extends FragmentBase { db.endTransaction(); } - if (update == null) - ServiceSynchronize.eval(context, "OAuth"); - else { - args.putBoolean("updated", true); - ServiceSynchronize.reload(context, update.id, true, "OAuth"); - } + ServiceSynchronize.eval(context, "OAuth"); + args.putBoolean("updated", update != null); return null; } diff --git a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java index 496908603f..358f89bc4b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java @@ -510,10 +510,7 @@ public class FragmentQuickSetup extends FragmentBase { EntityAccount primary = db.account().getPrimaryAccount(); if (args.getBoolean("update")) { - List accounts = - db.account().getAccounts(user, - EntityAccount.TYPE_IMAP, - new int[]{AUTH_TYPE_PASSWORD}); + List accounts = db.account().getAccounts(user, EntityAccount.TYPE_IMAP); if (accounts != null && accounts.size() == 1) update = accounts.get(0); } @@ -593,9 +590,9 @@ public class FragmentQuickSetup extends FragmentBase { args.putLong("account", update.id); EntityLog.log(context, "Quick setup update account=" + update.name); db.account().setAccountSynchronize(update.id, true); - db.account().setAccountPassword(update.id, password, AUTH_TYPE_PASSWORD); + db.account().setAccountPassword(update.id, password, AUTH_TYPE_PASSWORD, null); db.account().setAccountFingerprint(update.id, imap_fingerprint); - db.identity().setIdentityPassword(update.id, update.user, password, update.auth_type, AUTH_TYPE_PASSWORD); + db.identity().setIdentityPassword(update.id, update.user, password, update.auth_type, AUTH_TYPE_PASSWORD, null); db.identity().setIdentityFingerprint(update.id, smtp_fingerprint); } @@ -604,12 +601,8 @@ public class FragmentQuickSetup extends FragmentBase { db.endTransaction(); } - if (update == null) - ServiceSynchronize.eval(context, "quick setup"); - else { - args.putBoolean("updated", true); - ServiceSynchronize.reload(context, update.id, true, "quick setup"); - } + ServiceSynchronize.eval(context, "quick setup"); + args.putBoolean("updated", update != null); return provider; } catch (Throwable ex) { diff --git a/app/src/main/java/eu/faircode/email/TupleAccountState.java b/app/src/main/java/eu/faircode/email/TupleAccountState.java index 2cb5a1b341..110ab11e05 100644 --- a/app/src/main/java/eu/faircode/email/TupleAccountState.java +++ b/app/src/main/java/eu/faircode/email/TupleAccountState.java @@ -37,7 +37,8 @@ public class TupleAccountState extends EntityAccount { this.insecure.equals(other.insecure) && this.port.equals(other.port) && this.user.equals(other.user) && - (auth_type != AUTH_TYPE_PASSWORD || this.password.equals(other.password)) && + Objects.equals(this.auth_type, other.auth_type) && + this.password.equals(other.password) && Objects.equals(this.certificate_alias, other.certificate_alias) && Objects.equals(this.realm, other.realm) && Objects.equals(this.fingerprint, other.fingerprint) &&