@@ -37,7 +37,6 @@ import com.owncloud.android.lib.resources.status.RemoteServerInfo
37
37
import org.apache.commons.lang3.exception.ExceptionUtils
38
38
import timber.log.Timber
39
39
import java.io.IOException
40
- import java.lang.Exception
41
40
42
41
/* *
43
42
* ConnectionValidator
@@ -46,7 +45,7 @@ import java.lang.Exception
46
45
*/
47
46
class ConnectionValidator (
48
47
val context : Context ,
49
- val clearCookiesOnValidation : Boolean
48
+ private val clearCookiesOnValidation : Boolean
50
49
) {
51
50
fun validate (baseClient : OwnCloudClient , singleSessionManager : SingleSessionManager , context : Context ): Boolean {
52
51
try {
@@ -61,12 +60,12 @@ class ConnectionValidator(
61
60
client.account = baseClient.account
62
61
client.credentials = baseClient.credentials
63
62
while (validationRetryCount < VALIDATION_RETRY_COUNT ) {
64
- Timber .d(" validationRetryCout %d" , validationRetryCount)
63
+ Timber .d(" validationRetryCount %d" , validationRetryCount)
65
64
var successCounter = 0
66
65
var failCounter = 0
67
66
68
67
client.setFollowRedirects(true )
69
- if (isOnwCloudStatusOk (client)) {
68
+ if (isOwnCloudStatusOk (client)) {
70
69
successCounter++
71
70
} else {
72
71
failCounter++
@@ -103,7 +102,7 @@ class ConnectionValidator(
103
102
return false
104
103
}
105
104
106
- private fun isOnwCloudStatusOk (client : OwnCloudClient ): Boolean {
105
+ private fun isOwnCloudStatusOk (client : OwnCloudClient ): Boolean {
107
106
val reply = getOwnCloudStatus(client)
108
107
// dont check status code. It currently relais on the broken redirect code of the owncloud client
109
108
// TODO: Use okhttp redirect and add this check again
@@ -138,6 +137,12 @@ class ConnectionValidator(
138
137
// test if have all the needed to effectively invalidate ...
139
138
shouldInvalidateAccountCredentials =
140
139
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
+ )
141
146
return shouldInvalidateAccountCredentials
142
147
}
143
148
@@ -150,6 +155,7 @@ class ConnectionValidator(
150
155
*
151
156
*/
152
157
private fun invalidateAccountCredentials (account : OwnCloudAccount , credentials : OwnCloudCredentials ) {
158
+ Timber .i(" Invalidating account credentials for account $account " )
153
159
val am = AccountManager .get(context)
154
160
am.invalidateAuthToken(
155
161
account.savedAccount.type,
@@ -167,8 +173,6 @@ class ConnectionValidator(
167
173
*
168
174
* Refresh current credentials if possible, and marks a retry.
169
175
*
170
- * @param status
171
- * @param repeatCounter
172
176
* @return
173
177
*/
174
178
private fun checkUnauthorizedAccess (client : OwnCloudClient , singleSessionManager : SingleSessionManager , status : Int ): Boolean {
@@ -181,6 +185,7 @@ class ConnectionValidator(
181
185
if (credentials.authTokenCanBeRefreshed()) {
182
186
try {
183
187
// This command does the actual refresh
188
+ Timber .i(" Trying to refresh auth token for account $account " )
184
189
account.loadCredentials(context)
185
190
// if mAccount.getCredentials().length() == 0 --> refresh failed
186
191
client.credentials = account.credentials
@@ -201,6 +206,7 @@ class ConnectionValidator(
201
206
if (! credentialsWereRefreshed) {
202
207
// if credentials are not refreshed, client must be removed
203
208
// 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" )
204
210
singleSessionManager.removeClientFor(account)
205
211
}
206
212
}
@@ -210,6 +216,6 @@ class ConnectionValidator(
210
216
}
211
217
212
218
companion object {
213
- private val VALIDATION_RETRY_COUNT = 3
219
+ private const val VALIDATION_RETRY_COUNT = 3
214
220
}
215
221
}
0 commit comments