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

Commit efb453b4 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

chore: add more debug stuff. Commit to remove before the merge

parent 70087113
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -14,6 +14,7 @@ import android.net.Uri
import android.os.RemoteException
import android.os.RemoteException
import android.provider.CalendarContract
import android.provider.CalendarContract
import android.provider.ContactsContract
import android.provider.ContactsContract
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.NotificationManagerCompat
import at.bitfire.dav4jvm.*
import at.bitfire.dav4jvm.*
@@ -182,10 +183,12 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
        val authState = accountSettings.credentials().authState
        val authState = accountSettings.credentials().authState


        if (authState == null || !authState.needsTokenRefresh) {
        if (authState == null || !authState.needsTokenRefresh) {
            Log.d("SyncManager.performSync()", "perform sync doesn't need to refresh token")
            performSync(DEFAULT_RETRY_AFTER, DEFAULT_SECOND_RETRY_AFTER, DEFAULT_MAX_RETRY_TIME)
            performSync(DEFAULT_RETRY_AFTER, DEFAULT_SECOND_RETRY_AFTER, DEFAULT_MAX_RETRY_TIME)
            return
            return
        }
        }


        Log.d("SyncManager.performSync()", "perform sync needs to refresh token")
        refreshAuthTokenAndSync(authState)
        refreshAuthTokenAndSync(authState)
    }
    }


@@ -194,9 +197,12 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
        val clientSecretString = accountSettings.credentials().clientSecret
        val clientSecretString = accountSettings.credentials().clientSecret
        val clientSecret = OpenIdUtils.getClientAuthentication(clientSecretString)
        val clientSecret = OpenIdUtils.getClientAuthentication(clientSecretString)


        Log.d("SyncManager.performSync()", "Refreshing token")
        val authorizationService = AuthorizationService(context)
        val authorizationService = AuthorizationService(context)

        authorizationService.performTokenRequest(tokenRequest, clientSecret) { tokenResponse, ex ->
        authorizationService.performTokenRequest(tokenRequest, clientSecret) { tokenResponse, ex ->
            authState.update(tokenResponse, ex)
            authState.update(tokenResponse, ex)

            accountSettings.credentials(
            accountSettings.credentials(
                Credentials(
                Credentials(
                    account.name,
                    account.name,
@@ -851,6 +857,7 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
                syncResult.stats.numIoExceptions++
                syncResult.stats.numIoExceptions++
            }
            }
            is UnauthorizedException -> {
            is UnauthorizedException -> {
                Log.d("SyncManager.notifyException()", "unauthorizedException has been caught. Try to show a notif")
                message = context.getString(R.string.sync_error_authentication_failed)
                message = context.getString(R.string.sync_error_authentication_failed)
                syncResult.stats.numAuthExceptions++
                syncResult.stats.numAuthExceptions++


@@ -930,6 +937,7 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
                .setCategory(NotificationCompat.CATEGORY_ERROR)
                .setCategory(NotificationCompat.CATEGORY_ERROR)
        viewItemAction?.let { builder.addAction(it) }
        viewItemAction?.let { builder.addAction(it) }


        Log.d("SyncManager.notifyException()", "about to try to notify if possible")
        notificationManager.notifyIfPossible(notificationTag, NotificationUtils.NOTIFY_SYNC_ERROR, builder.build())
        notificationManager.notifyIfPossible(notificationTag, NotificationUtils.NOTIFY_SYNC_ERROR, builder.build())
    }
    }