Loading app/core/src/main/java/com/fsck/k9/Account.kt +0 −4 Original line number Diff line number Diff line Loading @@ -360,10 +360,6 @@ class Account(override val uuid: String) : BaseAccount { @set:Synchronized var messagesNotificationChannelVersion = 0 @get:Synchronized @set:Synchronized var backgroundSync = true @get:Synchronized @set:Synchronized var isChangedVisibleLimits = false Loading app/core/src/main/java/com/fsck/k9/AccountPreferenceSerializer.kt +0 −3 Original line number Diff line number Diff line Loading @@ -54,7 +54,6 @@ class AccountPreferenceSerializer( isIgnoreChatMessages = storage.getBoolean("$accountUuid.ignoreChatMessages", false) isNotifySync = storage.getBoolean("$accountUuid.notifyMailCheck", false) messagesNotificationChannelVersion = storage.getInt("$accountUuid.messagesNotificationChannelVersion", 0) backgroundSync = storage.getBoolean("$accountUuid.backgroundSync", true) deletePolicy = DeletePolicy.fromInt(storage.getInt("$accountUuid.deletePolicy", DeletePolicy.NEVER.setting)) legacyInboxFolder = storage.getString("$accountUuid.inboxFolderName", null) importedDraftsFolder = storage.getString("$accountUuid.draftsFolderName", null) Loading Loading @@ -260,7 +259,6 @@ class AccountPreferenceSerializer( editor.putBoolean("$accountUuid.ignoreChatMessages", isIgnoreChatMessages) editor.putBoolean("$accountUuid.notifyMailCheck", isNotifySync) editor.putInt("$accountUuid.messagesNotificationChannelVersion", messagesNotificationChannelVersion) editor.putBoolean("$accountUuid.backgroundSync", backgroundSync) editor.putInt("$accountUuid.deletePolicy", deletePolicy.setting) editor.putString("$accountUuid.inboxFolderName", legacyInboxFolder) editor.putString("$accountUuid.draftsFolderName", importedDraftsFolder) Loading Loading @@ -551,7 +549,6 @@ class AccountPreferenceSerializer( isNotifyContactsMailOnly = false isIgnoreChatMessages = false messagesNotificationChannelVersion = 0 backgroundSync = true folderDisplayMode = FolderMode.NOT_SECOND_CLASS folderSyncMode = FolderMode.FIRST_CLASS folderPushMode = FolderMode.ALL Loading app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt 0 → 100644 +81 −0 Original line number Diff line number Diff line /* * Copyright MURENA 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 import android.accounts.Account import android.accounts.AccountManager import android.content.ContentResolver import android.content.Context import com.fsck.k9.setup.AccountManagerConstants import timber.log.Timber object OsAccountManagerUtil { /** * @return syncEnable or not. If account not found in accountManager accounts, * means account is setup by user... so return true by default */ fun isSyncEnable(context: Context, email: String): Boolean { val accountManager = AccountManager.get(context) val murenaAccounts = accountManager.getAccountsByType(AccountManagerConstants.EELO_ACCOUNT_TYPE) var syncEnable = isSyncEnable(accountManager, murenaAccounts, email) if (syncEnable.isAccountFound()) { return syncEnable.getStatus() } val googleAccounts = accountManager.getAccountsByType(AccountManagerConstants.GOOGLE_ACCOUNT_TYPE) syncEnable = isSyncEnable(accountManager, googleAccounts, email) if (syncEnable.isAccountFound()) { return syncEnable.getStatus() } return true } private fun isSyncEnable(accountManager: AccountManager, accounts: Array<out Account>, email: String): Syncable { accounts.forEach { try { val accountEmail: String = accountManager.getUserData(it, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY) if (accountEmail == email) { // if master sync disable, then account sync is disable return if (!ContentResolver.getMasterSyncAutomatically()) { Syncable.NOT_SYNCABLE } else Syncable.getSyncable(ContentResolver.getSyncAutomatically(it, AccountManagerConstants.MAIL_CONTENT_AUTHORITY)) } } catch (e: Throwable) { Timber.e(e) } } return Syncable.ACCOUNT_NOT_FOUND } private enum class Syncable { SYNCABLE, NOT_SYNCABLE, ACCOUNT_NOT_FOUND; companion object { fun getSyncable(status: Boolean) = if (status) SYNCABLE else NOT_SYNCABLE } fun getStatus() = this == SYNCABLE fun isAccountFound() = this != ACCOUNT_NOT_FOUND } } No newline at end of file app/core/src/main/java/com/fsck/k9/controller/push/KoinModule.kt +2 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,8 @@ internal val controllerPushModule = module { autoSyncManager = get(), pushNotificationManager = get(), connectivityManager = get(), accountPushControllerFactory = get() accountPushControllerFactory = get(), context = get() ) } } app/core/src/main/java/com/fsck/k9/controller/push/PushController.kt +5 −2 Original line number Diff line number Diff line package com.fsck.k9.controller.push import android.content.Context import com.fsck.k9.Account import com.fsck.k9.Account.FolderMode import com.fsck.k9.OsAccountManagerUtil import com.fsck.k9.Preferences import com.fsck.k9.backend.BackendManager import com.fsck.k9.network.ConnectivityChangeListener Loading Loading @@ -39,7 +41,8 @@ class PushController internal constructor( private val connectivityManager: ConnectivityManager, private val accountPushControllerFactory: AccountPushControllerFactory, private val coroutineScope: CoroutineScope = GlobalScope, private val coroutineDispatcher: CoroutineDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher() private val coroutineDispatcher: CoroutineDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher(), private val context: Context ) { private val lock = Any() private var initializationStarted = false Loading Loading @@ -211,7 +214,7 @@ class PushController internal constructor( private fun getPushAccounts(): List<Account> { return preferences.accounts.filter { account -> account.folderPushMode != FolderMode.NONE && account.backgroundSync && backendManager.getBackend(account)?.isPushCapable ?: false account.folderPushMode != FolderMode.NONE && OsAccountManagerUtil.isSyncEnable(context, account.email) && backendManager.getBackend(account)?.isPushCapable ?: false } } private fun setPushNotificationState(notificationState: PushNotificationState) { Loading Loading
app/core/src/main/java/com/fsck/k9/Account.kt +0 −4 Original line number Diff line number Diff line Loading @@ -360,10 +360,6 @@ class Account(override val uuid: String) : BaseAccount { @set:Synchronized var messagesNotificationChannelVersion = 0 @get:Synchronized @set:Synchronized var backgroundSync = true @get:Synchronized @set:Synchronized var isChangedVisibleLimits = false Loading
app/core/src/main/java/com/fsck/k9/AccountPreferenceSerializer.kt +0 −3 Original line number Diff line number Diff line Loading @@ -54,7 +54,6 @@ class AccountPreferenceSerializer( isIgnoreChatMessages = storage.getBoolean("$accountUuid.ignoreChatMessages", false) isNotifySync = storage.getBoolean("$accountUuid.notifyMailCheck", false) messagesNotificationChannelVersion = storage.getInt("$accountUuid.messagesNotificationChannelVersion", 0) backgroundSync = storage.getBoolean("$accountUuid.backgroundSync", true) deletePolicy = DeletePolicy.fromInt(storage.getInt("$accountUuid.deletePolicy", DeletePolicy.NEVER.setting)) legacyInboxFolder = storage.getString("$accountUuid.inboxFolderName", null) importedDraftsFolder = storage.getString("$accountUuid.draftsFolderName", null) Loading Loading @@ -260,7 +259,6 @@ class AccountPreferenceSerializer( editor.putBoolean("$accountUuid.ignoreChatMessages", isIgnoreChatMessages) editor.putBoolean("$accountUuid.notifyMailCheck", isNotifySync) editor.putInt("$accountUuid.messagesNotificationChannelVersion", messagesNotificationChannelVersion) editor.putBoolean("$accountUuid.backgroundSync", backgroundSync) editor.putInt("$accountUuid.deletePolicy", deletePolicy.setting) editor.putString("$accountUuid.inboxFolderName", legacyInboxFolder) editor.putString("$accountUuid.draftsFolderName", importedDraftsFolder) Loading Loading @@ -551,7 +549,6 @@ class AccountPreferenceSerializer( isNotifyContactsMailOnly = false isIgnoreChatMessages = false messagesNotificationChannelVersion = 0 backgroundSync = true folderDisplayMode = FolderMode.NOT_SECOND_CLASS folderSyncMode = FolderMode.FIRST_CLASS folderPushMode = FolderMode.ALL Loading
app/core/src/main/java/com/fsck/k9/OsAccountManagerUtil.kt 0 → 100644 +81 −0 Original line number Diff line number Diff line /* * Copyright MURENA 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 import android.accounts.Account import android.accounts.AccountManager import android.content.ContentResolver import android.content.Context import com.fsck.k9.setup.AccountManagerConstants import timber.log.Timber object OsAccountManagerUtil { /** * @return syncEnable or not. If account not found in accountManager accounts, * means account is setup by user... so return true by default */ fun isSyncEnable(context: Context, email: String): Boolean { val accountManager = AccountManager.get(context) val murenaAccounts = accountManager.getAccountsByType(AccountManagerConstants.EELO_ACCOUNT_TYPE) var syncEnable = isSyncEnable(accountManager, murenaAccounts, email) if (syncEnable.isAccountFound()) { return syncEnable.getStatus() } val googleAccounts = accountManager.getAccountsByType(AccountManagerConstants.GOOGLE_ACCOUNT_TYPE) syncEnable = isSyncEnable(accountManager, googleAccounts, email) if (syncEnable.isAccountFound()) { return syncEnable.getStatus() } return true } private fun isSyncEnable(accountManager: AccountManager, accounts: Array<out Account>, email: String): Syncable { accounts.forEach { try { val accountEmail: String = accountManager.getUserData(it, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY) if (accountEmail == email) { // if master sync disable, then account sync is disable return if (!ContentResolver.getMasterSyncAutomatically()) { Syncable.NOT_SYNCABLE } else Syncable.getSyncable(ContentResolver.getSyncAutomatically(it, AccountManagerConstants.MAIL_CONTENT_AUTHORITY)) } } catch (e: Throwable) { Timber.e(e) } } return Syncable.ACCOUNT_NOT_FOUND } private enum class Syncable { SYNCABLE, NOT_SYNCABLE, ACCOUNT_NOT_FOUND; companion object { fun getSyncable(status: Boolean) = if (status) SYNCABLE else NOT_SYNCABLE } fun getStatus() = this == SYNCABLE fun isAccountFound() = this != ACCOUNT_NOT_FOUND } } No newline at end of file
app/core/src/main/java/com/fsck/k9/controller/push/KoinModule.kt +2 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,8 @@ internal val controllerPushModule = module { autoSyncManager = get(), pushNotificationManager = get(), connectivityManager = get(), accountPushControllerFactory = get() accountPushControllerFactory = get(), context = get() ) } }
app/core/src/main/java/com/fsck/k9/controller/push/PushController.kt +5 −2 Original line number Diff line number Diff line package com.fsck.k9.controller.push import android.content.Context import com.fsck.k9.Account import com.fsck.k9.Account.FolderMode import com.fsck.k9.OsAccountManagerUtil import com.fsck.k9.Preferences import com.fsck.k9.backend.BackendManager import com.fsck.k9.network.ConnectivityChangeListener Loading Loading @@ -39,7 +41,8 @@ class PushController internal constructor( private val connectivityManager: ConnectivityManager, private val accountPushControllerFactory: AccountPushControllerFactory, private val coroutineScope: CoroutineScope = GlobalScope, private val coroutineDispatcher: CoroutineDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher() private val coroutineDispatcher: CoroutineDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher(), private val context: Context ) { private val lock = Any() private var initializationStarted = false Loading Loading @@ -211,7 +214,7 @@ class PushController internal constructor( private fun getPushAccounts(): List<Account> { return preferences.accounts.filter { account -> account.folderPushMode != FolderMode.NONE && account.backgroundSync && backendManager.getBackend(account)?.isPushCapable ?: false account.folderPushMode != FolderMode.NONE && OsAccountManagerUtil.isSyncEnable(context, account.email) && backendManager.getBackend(account)?.isPushCapable ?: false } } private fun setPushNotificationState(notificationState: PushNotificationState) { Loading