mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			bdabc97f80
			...
			a035423d34
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | a035423d34 | 
| @ -1,6 +1,6 @@ | |||||||
| buildscript { | buildscript { | ||||||
|     ext { |     ext { | ||||||
|         orgJetbrainsKotlin = '1.8.10' |         orgJetbrainsKotlin = '1.7.20' | ||||||
|         comSquareupMoshi = '1.14.0' |         comSquareupMoshi = '1.14.0' | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -10,8 +10,8 @@ buildscript { | |||||||
|         maven { url "https://plugins.gradle.org/m2/" } |         maven { url "https://plugins.gradle.org/m2/" } | ||||||
|     } |     } | ||||||
|     dependencies { |     dependencies { | ||||||
|         classpath "org.jlleitschuh.gradle:ktlint-gradle:11.1.0" |         classpath "org.jlleitschuh.gradle:ktlint-gradle:11.0.0" | ||||||
|         classpath 'com.android.tools.build:gradle:7.4.1' |         classpath 'com.android.tools.build:gradle:7.3.1' | ||||||
|         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$orgJetbrainsKotlin" |         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$orgJetbrainsKotlin" | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							| @ -1,5 +1,5 @@ | |||||||
| distributionBase=GRADLE_USER_HOME | distributionBase=GRADLE_USER_HOME | ||||||
| distributionPath=wrapper/dists | distributionPath=wrapper/dists | ||||||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip | ||||||
| zipStoreBase=GRADLE_USER_HOME | zipStoreBase=GRADLE_USER_HOME | ||||||
| zipStorePath=wrapper/dists | zipStorePath=wrapper/dists | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ apply plugin: 'kotlin-parcelize' | |||||||
| 
 | 
 | ||||||
| dependencies { | dependencies { | ||||||
|     api 'com.squareup.okhttp3:okhttp:4.6.0' |     api 'com.squareup.okhttp3:okhttp:4.6.0' | ||||||
|     implementation "org.jetbrains.kotlin:kotlin-stdlib:$orgJetbrainsKotlin" |     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$orgJetbrainsKotlin" | ||||||
|     api 'com.gitlab.ownclouders:dav4android:oc_support_2.1.5' |     api 'com.gitlab.ownclouders:dav4android:oc_support_2.1.5' | ||||||
|     api 'com.github.AppDevNext.Logcat:LogcatCore:2.12' |     api 'com.github.AppDevNext.Logcat:LogcatCore:2.12' | ||||||
| 
 | 
 | ||||||
| @ -17,7 +17,7 @@ dependencies { | |||||||
|     kapt "com.squareup.moshi:moshi-kotlin-codegen:$comSquareupMoshi" |     kapt "com.squareup.moshi:moshi-kotlin-codegen:$comSquareupMoshi" | ||||||
| 
 | 
 | ||||||
|     testImplementation 'junit:junit:4.13.2' |     testImplementation 'junit:junit:4.13.2' | ||||||
|     testImplementation 'org.robolectric:robolectric:4.9.2' |     testImplementation 'org.robolectric:robolectric:4.9' | ||||||
|     debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0' |     debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0' | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -37,6 +37,7 @@ import com.owncloud.android.lib.resources.status.RemoteServerInfo | |||||||
| import org.apache.commons.lang3.exception.ExceptionUtils | import org.apache.commons.lang3.exception.ExceptionUtils | ||||||
| import timber.log.Timber | import timber.log.Timber | ||||||
| import java.io.IOException | import java.io.IOException | ||||||
|  | import java.lang.Exception | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * ConnectionValidator |  * ConnectionValidator | ||||||
| @ -45,7 +46,7 @@ import java.io.IOException | |||||||
|  */ |  */ | ||||||
| class ConnectionValidator( | class ConnectionValidator( | ||||||
|     val context: Context, |     val context: Context, | ||||||
|     private val clearCookiesOnValidation: Boolean |     val clearCookiesOnValidation: Boolean | ||||||
| ) { | ) { | ||||||
|     fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager, context: Context): Boolean { |     fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager, context: Context): Boolean { | ||||||
|         try { |         try { | ||||||
| @ -60,12 +61,12 @@ class ConnectionValidator( | |||||||
|             client.account = baseClient.account |             client.account = baseClient.account | ||||||
|             client.credentials = baseClient.credentials |             client.credentials = baseClient.credentials | ||||||
|             while (validationRetryCount < VALIDATION_RETRY_COUNT) { |             while (validationRetryCount < VALIDATION_RETRY_COUNT) { | ||||||
|                 Timber.d("validationRetryCount %d", validationRetryCount) |                 Timber.d("validationRetryCout %d", validationRetryCount) | ||||||
|                 var successCounter = 0 |                 var successCounter = 0 | ||||||
|                 var failCounter = 0 |                 var failCounter = 0 | ||||||
| 
 | 
 | ||||||
|                 client.setFollowRedirects(true) |                 client.setFollowRedirects(true) | ||||||
|                 if (isOwnCloudStatusOk(client)) { |                 if (isOnwCloudStatusOk(client)) { | ||||||
|                     successCounter++ |                     successCounter++ | ||||||
|                 } else { |                 } else { | ||||||
|                     failCounter++ |                     failCounter++ | ||||||
| @ -102,7 +103,7 @@ class ConnectionValidator( | |||||||
|         return false |         return false | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private fun isOwnCloudStatusOk(client: OwnCloudClient): Boolean { |     private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean { | ||||||
|         val reply = getOwnCloudStatus(client) |         val reply = getOwnCloudStatus(client) | ||||||
|         // dont check status code. It currently relais on the broken redirect code of the owncloud client |         // dont check status code. It currently relais on the broken redirect code of the owncloud client | ||||||
|         // TODO: Use okhttp redirect and add this check again |         // TODO: Use okhttp redirect and add this check again | ||||||
| @ -137,12 +138,6 @@ class ConnectionValidator( | |||||||
|         // test if have all the needed to effectively invalidate ... |         // test if have all the needed to effectively invalidate ... | ||||||
|         shouldInvalidateAccountCredentials = |         shouldInvalidateAccountCredentials = | ||||||
|             shouldInvalidateAccountCredentials and (account.savedAccount != null) |             shouldInvalidateAccountCredentials and (account.savedAccount != null) | ||||||
|         Timber.d( |  | ||||||
|             """Received error: $httpStatusCode, |  | ||||||
|             account: ${account.name} |  | ||||||
|             credentials are real: ${credentials !is OwnCloudAnonymousCredentials}, |  | ||||||
|             so we need to invalidate credentials for account ${account.name} : $shouldInvalidateAccountCredentials""" |  | ||||||
|         ) |  | ||||||
|         return shouldInvalidateAccountCredentials |         return shouldInvalidateAccountCredentials | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -155,7 +150,6 @@ class ConnectionValidator( | |||||||
|      * |      * | ||||||
|      */ |      */ | ||||||
|     private fun invalidateAccountCredentials(account: OwnCloudAccount, credentials: OwnCloudCredentials) { |     private fun invalidateAccountCredentials(account: OwnCloudAccount, credentials: OwnCloudCredentials) { | ||||||
|         Timber.i("Invalidating account credentials for account $account") |  | ||||||
|         val am = AccountManager.get(context) |         val am = AccountManager.get(context) | ||||||
|         am.invalidateAuthToken( |         am.invalidateAuthToken( | ||||||
|             account.savedAccount.type, |             account.savedAccount.type, | ||||||
| @ -173,6 +167,8 @@ class ConnectionValidator( | |||||||
|      * |      * | ||||||
|      * Refresh current credentials if possible, and marks a retry. |      * Refresh current credentials if possible, and marks a retry. | ||||||
|      * |      * | ||||||
|  |      * @param status | ||||||
|  |      * @param repeatCounter | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     private fun checkUnauthorizedAccess(client: OwnCloudClient, singleSessionManager: SingleSessionManager, status: Int): Boolean { |     private fun checkUnauthorizedAccess(client: OwnCloudClient, singleSessionManager: SingleSessionManager, status: Int): Boolean { | ||||||
| @ -185,7 +181,6 @@ class ConnectionValidator( | |||||||
|             if (credentials.authTokenCanBeRefreshed()) { |             if (credentials.authTokenCanBeRefreshed()) { | ||||||
|                 try { |                 try { | ||||||
|                     // This command does the actual refresh |                     // This command does the actual refresh | ||||||
|                     Timber.i("Trying to refresh auth token for account $account") |  | ||||||
|                     account.loadCredentials(context) |                     account.loadCredentials(context) | ||||||
|                     // if mAccount.getCredentials().length() == 0 --> refresh failed |                     // if mAccount.getCredentials().length() == 0 --> refresh failed | ||||||
|                     client.credentials = account.credentials |                     client.credentials = account.credentials | ||||||
| @ -206,7 +201,6 @@ class ConnectionValidator( | |||||||
|                 if (!credentialsWereRefreshed) { |                 if (!credentialsWereRefreshed) { | ||||||
|                     // if credentials are not refreshed, client must be removed |                     // if credentials are not refreshed, client must be removed | ||||||
|                     // from the OwnCloudClientManager to prevent it is reused once and again |                     // from the OwnCloudClientManager to prevent it is reused once and again | ||||||
|                     Timber.w("Credentials were not refreshed, client will be removed from the Session Manager to prevent using it over and over") |  | ||||||
|                     singleSessionManager.removeClientFor(account) |                     singleSessionManager.removeClientFor(account) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @ -216,6 +210,6 @@ class ConnectionValidator( | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     companion object { |     companion object { | ||||||
|         private const val VALIDATION_RETRY_COUNT = 3 |         private val VALIDATION_RETRY_COUNT = 3 | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -31,6 +31,7 @@ import android.net.Uri; | |||||||
| 
 | 
 | ||||||
| import com.owncloud.android.lib.common.accounts.AccountUtils; | import com.owncloud.android.lib.common.accounts.AccountUtils; | ||||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; | import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; | ||||||
|  | import com.owncloud.android.lib.common.http.HttpClient; | ||||||
| import timber.log.Timber; | import timber.log.Timber; | ||||||
| 
 | 
 | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| @ -123,24 +124,6 @@ public class SingleSessionManager { | |||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             Timber.v("reusing client for account %s", accountName); |             Timber.v("reusing client for account %s", accountName); | ||||||
|             if (client.getAccount() != null && |  | ||||||
|                     client.getAccount().getCredentials() != null && |  | ||||||
|                     (client.getAccount().getCredentials().getAuthToken() == null || client.getAccount().getCredentials().getAuthToken().isEmpty()) |  | ||||||
|             ) { |  | ||||||
|                 Timber.i("Client " + client.getAccount().getName() + " needs to refresh credentials"); |  | ||||||
| 
 |  | ||||||
|                 //the next two lines are a hack because okHttpclient is used as a singleton instead of being an |  | ||||||
|                 //injected instance that can be deleted when required |  | ||||||
|                 client.clearCookies(); |  | ||||||
|                 client.clearCredentials(); |  | ||||||
| 
 |  | ||||||
|                 client.setAccount(account); |  | ||||||
| 
 |  | ||||||
|                 account.loadCredentials(context); |  | ||||||
|                 client.setCredentials(account.getCredentials()); |  | ||||||
| 
 |  | ||||||
|                 Timber.i("Client " + account.getName() + " with credentials size" + client.getAccount().getCredentials().getAuthToken().length()); |  | ||||||
|             } |  | ||||||
|             reusingKnown = true; |             reusingKnown = true; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -112,7 +112,6 @@ public class AccountUtils { | |||||||
|         String username = AccountUtils.getUsernameForAccount(account); |         String username = AccountUtils.getUsernameForAccount(account); | ||||||
| 
 | 
 | ||||||
|         if (isOauth2) { |         if (isOauth2) { | ||||||
|             Timber.i("Trying to retrieve credentials for oAuth account" + account.name); |  | ||||||
|             String accessToken = am.blockingGetAuthToken( |             String accessToken = am.blockingGetAuthToken( | ||||||
|                     account, |                     account, | ||||||
|                     AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), |                     AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), | ||||||
|  | |||||||
| @ -36,7 +36,13 @@ import com.owncloud.android.lib.common.http.HttpConstants.VALUE_FORMAT | |||||||
| import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod | import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperation | import com.owncloud.android.lib.common.operations.RemoteOperation | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||||
|  | import com.owncloud.android.lib.resources.CommonOcsResponse | ||||||
|  | import com.owncloud.android.lib.resources.shares.responses.ShareItem | ||||||
|  | import com.squareup.moshi.JsonAdapter | ||||||
|  | import com.squareup.moshi.Moshi | ||||||
|  | import com.squareup.moshi.Types | ||||||
| import timber.log.Timber | import timber.log.Timber | ||||||
|  | import java.lang.reflect.Type | ||||||
| import java.net.URL | import java.net.URL | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -46,10 +52,14 @@ import java.net.URL | |||||||
|  * @author David A. Velasco |  * @author David A. Velasco | ||||||
|  * @author David González Verdugo |  * @author David González Verdugo | ||||||
|  * @author Fernando Sanz Velasco |  * @author Fernando Sanz Velasco | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Constructor | ||||||
|  * |  * | ||||||
|  * @param remoteShareId Share ID |  * @param remoteShareId Share ID | ||||||
|  */ |  */ | ||||||
| class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOperation<Unit>() { | class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOperation<ShareResponse>() { | ||||||
| 
 | 
 | ||||||
|     private fun buildRequestUri(baseUri: Uri) = |     private fun buildRequestUri(baseUri: Uri) = | ||||||
|         baseUri.buildUpon() |         baseUri.buildUpon() | ||||||
| @ -58,12 +68,24 @@ class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOper | |||||||
|             .appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT) |             .appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT) | ||||||
|             .build() |             .build() | ||||||
| 
 | 
 | ||||||
|  |     private fun parseResponse(response: String): ShareResponse? { | ||||||
|  |         val moshi = Moshi.Builder().build() | ||||||
|  |         val listOfShareItemType: Type = Types.newParameterizedType(List::class.java, ShareItem::class.java) | ||||||
|  |         val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, listOfShareItemType) | ||||||
|  |         val adapter: JsonAdapter<CommonOcsResponse<List<ShareItem>>> = moshi.adapter(commonOcsType) | ||||||
|  |         return adapter.fromJson(response)?.ocs?.data?.let { listOfShareItems -> | ||||||
|  |             ShareResponse(listOfShareItems.map { shareItem -> | ||||||
|  |                 shareItem.toRemoteShare() | ||||||
|  |             }) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private fun onResultUnsuccessful( |     private fun onResultUnsuccessful( | ||||||
|         method: DeleteMethod, |         method: DeleteMethod, | ||||||
|         response: String?, |         response: String?, | ||||||
|         status: Int |         status: Int | ||||||
|     ): RemoteOperationResult<Unit> { |     ): RemoteOperationResult<ShareResponse> { | ||||||
|         Timber.e("Failed response while removing share ") |         Timber.e("Failed response while unshare link ") | ||||||
|         if (response != null) { |         if (response != null) { | ||||||
|             Timber.e("*** status code: $status; response message: $response") |             Timber.e("*** status code: $status; response message: $response") | ||||||
|         } else { |         } else { | ||||||
| @ -72,14 +94,17 @@ class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOper | |||||||
|         return RemoteOperationResult(method) |         return RemoteOperationResult(method) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private fun onRequestSuccessful(response: String?): RemoteOperationResult<Unit> { |     private fun onRequestSuccessful(response: String?): RemoteOperationResult<ShareResponse> { | ||||||
|         val result = RemoteOperationResult<Unit>(RemoteOperationResult.ResultCode.OK) |         val result = RemoteOperationResult<ShareResponse>(RemoteOperationResult.ResultCode.OK) | ||||||
|         Timber.d("Successful response: $response") |         Timber.d("Successful response: $response") | ||||||
|  |         result.data = parseResponse(response!!) | ||||||
|         Timber.d("*** Unshare link completed ") |         Timber.d("*** Unshare link completed ") | ||||||
|         return result |         return result | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> { |     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|         val requestUri = buildRequestUri(client.baseUri) |         val requestUri = buildRequestUri(client.baseUri) | ||||||
| 
 | 
 | ||||||
|         val deleteMethod = DeleteMethod(URL(requestUri.toString())).apply { |         val deleteMethod = DeleteMethod(URL(requestUri.toString())).apply { | ||||||
|  | |||||||
| @ -58,5 +58,5 @@ interface ShareService : Service { | |||||||
|         publicUpload: Boolean |         publicUpload: Boolean | ||||||
|     ): RemoteOperationResult<ShareResponse> |     ): RemoteOperationResult<ShareResponse> | ||||||
| 
 | 
 | ||||||
|     fun deleteShare(remoteId: String): RemoteOperationResult<Unit> |     fun deleteShare(remoteId: String): RemoteOperationResult<ShareResponse> | ||||||
| } | } | ||||||
|  | |||||||
| @ -36,7 +36,8 @@ import com.owncloud.android.lib.resources.shares.ShareType | |||||||
| import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation | import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation | ||||||
| import com.owncloud.android.lib.resources.shares.services.ShareService | import com.owncloud.android.lib.resources.shares.services.ShareService | ||||||
| 
 | 
 | ||||||
| class OCShareService(override val client: OwnCloudClient) : ShareService { | class OCShareService(override val client: OwnCloudClient) : | ||||||
|  |     ShareService { | ||||||
|     override fun getShares( |     override fun getShares( | ||||||
|         remoteFilePath: String, |         remoteFilePath: String, | ||||||
|         reshares: Boolean, |         reshares: Boolean, | ||||||
| @ -89,7 +90,7 @@ class OCShareService(override val client: OwnCloudClient) : ShareService { | |||||||
|             this.retrieveShareDetails = true |             this.retrieveShareDetails = true | ||||||
|         }.execute(client) |         }.execute(client) | ||||||
| 
 | 
 | ||||||
|     override fun deleteShare(remoteId: String): RemoteOperationResult<Unit> = |     override fun deleteShare(remoteId: String): RemoteOperationResult<ShareResponse> = | ||||||
|         RemoveRemoteShareOperation( |         RemoveRemoteShareOperation( | ||||||
|             remoteId |             remoteId | ||||||
|         ).execute(client) |         ).execute(client) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user