Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit defa4d1

Browse files
authored
Merge pull request #525 from owncloud/debug/connection_validator_logs
Add several logs to try to debug potential errors related to token refreshment
2 parents b710070 + 3545686 commit defa4d1

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/ConnectionValidator.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import com.owncloud.android.lib.resources.status.RemoteServerInfo
3737
import org.apache.commons.lang3.exception.ExceptionUtils
3838
import timber.log.Timber
3939
import java.io.IOException
40-
import java.lang.Exception
4140

4241
/**
4342
* ConnectionValidator
@@ -46,7 +45,7 @@ import java.lang.Exception
4645
*/
4746
class ConnectionValidator(
4847
val context: Context,
49-
val clearCookiesOnValidation: Boolean
48+
private val clearCookiesOnValidation: Boolean
5049
) {
5150
fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager, context: Context): Boolean {
5251
try {
@@ -61,12 +60,12 @@ class ConnectionValidator(
6160
client.account = baseClient.account
6261
client.credentials = baseClient.credentials
6362
while (validationRetryCount < VALIDATION_RETRY_COUNT) {
64-
Timber.d("validationRetryCout %d", validationRetryCount)
63+
Timber.d("validationRetryCount %d", validationRetryCount)
6564
var successCounter = 0
6665
var failCounter = 0
6766

6867
client.setFollowRedirects(true)
69-
if (isOnwCloudStatusOk(client)) {
68+
if (isOwnCloudStatusOk(client)) {
7069
successCounter++
7170
} else {
7271
failCounter++
@@ -103,7 +102,7 @@ class ConnectionValidator(
103102
return false
104103
}
105104

106-
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
105+
private fun isOwnCloudStatusOk(client: OwnCloudClient): Boolean {
107106
val reply = getOwnCloudStatus(client)
108107
// dont check status code. It currently relais on the broken redirect code of the owncloud client
109108
// TODO: Use okhttp redirect and add this check again
@@ -138,6 +137,12 @@ class ConnectionValidator(
138137
// test if have all the needed to effectively invalidate ...
139138
shouldInvalidateAccountCredentials =
140139
shouldInvalidateAccountCredentials and (account.savedAccount != null)
140+
Timber.d(
141+
"""Received error: $httpStatusCode,
142+
account: ${account.name}
143+
credentials are real: ${credentials !is OwnCloudAnonymousCredentials},
144+
so we need to invalidate credentials for account ${account.name} : $shouldInvalidateAccountCredentials"""
145+
)
141146
return shouldInvalidateAccountCredentials
142147
}
143148

@@ -150,6 +155,7 @@ class ConnectionValidator(
150155
*
151156
*/
152157
private fun invalidateAccountCredentials(account: OwnCloudAccount, credentials: OwnCloudCredentials) {
158+
Timber.i("Invalidating account credentials for account $account")
153159
val am = AccountManager.get(context)
154160
am.invalidateAuthToken(
155161
account.savedAccount.type,
@@ -167,8 +173,6 @@ class ConnectionValidator(
167173
*
168174
* Refresh current credentials if possible, and marks a retry.
169175
*
170-
* @param status
171-
* @param repeatCounter
172176
* @return
173177
*/
174178
private fun checkUnauthorizedAccess(client: OwnCloudClient, singleSessionManager: SingleSessionManager, status: Int): Boolean {
@@ -181,6 +185,7 @@ class ConnectionValidator(
181185
if (credentials.authTokenCanBeRefreshed()) {
182186
try {
183187
// This command does the actual refresh
188+
Timber.i("Trying to refresh auth token for account $account")
184189
account.loadCredentials(context)
185190
// if mAccount.getCredentials().length() == 0 --> refresh failed
186191
client.credentials = account.credentials
@@ -201,6 +206,7 @@ class ConnectionValidator(
201206
if (!credentialsWereRefreshed) {
202207
// if credentials are not refreshed, client must be removed
203208
// from the OwnCloudClientManager to prevent it is reused once and again
209+
Timber.w("Credentials were not refreshed, client will be removed from the Session Manager to prevent using it over and over")
204210
singleSessionManager.removeClientFor(account)
205211
}
206212
}
@@ -210,6 +216,6 @@ class ConnectionValidator(
210216
}
211217

212218
companion object {
213-
private val VALIDATION_RETRY_COUNT = 3
219+
private const val VALIDATION_RETRY_COUNT = 3
214220
}
215221
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public static OwnCloudCredentials getCredentialsForAccount(Context context, Acco
112112
String username = AccountUtils.getUsernameForAccount(account);
113113

114114
if (isOauth2) {
115+
Timber.i("Trying to retrieve credentials for oAuth account" + account.name);
115116
String accessToken = am.blockingGetAuthToken(
116117
account,
117118
AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),

0 commit comments

Comments
 (0)