diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle
index 28c9a5d1..384dacf3 100644
--- a/owncloudComLibrary/build.gradle
+++ b/owncloudComLibrary/build.gradle
@@ -1,7 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
-
apply plugin: 'kotlin-allopen'
dependencies {
diff --git a/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt b/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt
deleted file mode 100644
index 3c91e836..00000000
--- a/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.owncloud.android.lib.testing
-
-/**
- * This annotation allows us to open some classes for mocking purposes while they are final in
- * release builds.
- */
-@Target(AnnotationTarget.ANNOTATION_CLASS)
-annotation class OpenClass
-
-/**
- * Annotate a class with [OpenForTesting] if you want it to be extendable in debug builds.
- */
-@OpenClass
-@Target(AnnotationTarget.CLASS)
-annotation class OpenForTesting
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java
index 04b1f69a..38fb11e4 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java
@@ -11,7 +11,7 @@ import java.io.IOException;
/**
* Dynamic implementation of {@link OwnCloudClientManager}.
- *
+ *
* Wraps instances of {@link SingleSessionManager} and {@link SimpleFactoryManager} and delegates on one
* or the other depending on the known version of the server corresponding to the {@link OwnCloudAccount}
*
@@ -60,4 +60,4 @@ public class DynamicSessionManager implements OwnCloudClientManager {
mSimpleFactoryManager.saveAllClients(context, accountType);
mSingleSessionManager.saveAllClients(context, accountType);
}
-}
\ No newline at end of file
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java
index ba03b545..222eb366 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java
@@ -149,5 +149,4 @@ public class OwnCloudAccount {
return null;
}
}
-
}
\ No newline at end of file
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java
index e0a48f19..d036214d 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java
@@ -114,7 +114,7 @@ public class OwnCloudClient extends HttpClient {
status = method.execute();
checkFirstRedirection(method);
- if (mFollowRedirects && !isIdPRedirection()) {
+ if (mFollowRedirects) {
status = followRedirection(method).getLastStatus();
}
@@ -422,7 +422,7 @@ public class OwnCloudClient extends HttpClient {
*/
private boolean shouldInvalidateAccountCredentials(int httpStatusCode) {
- boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED || isIdPRedirection()); // invalid credentials
+ boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED); // invalid credentials
should &= (mCredentials != null && // real credentials
!(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials));
@@ -459,17 +459,6 @@ public class OwnCloudClient extends HttpClient {
mOwnCloudClientManager = clientManager;
}
- /**
- * Check if the redirection is to an identity provider such as SAML or wayf
- *
- * @return true if the redirection location includes SAML or wayf, false otherwise
- */
- private boolean isIdPRedirection() {
- return (mRedirectedLocation != null &&
- (mRedirectedLocation.toUpperCase().contains("SAML") ||
- mRedirectedLocation.toLowerCase().contains("wayf")));
- }
-
public boolean followRedirects() {
return mFollowRedirects;
}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java
index 041f72fa..6fb5345f 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java
@@ -24,123 +24,13 @@
package com.owncloud.android.lib.common;
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.AccountManagerFuture;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
-import android.app.Activity;
import android.content.Context;
import android.net.Uri;
-import android.os.Bundle;
-
-import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
-import com.owncloud.android.lib.common.accounts.AccountUtils;
-import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
-import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
-import com.owncloud.android.lib.resources.status.OwnCloudVersion;
-
-import java.io.IOException;
public class OwnCloudClientFactory {
final private static String TAG = OwnCloudClientFactory.class.getSimpleName();
- /**
- * Creates a OwnCloudClient setup for an ownCloud account
- *
- * Do not call this method from the main thread.
- *
- * @param account The ownCloud account
- * @param appContext Android application context
- * @param currentActivity Caller {@link Activity}
- * @return A OwnCloudClient object ready to be used
- * @throws AuthenticatorException If the authenticator failed to get the authorization
- * token for the account.
- * @throws OperationCanceledException If the authenticator operation was cancelled while
- * getting the authorization token for the account.
- * @throws IOException If there was some I/O error while getting the
- * authorization token for the account.
- * @throws AccountNotFoundException If 'account' is unknown for the AccountManager
- */
- public static OwnCloudClient createOwnCloudClient(Account account, Context appContext,
- Activity currentActivity)
- throws OperationCanceledException, AuthenticatorException, IOException,
- AccountNotFoundException {
- Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account));
- AccountManager am = AccountManager.get(appContext);
- // TODO avoid calling to getUserData here
- boolean isOauth2 =
- am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null;
- boolean isSamlSso =
- am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
- OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
-
- String username = AccountUtils.getUsernameForAccount(account);
- if (isOauth2) { // TODO avoid a call to getUserData here
- AccountManagerFuture future = am.getAuthToken(
- account,
- AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),
- null,
- currentActivity,
- null,
- null);
-
- Bundle result = future.getResult();
- String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
- if (accessToken == null) {
- throw new AuthenticatorException("WTF!");
- }
- client.setCredentials(
- OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken)
- );
-
- } else if (isSamlSso) { // TODO avoid a call to getUserData here
- AccountManagerFuture future = am.getAuthToken(
- account,
- AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type),
- null,
- currentActivity,
- null,
- null);
-
- Bundle result = future.getResult();
- String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
- if (accessToken == null) {
- throw new AuthenticatorException("WTF!");
- }
- client.setCredentials(
- OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken)
- );
-
- } else {
- AccountManagerFuture future = am.getAuthToken(
- account,
- AccountTypeUtils.getAuthTokenTypePass(account.type),
- null,
- currentActivity,
- null,
- null
- );
-
- Bundle result = future.getResult();
- String password = result.getString(AccountManager.KEY_AUTHTOKEN);
- OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext);
- client.setCredentials(
- OwnCloudCredentialsFactory.newBasicCredentials(
- username,
- password,
- (version != null && version.isPreemptiveAuthenticationPreferred())
- )
- );
- }
-
- // Restore cookies
- AccountUtils.restoreCookies(account, client, appContext);
-
- return client;
- }
-
/**
* Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud
* client connections.
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java
index b66bc249..14944a15 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2016 ownCloud GmbH.
+ * Copyright (C) 2019 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -38,9 +38,6 @@ public class OwnCloudClientManagerFactory {
case ALWAYS_NEW_CLIENT:
return new SimpleFactoryManager();
- case SINGLE_SESSION_PER_ACCOUNT:
- return new SingleSessionManager();
-
case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING:
return new DynamicSessionManager();
@@ -82,15 +79,11 @@ public class OwnCloudClientManagerFactory {
if (sDefaultSingleton == null) {
return false;
}
- if (policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager)) {
- return true;
- }
- return policy == Policy.SINGLE_SESSION_PER_ACCOUNT && !(sDefaultSingleton instanceof SingleSessionManager);
+ return policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager);
}
public enum Policy {
ALWAYS_NEW_CLIENT,
- SINGLE_SESSION_PER_ACCOUNT,
SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING
}
-}
\ No newline at end of file
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java
index 630ba7f7..21bdf925 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java
@@ -33,7 +33,6 @@ import android.net.Uri;
import android.util.Log;
import com.owncloud.android.lib.common.accounts.AccountUtils;
-import com.owncloud.android.lib.common.authentication.OwnCloudSamlSsoCredentials;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.utils.Log_OC;
@@ -116,10 +115,6 @@ public class SingleSessionManager implements OwnCloudClientManager {
account.loadCredentials(context);
client.setCredentials(account.getCredentials());
- if (client.getCredentials() instanceof OwnCloudSamlSsoCredentials) {
- client.disableAutomaticCookiesHandling();
- }
-
if (accountName != null) {
mClientsWithKnownUsername.put(accountName, client);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
@@ -226,4 +221,4 @@ public class SingleSessionManager implements OwnCloudClientManager {
reusedClient.setBaseUri(recentUri);
}
}
-}
\ No newline at end of file
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java
index b5e67c82..1d40884e 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2016 ownCloud GmbH.
+ * Copyright (C) 2019 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,9 +41,4 @@ public class AccountTypeUtils {
public static String getAuthTokenTypeRefreshToken(String accountType) {
return accountType + ".oauth2.refresh_token";
}
-
- public static String getAuthTokenTypeSamlSessionCookie(String accountType) {
- return accountType + ".saml.web_sso.session_cookie";
- }
-
}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java
index 4478330f..2be339d8 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java
@@ -65,11 +65,7 @@ public class AccountUtils {
OwnCloudCredentials ownCloudCredentials = getCredentialsForAccount(context, account);
webDavUrlForAccount = getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_FILES_PATH_4_0
+ ownCloudCredentials.getUsername();
- } catch (OperationCanceledException e) {
- e.printStackTrace();
- } catch (AuthenticatorException e) {
- e.printStackTrace();
- } catch (IOException e) {
+ } catch (OperationCanceledException | AuthenticatorException | IOException e) {
e.printStackTrace();
}
@@ -148,11 +144,6 @@ public class AccountUtils {
String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2);
boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE");
- String supportsSamlSSo = am.getUserData(account,
- AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO);
-
- boolean isSamlSso = supportsSamlSSo != null && supportsSamlSSo.equals("TRUE");
-
String username = AccountUtils.getUsernameForAccount(account);
OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION));
@@ -164,14 +155,6 @@ public class AccountUtils {
credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken);
- } else if (isSamlSso) {
- String accessToken = am.blockingGetAuthToken(
- account,
- AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type),
- false);
-
- credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken);
-
} else {
String password = am.blockingGetAuthToken(
account,
@@ -317,10 +300,7 @@ public class AccountUtils {
* Flag signaling if the ownCloud server can be accessed with OAuth2 access tokens.
*/
public static final String KEY_SUPPORTS_OAUTH2 = "oc_supports_oauth2";
- /**
- * Flag signaling if the ownCloud server can be accessed with session cookies from SAML-based web single-sign-on.
- */
- public static final String KEY_SUPPORTS_SAML_WEB_SSO = "oc_supports_saml_web_sso";
+
/**
* OC account cookies
*/
@@ -345,6 +325,5 @@ public class AccountUtils {
* OAuth2 refresh token
**/
public static final String KEY_OAUTH2_REFRESH_TOKEN = "oc_oauth2_refresh_token";
-
}
-}
\ No newline at end of file
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java
index 5ac44517..822ef760 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java
@@ -48,10 +48,6 @@ public class OwnCloudCredentialsFactory {
return new OwnCloudBearerCredentials(username, authToken);
}
- public static OwnCloudCredentials newSamlSsoCredentials(String username, String sessionCookie) {
- return new OwnCloudSamlSsoCredentials(username, sessionCookie);
- }
-
public static final OwnCloudCredentials getAnonymousCredentials() {
if (sAnonymousCredentials == null) {
sAnonymousCredentials = new OwnCloudAnonymousCredentials();
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java
deleted file mode 100644
index 40f77bb3..00000000
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2019 ownCloud GmbH.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-package com.owncloud.android.lib.common.authentication;
-
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.http.HttpClient;
-import com.owncloud.android.lib.common.http.HttpConstants;
-
-public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
-
- private String mUsername;
- private String mSessionCookie;
-
- public OwnCloudSamlSsoCredentials(String username, String sessionCookie) {
- mUsername = username != null ? username : "";
- mSessionCookie = sessionCookie != null ? sessionCookie : "";
- }
-
- @Override
- public void applyTo(OwnCloudClient client) {
- // Clear previous credentials
- HttpClient.deleteHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER);
- HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
-
- HttpClient.addHeaderForAllRequests(HttpConstants.COOKIE_HEADER, mSessionCookie);
- client.setFollowRedirects(false);
- }
-
- @Override
- public String getUsername() {
- // not relevant for authentication, but relevant for informational purposes
- return mUsername;
- }
-
- @Override
- public String getAuthToken() {
- return mSessionCookie;
- }
-
- @Override
- public boolean authTokenExpires() {
- return true;
- }
-
- @Override
- public boolean authTokenCanBeRefreshed() {
- return false;
- }
-}
\ No newline at end of file
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java
index 83d1625c..935004dd 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java
@@ -152,5 +152,4 @@ public class OwnCloudOAuth2RequestBuilder implements OAuth2RequestBuilder {
);
}
}
-
}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java
index b0b3e7a2..9564922d 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java
@@ -156,10 +156,13 @@ public class HttpClient {
* @param headerValue
*/
public static void addHeaderForAllRequests(String headerName, String headerValue) {
- getOkHttpInterceptor()
- .addRequestInterceptor(
- new RequestHeaderInterceptor(headerName, headerValue)
- );
+ HttpInterceptor httpInterceptor = getOkHttpInterceptor();
+
+ if(getOkHttpInterceptor() != null) {
+ httpInterceptor.addRequestInterceptor(
+ new RequestHeaderInterceptor(headerName, headerValue)
+ );
+ }
}
public static void deleteHeaderForAllRequests(String headerName) {
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java
index b9720924..55abe84d 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java
@@ -46,26 +46,32 @@ public class HttpInterceptor implements Interceptor {
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
- for (RequestInterceptor interceptor : mRequestInterceptors) {
- request = interceptor.intercept(request);
+ ListIterator requestInterceptorIterator = mRequestInterceptors.listIterator();
+
+ while (requestInterceptorIterator.hasNext()) {
+ RequestInterceptor currentRequestInterceptor = requestInterceptorIterator.next();
+ request = currentRequestInterceptor.intercept(request);
}
Response response = chain.proceed(request);
- for (ResponseInterceptor interceptor : mResponseInterceptors) {
- response = interceptor.intercept(response);
+ ListIterator responseInterceptorIterator = mResponseInterceptors.listIterator();
+
+ while (responseInterceptorIterator.hasNext()) {
+ ResponseInterceptor currentResponseInterceptor = responseInterceptorIterator.next();
+ response = currentResponseInterceptor.intercept(response);
}
return response;
}
public HttpInterceptor addRequestInterceptor(RequestInterceptor requestInterceptor) {
- mRequestInterceptors.add(requestInterceptor);
+ mRequestInterceptors.listIterator().add(requestInterceptor);
return this;
}
public HttpInterceptor addResponseInterceptor(ResponseInterceptor responseInterceptor) {
- mResponseInterceptors.add(responseInterceptor);
+ mResponseInterceptors.listIterator().add(responseInterceptor);
return this;
}
@@ -107,4 +113,4 @@ public class HttpInterceptor implements Interceptor {
public interface ResponseInterceptor {
Response intercept(Response response) throws IOException;
}
-}
\ No newline at end of file
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java
index fc8fd3d4..9f009bbd 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java
@@ -16,7 +16,7 @@ import okhttp3.OkHttpClient;
import java.io.IOException;
-public abstract class RemoteOperation implements Runnable {
+public abstract class RemoteOperation implements Runnable {
/**
* OCS API header name
@@ -192,7 +192,7 @@ public abstract class RemoteOperation implements Runnable {
/**
* Synchronously executes the remote operation
- *
+ *
* Do not call this method from the main thread.
*
* @param client Client object to reach an ownCloud server during the execution of
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java
index e87ed5ec..b58d1b73 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java
@@ -52,7 +52,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-public class RemoteOperationResult
+public class RemoteOperationResult
implements Serializable {
/**
@@ -70,6 +70,7 @@ public class RemoteOperationResult
private ArrayList mAuthenticate = new ArrayList<>();
private String mLastPermanentLocation = null;
private T mData = null;
+
/**
* Public constructor from result code.
*
@@ -253,10 +254,6 @@ public class RemoteOperationResult
}
}
}
- if (isIdPRedirection()) {
- // overrides default ResultCode.UNKNOWN
- mCode = ResultCode.UNAUTHORIZED;
- }
}
/**
@@ -491,12 +488,6 @@ public class RemoteOperationResult
return mRedirectedLocation;
}
- public boolean isIdPRedirection() {
- return (mRedirectedLocation != null &&
- (mRedirectedLocation.toUpperCase().contains("SAML") ||
- mRedirectedLocation.toLowerCase().contains("wayf")));
- }
-
/**
* Checks if is a non https connection
*
@@ -583,4 +574,4 @@ public class RemoteOperationResult
SPECIFIC_UNSUPPORTED_MEDIA_TYPE,
SPECIFIC_METHOD_NOT_ALLOWED
}
-}
\ No newline at end of file
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/Service.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/Service.kt
new file mode 100644
index 00000000..0fa90756
--- /dev/null
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/Service.kt
@@ -0,0 +1,31 @@
+/**
+ * ownCloud Android client application
+ *
+ * @author David González Verdugo
+ *
+ * Copyright (C) 2019 ownCloud GmbH.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.owncloud.android.lib.resources
+
+import com.owncloud.android.lib.common.OwnCloudClient
+
+/**
+ * Facade to perform network calls without the verbosity of remote operations
+ */
+
+interface Service {
+ val client: OwnCloudClient
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java
index f0165505..c9c424d3 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java
@@ -78,8 +78,9 @@ public class FileUtils {
(path.contains("\\") || path.contains("<") || path.contains(">") ||
path.contains(":") || path.contains("\"") || path.contains("|") ||
path.contains("?") || path.contains("*"))) {
+
result = false;
}
return result;
}
-}
\ No newline at end of file
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt
index d439ff26..1419ff7e 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt
@@ -33,16 +33,12 @@ import com.owncloud.android.lib.common.http.HttpConstants
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
+import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK
import com.owncloud.android.lib.common.utils.Log_OC
-
import org.json.JSONObject
-
import java.net.URL
import java.util.ArrayList
-import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK
-import com.owncloud.android.lib.testing.OpenForTesting
-
/**
* Created by masensio on 08/10/2015.
*
@@ -73,7 +69,6 @@ import com.owncloud.android.lib.testing.OpenForTesting
* @author David A. Velasco
* @author David González Verdugo
*/
-@OpenForTesting
class GetRemoteShareesOperation
/**
* Constructor
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt
index 321f170b..f74a7e75 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt
@@ -75,7 +75,7 @@ class GetRemoteSharesForFileOperation(
val getMethod = GetMethod(URL(uriBuilder.build().toString()))
- getMethod.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE)
+ getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
val status = client.executeHttpMethod(getMethod)
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java
deleted file mode 100644
index 5f4110e4..00000000
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/* ownCloud Android Library is available under MIT license
- *
- * Copyright (C) 2019 ownCloud GmbH.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-package com.owncloud.android.lib.resources.shares;
-
-import android.net.Uri;
-
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.http.HttpConstants;
-import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.utils.Log_OC;
-
-import java.net.URL;
-
-/**
- * Get the data from the server about ALL the known shares owned by the requester.
- *
- * @author masensio
- * @author David A. Velasco
- * @author David González Verdugo
- */
-
-public class GetRemoteSharesOperation extends RemoteOperation {
-
- private static final String TAG = GetRemoteSharesOperation.class.getSimpleName();
-
- @Override
- protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result;
-
- try {
- Uri requestUri = client.getBaseUri();
- Uri.Builder uriBuilder = requestUri.buildUpon();
- uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
-
- GetMethod getMethod = new GetMethod(
- new URL(client.getBaseUri() + ShareUtils.SHARING_API_PATH)
- );
-
- getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
-
- int status = client.executeHttpMethod(getMethod);
-
- if (isSuccess(status)) {
-
- // Parse xml response and obtain the list of shares
- ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser(
- new ShareXMLParser()
- );
- parser.setOwnCloudVersion(client.getOwnCloudVersion());
- parser.setServerBaseUri(client.getBaseUri());
- result = parser.parse(getMethod.getResponseBodyAsString());
- } else {
- result = new RemoteOperationResult<>(getMethod);
- }
- } catch (Exception e) {
- result = new RemoteOperationResult<>(e);
- Log_OC.e(TAG, "Exception while getting remote shares ", e);
- }
-
- return result;
- }
-
- private boolean isSuccess(int status) {
- return (status == HttpConstants.HTTP_OK);
- }
-}
\ No newline at end of file
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt
index 04b61b97..a0a4afea 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt
@@ -24,11 +24,7 @@
package com.owncloud.android.lib.resources.shares
-import android.os.Parcel
-import android.os.Parcelable
-import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.resources.files.FileUtils
-import java.io.Serializable
/**
* Contains the data of a Share from the Share API
@@ -37,124 +33,27 @@ import java.io.Serializable
* @author David A. Velasco
* @author David González Verdugo
*/
-class RemoteShare : Parcelable, Serializable {
- var id: Long = 0
- var shareWith: String = ""
- var path: String = ""
- var token: String = ""
- var sharedWithDisplayName: String = ""
- var sharedWithAdditionalInfo: String = ""
- var name: String = ""
- var shareLink: String = ""
- var fileSource: Long = 0
- var itemSource: Long = 0
- var shareType: ShareType? = null
- var permissions: Int = DEFAULT_PERMISSION
- var sharedDate: Long = INIT_SHARED_DATE
- var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS
- var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR)
- var userId: Long = 0
-
+data class RemoteShare(
+ var id: Long = 0,
+ var shareWith: String = "",
+ var path: String = "",
+ var token: String = "",
+ var sharedWithDisplayName: String = "",
+ var sharedWithAdditionalInfo: String = "",
+ var name: String = "",
+ var shareLink: String = "",
+ var fileSource: Long = 0,
+ var itemSource: Long = 0,
+ var shareType: ShareType? = ShareType.UNKNOWN,
+ var permissions: Int = DEFAULT_PERMISSION,
+ var sharedDate: Long = INIT_SHARED_DATE,
+ var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS,
+ var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR),
+ var userId: Long = 0,
val isValid: Boolean = id > -1
-
- constructor() : super() {
- resetData()
- }
-
- constructor(path: String?) {
- resetData()
- if (path.isNullOrEmpty() || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
- Log_OC.e(TAG, "Trying to create a RemoteShare with a non valid path")
- throw IllegalArgumentException("Trying to create a RemoteShare with a non valid path: " + path!!)
- }
- this.path = path
- }
-
- /**
- * Used internally. Reset all file properties
- */
- private fun resetData() {
- id = -1
- shareWith = ""
- path = ""
- token = ""
- sharedWithDisplayName = ""
- sharedWithAdditionalInfo = ""
- name = ""
- shareLink = ""
- fileSource = 0
- itemSource = 0
- shareType = ShareType.NO_SHARED
- permissions = DEFAULT_PERMISSION
- sharedDate = INIT_SHARED_DATE
- expirationDate = INIT_EXPIRATION_DATE_IN_MILLIS
- sharedWithAdditionalInfo = ""
- isFolder = false
- userId = -1
- }
-
- /**
- * Reconstruct from parcel
- *
- * @param source The source parcel
- */
- protected constructor(source: Parcel) {
- readFromParcel(source)
- }
-
- fun readFromParcel(source: Parcel) {
- id = source.readLong()
- shareWith = source.readString().toString()
- path = source.readString().toString()
- token = source.readString().toString()
- sharedWithDisplayName = source.readString().toString()
- sharedWithAdditionalInfo = source.readString().toString()
- name = source.readString().toString()
- shareLink = source.readString().toString()
- fileSource = source.readLong()
- itemSource = source.readLong()
- shareType = ShareType.NO_SHARED
- try {
- shareType = source.readString()?.let { ShareType.valueOf(it) }
- } catch (x: IllegalArgumentException) {
- }
- permissions = source.readInt()
- sharedDate = source.readLong()
- expirationDate = source.readLong()
- isFolder = source.readInt() == 0
- userId = source.readLong()
- }
-
- override fun describeContents(): Int = this.hashCode()
-
- override fun writeToParcel(dest: Parcel, flags: Int) {
- dest.writeLong(id)
- dest.writeString(shareWith)
- dest.writeString(path)
- dest.writeString(token)
- dest.writeString(sharedWithDisplayName)
- dest.writeString(sharedWithAdditionalInfo)
- dest.writeString(name)
- dest.writeString(shareLink)
- dest.writeLong(fileSource)
- dest.writeLong(itemSource)
- dest.writeString(shareType?.name ?: "")
- dest.writeInt(permissions)
- dest.writeLong(sharedDate)
- dest.writeLong(expirationDate)
- dest.writeInt(if (isFolder) 1 else 0)
- dest.writeLong(userId)
- }
+) {
companion object {
-
- /**
- * Generated - should be refreshed every time the class changes!!
- */
- private const val serialVersionUID = 4124975224281327921L
-
- private val TAG = RemoteShare::class.java.simpleName
-
const val DEFAULT_PERMISSION = -1
const val READ_PERMISSION_FLAG = 1
const val UPDATE_PERMISSION_FLAG = 2
@@ -180,18 +79,44 @@ class RemoteShare : Parcelable, Serializable {
const val INIT_EXPIRATION_DATE_IN_MILLIS: Long = 0
const val INIT_SHARED_DATE: Long = 0
+ }
+}
- /**
- * Parcelable Methods
- */
- @JvmField
- val CREATOR: Parcelable.Creator = object : Parcelable.Creator {
- override fun createFromParcel(source: Parcel): RemoteShare {
- return RemoteShare(source)
- }
+/**
+ * // TODO This type is already included in the domain but we still need it here since the parsing takes place in this library for the moment
+ *
+ * Enum for Share Type, with values:
+ * -1 - Unknown
+ * 0 - Shared by user
+ * 1 - Shared by group
+ * 3 - Shared by public link
+ * 4 - Shared by e-mail
+ * 5 - Shared by contact
+ * 6 - Federated
+ *
+ * @author masensio
+ */
- override fun newArray(size: Int): Array {
- return arrayOfNulls(size)
+enum class ShareType constructor(val value: Int) {
+ UNKNOWN(-1),
+ USER(0),
+ GROUP(1),
+ PUBLIC_LINK(3),
+ EMAIL(4),
+ CONTACT(5),
+ FEDERATED(6);
+
+ companion object {
+ fun fromValue(value: Int): ShareType? {
+ return when (value) {
+ -1 -> UNKNOWN
+ 0 -> USER
+ 1 -> GROUP
+ 3 -> PUBLIC_LINK
+ 4 -> EMAIL
+ 5 -> CONTACT
+ 6 -> FEDERATED
+ else -> null
}
}
}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt
new file mode 100644
index 00000000..e8b728b3
--- /dev/null
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt
@@ -0,0 +1,54 @@
+/**
+ * ownCloud Android client application
+ *
+ * @author David González Verdugo
+ *
+ * Copyright (C) 2019 ownCloud GmbH.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.owncloud.android.lib.resources.shares
+
+import com.owncloud.android.lib.common.operations.RemoteOperationResult
+import com.owncloud.android.lib.resources.Service
+
+interface ShareService : Service {
+ fun getShares(
+ remoteFilePath: String,
+ reshares: Boolean,
+ subfiles: Boolean
+ ): RemoteOperationResult
+
+ fun insertShare(
+ remoteFilePath: String,
+ shareType: ShareType,
+ shareWith: String,
+ permissions: Int,
+ name: String,
+ password: String,
+ expirationDate: Long,
+ publicUpload: Boolean
+ ): RemoteOperationResult
+
+ fun updateShare(
+ remoteId: Long,
+ name: String,
+ password: String?,
+ expirationDate: Long,
+ permissions: Int,
+ publicUpload: Boolean
+ ): RemoteOperationResult
+
+ fun deleteShare(remoteId: Long): RemoteOperationResult
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt
deleted file mode 100644
index 234b4276..00000000
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt
+++ /dev/null
@@ -1,64 +0,0 @@
-/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2019 ownCloud GmbH.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-package com.owncloud.android.lib.resources.shares
-
-/**
- * Enum for Share Type, with values:
- * -1 - No shared
- * 0 - Shared by user
- * 1 - Shared by group
- * 3 - Shared by public link
- * 4 - Shared by e-mail
- * 5 - Shared by contact
- * 6 - Federated
- *
- * @author masensio
- */
-
-enum class ShareType constructor(val value: Int) {
- NO_SHARED(-1),
- USER(0),
- GROUP(1),
- PUBLIC_LINK(3),
- EMAIL(4),
- CONTACT(5),
- FEDERATED(6);
-
- companion object {
-
- fun fromValue(value: Int): ShareType? {
- return when (value) {
- -1 -> NO_SHARED
- 0 -> USER
- 1 -> GROUP
- 3 -> PUBLIC_LINK
- 4 -> EMAIL
- 5 -> CONTACT
- 6 -> FEDERATED
- else -> null
- }
- }
- }
-}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt
new file mode 100644
index 00000000..ba6426dc
--- /dev/null
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt
@@ -0,0 +1,34 @@
+/**
+ * ownCloud Android client application
+ *
+ * @author David González Verdugo
+ *
+ * Copyright (C) 2019 ownCloud GmbH.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.owncloud.android.lib.resources.shares
+
+import com.owncloud.android.lib.common.operations.RemoteOperationResult
+import com.owncloud.android.lib.resources.Service
+import org.json.JSONObject
+import java.util.ArrayList
+
+interface ShareeService : Service {
+ fun getSharees(
+ searchString: String,
+ page: Int,
+ perPage: Int
+ ): RemoteOperationResult>
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt
index 49f38e65..16f34e2d 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt
@@ -47,7 +47,6 @@ import java.util.Locale
* @author David A. Velasco
* @author David González Verdugo
*/
-
class UpdateRemoteShareOperation
/**
* Constructor. No update is initialized by default, need to be applied with setters below.
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt
deleted file mode 100644
index 7d3d51e7..00000000
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt
+++ /dev/null
@@ -1,65 +0,0 @@
-/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2019 ownCloud GmbH.
- * @author masensio
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-package com.owncloud.android.lib.resources.status
-
-/**
- * Enum for Boolean Type in RemoteCapability parameters, with values:
- * -1 - Unknown
- * 0 - False
- * 1 - True
- */
-enum class CapabilityBooleanType private constructor(val value: Int) {
- UNKNOWN(-1),
- FALSE(0),
- TRUE(1);
-
- val isUnknown: Boolean
- get() = value == -1
-
- val isFalse: Boolean
- get() = value == 0
-
- val isTrue: Boolean
- get() = value == 1
-
- companion object {
- fun fromValue(value: Int): CapabilityBooleanType? {
- return when (value) {
- -1 -> UNKNOWN
- 0 -> FALSE
- 1 -> TRUE
- else -> null
- }
- }
-
- fun fromBooleanValue(boolValue: Boolean): CapabilityBooleanType {
- return if (boolValue) {
- TRUE
- } else {
- FALSE
- }
- }
- }
-}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt
new file mode 100644
index 00000000..1253f9ca
--- /dev/null
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt
@@ -0,0 +1,28 @@
+/**
+ * ownCloud Android client application
+ *
+ * @author David González Verdugo
+ *
+ * Copyright (C) 2019 ownCloud GmbH.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.owncloud.android.lib.resources.status
+
+import com.owncloud.android.lib.common.operations.RemoteOperationResult
+import com.owncloud.android.lib.resources.Service
+
+interface CapabilityService: Service {
+ fun getCapabilities() : RemoteOperationResult
+}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt
index d5ab846d..e5cd965b 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt
@@ -36,6 +36,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
import com.owncloud.android.lib.common.utils.Log_OC
import org.json.JSONObject
import java.net.URL
+import com.owncloud.android.lib.resources.status.RemoteCapability.CapabilityBooleanType
/**
* Get the Capabilities from the server
@@ -124,7 +125,7 @@ class GetRemoteCapabilitiesOperation : RemoteOperation() {
)
}
if (respFilesSharing.has(PROPERTY_SEARCH_MIN_LENGTH)){
- capability.filesSharingMinLength = respFilesSharing.getInt(
+ capability.filesSharingSearchMinLength = respFilesSharing.getInt(
PROPERTY_SEARCH_MIN_LENGTH)
}
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt
index ef9b6357..dae5b91a 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt
@@ -27,9 +27,7 @@ package com.owncloud.android.lib.resources.status
import android.os.Parcel
import android.os.Parcelable
-import com.owncloud.android.lib.testing.OpenForTesting
-@OpenForTesting
class OwnCloudVersion(version: String) : Comparable, Parcelable {
// format is in version
diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt
index c1337119..6bd51efe 100644
--- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt
+++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt
@@ -29,76 +29,76 @@ package com.owncloud.android.lib.resources.status
/**
* Contains data of the Capabilities for an account, from the Capabilities API
*/
-class RemoteCapability {
- var accountName: String
+data class RemoteCapability(
+ var accountName: String = "",
// Server version
- var versionMayor: Int
- var versionMinor: Int
- var versionMicro: Int
- var versionString: String
- var versionEdition: String
+ var versionMayor: Int = 0,
+ var versionMinor: Int = 0,
+ var versionMicro: Int = 0,
+ var versionString: String = "",
+ var versionEdition: String = "",
// Core PollInterval
- var corePollinterval: Int
+ var corePollinterval: Int = 0,
// Files Sharing
- var filesSharingApiEnabled: CapabilityBooleanType
- var filesSharingMinLength: Int
- var filesSharingPublicEnabled: CapabilityBooleanType
- var filesSharingPublicPasswordEnforced: CapabilityBooleanType
- var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType
- var filesSharingPublicPasswordEnforcedReadWrite: CapabilityBooleanType
- var filesSharingPublicPasswordEnforcedUploadOnly: CapabilityBooleanType
- var filesSharingPublicExpireDateEnabled: CapabilityBooleanType
- var filesSharingPublicExpireDateDays: Int
- var filesSharingPublicExpireDateEnforced: CapabilityBooleanType
- var filesSharingPublicSendMail: CapabilityBooleanType
- var filesSharingPublicUpload: CapabilityBooleanType
- var filesSharingPublicMultiple: CapabilityBooleanType
- var filesSharingPublicSupportsUploadOnly: CapabilityBooleanType
- var filesSharingUserSendMail: CapabilityBooleanType
- var filesSharingResharing: CapabilityBooleanType
- var filesSharingFederationOutgoing: CapabilityBooleanType
- var filesSharingFederationIncoming: CapabilityBooleanType
+ var filesSharingApiEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingSearchMinLength: Int? = DEFAULT_MIN_CHARACTERS_TO_SEARCH,
+ var filesSharingPublicEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicPasswordEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicPasswordEnforcedReadWrite: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicPasswordEnforcedUploadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicExpireDateEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicExpireDateDays: Int = 0,
+ var filesSharingPublicExpireDateEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicSendMail: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicUpload: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicMultiple: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingPublicSupportsUploadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingUserSendMail: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingResharing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingFederationOutgoing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesSharingFederationIncoming: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
// Files
- var filesBigFileChunking: CapabilityBooleanType
- var filesUndelete: CapabilityBooleanType
- var filesVersioning: CapabilityBooleanType
+ var filesBigFileChunking: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesUndelete: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
+ var filesVersioning: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN
+) {
+ /**
+ * Enum for Boolean Type in capabilities, with values:
+ * -1 - Unknown
+ * 0 - False
+ * 1 - True
+ */
+ enum class CapabilityBooleanType constructor(val value: Int) {
+ UNKNOWN(-1),
+ FALSE(0),
+ TRUE(1);
- init {
- accountName = ""
+ companion object {
+ fun fromValue(value: Int): CapabilityBooleanType? {
+ return when (value) {
+ -1 -> UNKNOWN
+ 0 -> FALSE
+ 1 -> TRUE
+ else -> null
+ }
+ }
- versionMayor = 0
- versionMinor = 0
- versionMicro = 0
- versionString = ""
- versionEdition = ""
+ fun fromBooleanValue(boolValue: Boolean): CapabilityBooleanType {
+ return if (boolValue) {
+ TRUE
+ } else {
+ FALSE
+ }
+ }
+ }
+ }
- corePollinterval = 0
-
- filesSharingApiEnabled = CapabilityBooleanType.UNKNOWN
- filesSharingMinLength = 4
- filesSharingPublicEnabled = CapabilityBooleanType.UNKNOWN
- filesSharingPublicPasswordEnforced = CapabilityBooleanType.UNKNOWN
- filesSharingPublicPasswordEnforcedReadOnly = CapabilityBooleanType.UNKNOWN
- filesSharingPublicPasswordEnforcedReadWrite = CapabilityBooleanType.UNKNOWN
- filesSharingPublicPasswordEnforcedUploadOnly = CapabilityBooleanType.UNKNOWN
- filesSharingPublicExpireDateEnabled = CapabilityBooleanType.UNKNOWN
- filesSharingPublicExpireDateDays = 0
- filesSharingPublicExpireDateEnforced = CapabilityBooleanType.UNKNOWN
- filesSharingPublicSendMail = CapabilityBooleanType.UNKNOWN
- filesSharingPublicUpload = CapabilityBooleanType.UNKNOWN
- filesSharingPublicMultiple = CapabilityBooleanType.UNKNOWN
- filesSharingPublicSupportsUploadOnly = CapabilityBooleanType.UNKNOWN
- filesSharingUserSendMail = CapabilityBooleanType.UNKNOWN
- filesSharingResharing = CapabilityBooleanType.UNKNOWN
- filesSharingFederationOutgoing = CapabilityBooleanType.UNKNOWN
- filesSharingFederationIncoming = CapabilityBooleanType.UNKNOWN
-
- filesBigFileChunking = CapabilityBooleanType.UNKNOWN
- filesUndelete = CapabilityBooleanType.UNKNOWN
- filesVersioning = CapabilityBooleanType.UNKNOWN
+ companion object {
+ private const val DEFAULT_MIN_CHARACTERS_TO_SEARCH = 2
}
}
diff --git a/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt b/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt
deleted file mode 100644
index 3c91e836..00000000
--- a/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.owncloud.android.lib.testing
-
-/**
- * This annotation allows us to open some classes for mocking purposes while they are final in
- * release builds.
- */
-@Target(AnnotationTarget.ANNOTATION_CLASS)
-annotation class OpenClass
-
-/**
- * Annotate a class with [OpenForTesting] if you want it to be extendable in debug builds.
- */
-@OpenClass
-@Target(AnnotationTarget.CLASS)
-annotation class OpenForTesting