diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/database/MigrationTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/database/MigrationTest.kt index 399b6ea86a..8811d1a3df 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/database/MigrationTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/database/MigrationTest.kt @@ -43,6 +43,7 @@ class MigrationTest { FlowCryptRoomDatabase.MIGRATION_32_33, FlowCryptRoomDatabase.MIGRATION_33_34, FlowCryptRoomDatabase.MIGRATION_34_35, + FlowCryptRoomDatabase.MIGRATION_35_36, ) @get:Rule diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/rules/RetryRule.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/rules/RetryRule.kt index 4839079ca6..09863d53ea 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/rules/RetryRule.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/rules/RetryRule.kt @@ -46,7 +46,7 @@ class RetryRule(private val retryCount: Int = 0) : BaseRule() { .onSuccess { return } .onFailure { TestGeneralUtil.clearApp(targetContext) - Thread.sleep(1000) + Thread.sleep(1000 * (times + 1).toLong()) caughtThrowable = it System.err.println(description.displayName.toString() + ": run ${times + 1} failed") } diff --git a/FlowCrypt/src/consumerUiTests/java/com/flowcrypt/email/util/FlavorSettings.kt b/FlowCrypt/src/consumerUiTests/java/com/flowcrypt/email/util/FlavorSettings.kt index 50505ccb0b..d54516a4d9 100644 --- a/FlowCrypt/src/consumerUiTests/java/com/flowcrypt/email/util/FlavorSettings.kt +++ b/FlowCrypt/src/consumerUiTests/java/com/flowcrypt/email/util/FlavorSettings.kt @@ -17,8 +17,6 @@ object FlavorSettings : EnvironmentSettings { GeneralUtil.genIdlingResourcesName(this::class.java), GeneralUtil.isDebugBuild() ) - - override fun isGMailAPIEnabled(): Boolean = true override fun configure(context: Context) {} override fun getCountingIdlingResource() = countingIdlingResource override fun getGoogleIdToken(): String = UUID.randomUUID().toString() diff --git a/FlowCrypt/src/enterpriseDebug/java/com/flowcrypt/email/util/FlavorSettings.kt b/FlowCrypt/src/enterpriseDebug/java/com/flowcrypt/email/util/FlavorSettings.kt index 656de58d03..4331f78a3d 100644 --- a/FlowCrypt/src/enterpriseDebug/java/com/flowcrypt/email/util/FlavorSettings.kt +++ b/FlowCrypt/src/enterpriseDebug/java/com/flowcrypt/email/util/FlavorSettings.kt @@ -11,6 +11,5 @@ import android.content.Context * @author Denys Bondarenko */ object FlavorSettings : EnvironmentSettings { - override fun isGMailAPIEnabled(): Boolean = true override fun configure(context: Context) {} } diff --git a/FlowCrypt/src/enterpriseRelease/java/com/flowcrypt/email/util/FlavorSettings.kt b/FlowCrypt/src/enterpriseRelease/java/com/flowcrypt/email/util/FlavorSettings.kt index 656de58d03..4331f78a3d 100644 --- a/FlowCrypt/src/enterpriseRelease/java/com/flowcrypt/email/util/FlavorSettings.kt +++ b/FlowCrypt/src/enterpriseRelease/java/com/flowcrypt/email/util/FlavorSettings.kt @@ -11,6 +11,5 @@ import android.content.Context * @author Denys Bondarenko */ object FlavorSettings : EnvironmentSettings { - override fun isGMailAPIEnabled(): Boolean = true override fun configure(context: Context) {} } diff --git a/FlowCrypt/src/enterpriseUiTests/java/com/flowcrypt/email/util/FlavorSettings.kt b/FlowCrypt/src/enterpriseUiTests/java/com/flowcrypt/email/util/FlavorSettings.kt index 50505ccb0b..7d19536241 100644 --- a/FlowCrypt/src/enterpriseUiTests/java/com/flowcrypt/email/util/FlavorSettings.kt +++ b/FlowCrypt/src/enterpriseUiTests/java/com/flowcrypt/email/util/FlavorSettings.kt @@ -18,7 +18,6 @@ object FlavorSettings : EnvironmentSettings { GeneralUtil.isDebugBuild() ) - override fun isGMailAPIEnabled(): Boolean = true override fun configure(context: Context) {} override fun getCountingIdlingResource() = countingIdlingResource override fun getGoogleIdToken(): String = UUID.randomUUID().toString() diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptRoomDatabase.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptRoomDatabase.kt index a735d2e1db..c7e8b857b3 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptRoomDatabase.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptRoomDatabase.kt @@ -87,7 +87,7 @@ abstract class FlowCryptRoomDatabase : RoomDatabase() { companion object { const val DB_NAME = "flowcrypt.db" - const val DB_VERSION = 35 + const val DB_VERSION = 36 private val MIGRATION_1_3 = object : FlowCryptMigration(1, 3) { override fun doMigration(database: SupportSQLiteDatabase) { @@ -1216,6 +1216,52 @@ abstract class FlowCryptRoomDatabase : RoomDatabase() { } } + @VisibleForTesting + val MIGRATION_35_36 = object : FlowCryptMigration(35, 36) { + override fun doMigration(database: SupportSQLiteDatabase) { + //we need to clean old cache for some 'com.google' users: messages, attachments, labels + + val commonWhereClause = "email IN (SELECT email FROM " + AccountEntity.TABLE_NAME + + " WHERE account_type = ? AND use_api = ?)" + val commonWhereArgs = arrayOf( + AccountEntity.ACCOUNT_TYPE_GOOGLE, + "0", + JavaEmailConstants.FOLDER_OUTBOX + ) + //delete messages for predefined 'com.google' users, except outgoing + database.delete( + MessageEntity.TABLE_NAME, + "$commonWhereClause AND folder != ?", + commonWhereArgs + ) + + //delete attachments for predefined 'com.google' users, except outgoing + database.delete( + AttachmentEntity.TABLE_NAME, + "$commonWhereClause AND folder != ?", + commonWhereArgs + ) + + //delete all labels for 'com.google' users + database.delete( + LabelEntity.TABLE_NAME, + commonWhereClause, + commonWhereArgs.copyOf(2) + ) + + //in the and we need to force using Gmail API by 'com.google' users via 'use_api = 1' + val contentValues = ContentValues() + contentValues.put("use_api", "1") + database.update( + AccountEntity.TABLE_NAME, + SQLiteDatabase.CONFLICT_IGNORE, + contentValues, + "account_type = ?", + arrayOf(AccountEntity.ACCOUNT_TYPE_GOOGLE) + ) + } + } + // Singleton prevents multiple instances of database opening at the same time. @Volatile private var INSTANCE: FlowCryptRoomDatabase? = null @@ -1265,6 +1311,7 @@ abstract class FlowCryptRoomDatabase : RoomDatabase() { MIGRATION_32_33, MIGRATION_33_34, MIGRATION_34_35, + MIGRATION_35_36, ).build() INSTANCE = instance return instance diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AccountEntity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AccountEntity.kt index d2d70f4f7b..365454d2b9 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AccountEntity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AccountEntity.kt @@ -18,7 +18,6 @@ import com.flowcrypt.email.api.email.gmail.GmailConstants import com.flowcrypt.email.api.email.model.AuthCredentials import com.flowcrypt.email.api.email.model.SecurityType import com.flowcrypt.email.api.retrofit.response.model.ClientConfiguration -import com.flowcrypt.email.util.FlavorSettings import com.google.android.gms.auth.api.signin.GoogleSignInAccount import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize @@ -27,7 +26,7 @@ import kotlinx.parcelize.Parcelize * @author Denys Bondarenko */ @Entity( - tableName = "accounts", + tableName = AccountEntity.TABLE_NAME, indices = [ Index(name = "email_account_type_in_accounts", value = ["email", "account_type"], unique = true) ] @@ -128,7 +127,7 @@ data class AccountEntity constructor( contactsLoaded = false, showOnlyEncrypted = false, clientConfiguration = clientConfiguration, - useAPI = FlavorSettings.isGMailAPIEnabled(), + useAPI = true, useCustomerFesUrl = useCustomerFesUrl ) @@ -229,6 +228,7 @@ data class AccountEntity constructor( } companion object { + const val TABLE_NAME = "accounts" const val ACCOUNT_TYPE_GOOGLE = "com.google" const val ACCOUNT_TYPE_OUTLOOK = "outlook.com" } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AttachmentEntity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AttachmentEntity.kt index 714f38e632..472c6903e1 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AttachmentEntity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/AttachmentEntity.kt @@ -19,7 +19,7 @@ import com.flowcrypt.email.api.email.model.AttachmentInfo * @author Denys Bondarenko */ @Entity( - tableName = "attachment", + tableName = AttachmentEntity.TABLE_NAME, indices = [ Index( name = "email_uid_folder_path_in_attachment", @@ -75,6 +75,8 @@ data class AttachmentEntity( } companion object { + const val TABLE_NAME = "attachment" + fun fromAttInfo(attachmentInfo: AttachmentInfo): AttachmentEntity? { with(attachmentInfo) { val email = email ?: return null diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/LabelEntity.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/LabelEntity.kt index 941e189fa9..cf4593e87d 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/LabelEntity.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/database/entity/LabelEntity.kt @@ -19,7 +19,7 @@ import com.google.android.gms.common.util.CollectionUtils * @author Denys Bondarenko */ @Entity( - tableName = "labels", + tableName = LabelEntity.TABLE_NAME, indices = [ Index( name = "email_account_type_name_in_labels", @@ -52,7 +52,7 @@ data class LabelEntity( val attributesList: List = parseAttributes(attributes) companion object { - + const val TABLE_NAME = "labels" fun genLabel(accountEntity: AccountEntity, localFolder: LocalFolder): LabelEntity { return with(localFolder) { LabelEntity( diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/util/EnvironmentSettings.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/util/EnvironmentSettings.kt index 51c049e6b5..7ae47eaf8f 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/util/EnvironmentSettings.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/util/EnvironmentSettings.kt @@ -15,7 +15,6 @@ import java.util.Properties interface EnvironmentSettings { fun sslTrustedDomains(): List = emptyList() fun getFlavorPropertiesForSession(): Properties = Properties() - fun isGMailAPIEnabled(): Boolean = false fun configure(context: Context) fun getCountingIdlingResource(): CountingIdlingResource? = null fun getGoogleIdToken(): String? = null