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

Commit 3b2f7a67 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Revert "fix: clear cookie if the app is updated"

This reverts commit 73812170.
parent 7f1ad558
Loading
Loading
Loading
Loading
+0 −37
Original line number Diff line number Diff line
@@ -10,16 +10,12 @@ import android.content.ContentUris
import android.content.Context
import android.content.Intent
import android.content.SyncResult
import android.content.pm.PackageManager
import android.net.Uri
import android.os.RemoteException
import android.provider.CalendarContract
import android.provider.ContactsContract
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.edit
import androidx.core.content.pm.PackageInfoCompat
import androidx.preference.PreferenceManager
import at.bitfire.dav4jvm.*
import at.bitfire.dav4jvm.exception.*
import at.bitfire.dav4jvm.property.GetCTag
@@ -179,8 +175,6 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L

    val workDispatcher = getWorkDispatcher()

    private val PREF_LAST_VERSION_CODE = "LAST_VERSION_CODE"

    /**
     * Call performSync with default retry values
     */
@@ -201,34 +195,6 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
        refreshAuthTokenAndSync(authState)
    }

    private fun packageChanged(): Boolean {
        val prefs = PreferenceManager.getDefaultSharedPreferences(context)
        val currentVersion = getCurrentVersionCode()
        val savedVersion = prefs.getLong(PREF_LAST_VERSION_CODE, 0L)
        if (savedVersion != currentVersion) {
            Logger.log.warning("App has been updated!" +
                    "Previous: $savedVersion, Current: $currentVersion")
            prefs.edit {
                putLong(PREF_LAST_VERSION_CODE, currentVersion)
            }
            // Clear cookie since the app is updated.
            Logger.log.warning("Clear cookies for ${accountSettings.credentials().userName}")
            accountSettings.clearCookie()
            return true
        }

        return false
    }

    private fun getCurrentVersionCode(): Long {
        return try {
            val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
            PackageInfoCompat.getLongVersionCode(packageInfo)
        } catch (e: PackageManager.NameNotFoundException) {
            0
        }
    }

    private fun refreshAuthTokenAndSync(authState: AuthState) {
        val tokenRequest = authState.createTokenRefreshRequest()
        val clientSecretString = accountSettings.credentials().clientSecret
@@ -422,9 +388,6 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L

                is UnauthorizedException -> {
                    Logger.log.log(Level.WARNING, "Got 401 Unauthorized", e)
                    if (packageChanged()) {
                        return@unwrapExceptions
                    }
                    val credentials = accountSettings.credentials()
                    if (credentials.authState == null) {
                        credentials.passwordNeedsUpdate = true