Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MigrationTest {
FlowCryptRoomDatabase.MIGRATION_32_33,
FlowCryptRoomDatabase.MIGRATION_33_34,
FlowCryptRoomDatabase.MIGRATION_34_35,
FlowCryptRoomDatabase.MIGRATION_35_36,
)

@get:Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ import android.content.Context
* @author Denys Bondarenko
*/
object FlavorSettings : EnvironmentSettings {
override fun isGMailAPIEnabled(): Boolean = true
override fun configure(context: Context) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ import android.content.Context
* @author Denys Bondarenko
*/
object FlavorSettings : EnvironmentSettings {
override fun isGMailAPIEnabled(): Boolean = true
override fun configure(context: Context) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
]
Expand Down Expand Up @@ -128,7 +127,7 @@ data class AccountEntity constructor(
contactsLoaded = false,
showOnlyEncrypted = false,
clientConfiguration = clientConfiguration,
useAPI = FlavorSettings.isGMailAPIEnabled(),
useAPI = true,
useCustomerFesUrl = useCustomerFesUrl
)

Expand Down Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -52,7 +52,7 @@ data class LabelEntity(
val attributesList: List<String> = parseAttributes(attributes)

companion object {

const val TABLE_NAME = "labels"
fun genLabel(accountEntity: AccountEntity, localFolder: LocalFolder): LabelEntity {
return with(localFolder) {
LabelEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import java.util.Properties
interface EnvironmentSettings {
fun sslTrustedDomains(): List<String> = emptyList()
fun getFlavorPropertiesForSession(): Properties = Properties()
fun isGMailAPIEnabled(): Boolean = false
fun configure(context: Context)
fun getCountingIdlingResource(): CountingIdlingResource? = null
fun getGoogleIdToken(): String? = null
Expand Down