1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Merge pull request #278 from owncloud/new_arch/modularization

[New arch] Modularization
This commit is contained in:
David González Verdugo 2019-12-11 11:55:25 +01:00 committed by GitHub
commit a708b794c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 304 additions and 756 deletions

View File

@ -1,7 +1,6 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-allopen' apply plugin: 'kotlin-allopen'
dependencies { dependencies {

View File

@ -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

View File

@ -11,7 +11,7 @@ import java.io.IOException;
/** /**
* Dynamic implementation of {@link OwnCloudClientManager}. * Dynamic implementation of {@link OwnCloudClientManager}.
* <p> *
* Wraps instances of {@link SingleSessionManager} and {@link SimpleFactoryManager} and delegates on one * 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} * or the other depending on the known version of the server corresponding to the {@link OwnCloudAccount}
* *

View File

@ -149,5 +149,4 @@ public class OwnCloudAccount {
return null; return null;
} }
} }
} }

View File

@ -114,7 +114,7 @@ public class OwnCloudClient extends HttpClient {
status = method.execute(); status = method.execute();
checkFirstRedirection(method); checkFirstRedirection(method);
if (mFollowRedirects && !isIdPRedirection()) { if (mFollowRedirects) {
status = followRedirection(method).getLastStatus(); status = followRedirection(method).getLastStatus();
} }
@ -422,7 +422,7 @@ public class OwnCloudClient extends HttpClient {
*/ */
private boolean shouldInvalidateAccountCredentials(int httpStatusCode) { 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 should &= (mCredentials != null && // real credentials
!(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials)); !(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials));
@ -459,17 +459,6 @@ public class OwnCloudClient extends HttpClient {
mOwnCloudClientManager = clientManager; 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() { public boolean followRedirects() {
return mFollowRedirects; return mFollowRedirects;
} }

View File

@ -24,123 +24,13 @@
package com.owncloud.android.lib.common; 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.content.Context;
import android.net.Uri; 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 { public class OwnCloudClientFactory {
final private static String TAG = OwnCloudClientFactory.class.getSimpleName(); final private static String TAG = OwnCloudClientFactory.class.getSimpleName();
/**
* Creates a OwnCloudClient setup for an ownCloud account
* <p>
* 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<Bundle> 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<Bundle> 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<Bundle> 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 * Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud
* client connections. * client connections.

View File

@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license /* 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -38,9 +38,6 @@ public class OwnCloudClientManagerFactory {
case ALWAYS_NEW_CLIENT: case ALWAYS_NEW_CLIENT:
return new SimpleFactoryManager(); return new SimpleFactoryManager();
case SINGLE_SESSION_PER_ACCOUNT:
return new SingleSessionManager();
case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING: case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING:
return new DynamicSessionManager(); return new DynamicSessionManager();
@ -82,15 +79,11 @@ public class OwnCloudClientManagerFactory {
if (sDefaultSingleton == null) { if (sDefaultSingleton == null) {
return false; return false;
} }
if (policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager)) { return policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager);
return true;
}
return policy == Policy.SINGLE_SESSION_PER_ACCOUNT && !(sDefaultSingleton instanceof SingleSessionManager);
} }
public enum Policy { public enum Policy {
ALWAYS_NEW_CLIENT, ALWAYS_NEW_CLIENT,
SINGLE_SESSION_PER_ACCOUNT,
SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING
} }
} }

View File

@ -33,7 +33,6 @@ import android.net.Uri;
import android.util.Log; import android.util.Log;
import com.owncloud.android.lib.common.accounts.AccountUtils; 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.http.HttpClient;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
@ -116,10 +115,6 @@ public class SingleSessionManager implements OwnCloudClientManager {
account.loadCredentials(context); account.loadCredentials(context);
client.setCredentials(account.getCredentials()); client.setCredentials(account.getCredentials());
if (client.getCredentials() instanceof OwnCloudSamlSsoCredentials) {
client.disableAutomaticCookiesHandling();
}
if (accountName != null) { if (accountName != null) {
mClientsWithKnownUsername.put(accountName, client); mClientsWithKnownUsername.put(accountName, client);
if (Log.isLoggable(TAG, Log.VERBOSE)) { if (Log.isLoggable(TAG, Log.VERBOSE)) {

View File

@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license /* 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -41,9 +41,4 @@ public class AccountTypeUtils {
public static String getAuthTokenTypeRefreshToken(String accountType) { public static String getAuthTokenTypeRefreshToken(String accountType) {
return accountType + ".oauth2.refresh_token"; return accountType + ".oauth2.refresh_token";
} }
public static String getAuthTokenTypeSamlSessionCookie(String accountType) {
return accountType + ".saml.web_sso.session_cookie";
}
} }

View File

@ -65,11 +65,7 @@ public class AccountUtils {
OwnCloudCredentials ownCloudCredentials = getCredentialsForAccount(context, account); OwnCloudCredentials ownCloudCredentials = getCredentialsForAccount(context, account);
webDavUrlForAccount = getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_FILES_PATH_4_0 webDavUrlForAccount = getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_FILES_PATH_4_0
+ ownCloudCredentials.getUsername(); + ownCloudCredentials.getUsername();
} catch (OperationCanceledException e) { } catch (OperationCanceledException | AuthenticatorException | IOException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -148,11 +144,6 @@ public class AccountUtils {
String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2); String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2);
boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE"); 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); String username = AccountUtils.getUsernameForAccount(account);
OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION)); OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION));
@ -164,14 +155,6 @@ public class AccountUtils {
credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken); credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken);
} else if (isSamlSso) {
String accessToken = am.blockingGetAuthToken(
account,
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type),
false);
credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken);
} else { } else {
String password = am.blockingGetAuthToken( String password = am.blockingGetAuthToken(
account, account,
@ -317,10 +300,7 @@ public class AccountUtils {
* Flag signaling if the ownCloud server can be accessed with OAuth2 access tokens. * Flag signaling if the ownCloud server can be accessed with OAuth2 access tokens.
*/ */
public static final String KEY_SUPPORTS_OAUTH2 = "oc_supports_oauth2"; 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 * OC account cookies
*/ */
@ -345,6 +325,5 @@ public class AccountUtils {
* OAuth2 refresh token * OAuth2 refresh token
**/ **/
public static final String KEY_OAUTH2_REFRESH_TOKEN = "oc_oauth2_refresh_token"; public static final String KEY_OAUTH2_REFRESH_TOKEN = "oc_oauth2_refresh_token";
} }
} }

View File

@ -48,10 +48,6 @@ public class OwnCloudCredentialsFactory {
return new OwnCloudBearerCredentials(username, authToken); return new OwnCloudBearerCredentials(username, authToken);
} }
public static OwnCloudCredentials newSamlSsoCredentials(String username, String sessionCookie) {
return new OwnCloudSamlSsoCredentials(username, sessionCookie);
}
public static final OwnCloudCredentials getAnonymousCredentials() { public static final OwnCloudCredentials getAnonymousCredentials() {
if (sAnonymousCredentials == null) { if (sAnonymousCredentials == null) {
sAnonymousCredentials = new OwnCloudAnonymousCredentials(); sAnonymousCredentials = new OwnCloudAnonymousCredentials();

View File

@ -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;
}
}

View File

@ -152,5 +152,4 @@ public class OwnCloudOAuth2RequestBuilder implements OAuth2RequestBuilder {
); );
} }
} }
} }

View File

@ -156,10 +156,13 @@ public class HttpClient {
* @param headerValue * @param headerValue
*/ */
public static void addHeaderForAllRequests(String headerName, String headerValue) { public static void addHeaderForAllRequests(String headerName, String headerValue) {
getOkHttpInterceptor() HttpInterceptor httpInterceptor = getOkHttpInterceptor();
.addRequestInterceptor(
new RequestHeaderInterceptor(headerName, headerValue) if(getOkHttpInterceptor() != null) {
); httpInterceptor.addRequestInterceptor(
new RequestHeaderInterceptor(headerName, headerValue)
);
}
} }
public static void deleteHeaderForAllRequests(String headerName) { public static void deleteHeaderForAllRequests(String headerName) {

View File

@ -46,26 +46,32 @@ public class HttpInterceptor implements Interceptor {
public Response intercept(Chain chain) throws IOException { public Response intercept(Chain chain) throws IOException {
Request request = chain.request(); Request request = chain.request();
for (RequestInterceptor interceptor : mRequestInterceptors) { ListIterator<RequestInterceptor> requestInterceptorIterator = mRequestInterceptors.listIterator();
request = interceptor.intercept(request);
while (requestInterceptorIterator.hasNext()) {
RequestInterceptor currentRequestInterceptor = requestInterceptorIterator.next();
request = currentRequestInterceptor.intercept(request);
} }
Response response = chain.proceed(request); Response response = chain.proceed(request);
for (ResponseInterceptor interceptor : mResponseInterceptors) { ListIterator<ResponseInterceptor> responseInterceptorIterator = mResponseInterceptors.listIterator();
response = interceptor.intercept(response);
while (responseInterceptorIterator.hasNext()) {
ResponseInterceptor currentResponseInterceptor = responseInterceptorIterator.next();
response = currentResponseInterceptor.intercept(response);
} }
return response; return response;
} }
public HttpInterceptor addRequestInterceptor(RequestInterceptor requestInterceptor) { public HttpInterceptor addRequestInterceptor(RequestInterceptor requestInterceptor) {
mRequestInterceptors.add(requestInterceptor); mRequestInterceptors.listIterator().add(requestInterceptor);
return this; return this;
} }
public HttpInterceptor addResponseInterceptor(ResponseInterceptor responseInterceptor) { public HttpInterceptor addResponseInterceptor(ResponseInterceptor responseInterceptor) {
mResponseInterceptors.add(responseInterceptor); mResponseInterceptors.listIterator().add(responseInterceptor);
return this; return this;
} }

View File

@ -16,7 +16,7 @@ import okhttp3.OkHttpClient;
import java.io.IOException; import java.io.IOException;
public abstract class RemoteOperation<T extends Object> implements Runnable { public abstract class RemoteOperation<T> implements Runnable {
/** /**
* OCS API header name * OCS API header name
@ -192,7 +192,7 @@ public abstract class RemoteOperation<T extends Object> implements Runnable {
/** /**
* Synchronously executes the remote operation * Synchronously executes the remote operation
* <p> *
* Do not call this method from the main thread. * Do not call this method from the main thread.
* *
* @param client Client object to reach an ownCloud server during the execution of * @param client Client object to reach an ownCloud server during the execution of

View File

@ -52,7 +52,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class RemoteOperationResult<T extends Object> public class RemoteOperationResult<T>
implements Serializable { implements Serializable {
/** /**
@ -70,6 +70,7 @@ public class RemoteOperationResult<T extends Object>
private ArrayList<String> mAuthenticate = new ArrayList<>(); private ArrayList<String> mAuthenticate = new ArrayList<>();
private String mLastPermanentLocation = null; private String mLastPermanentLocation = null;
private T mData = null; private T mData = null;
/** /**
* Public constructor from result code. * Public constructor from result code.
* <p> * <p>
@ -253,10 +254,6 @@ public class RemoteOperationResult<T extends Object>
} }
} }
} }
if (isIdPRedirection()) {
// overrides default ResultCode.UNKNOWN
mCode = ResultCode.UNAUTHORIZED;
}
} }
/** /**
@ -491,12 +488,6 @@ public class RemoteOperationResult<T extends Object>
return mRedirectedLocation; return mRedirectedLocation;
} }
public boolean isIdPRedirection() {
return (mRedirectedLocation != null &&
(mRedirectedLocation.toUpperCase().contains("SAML") ||
mRedirectedLocation.toLowerCase().contains("wayf")));
}
/** /**
* Checks if is a non https connection * Checks if is a non https connection
* *

View File

@ -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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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
}

View File

@ -78,6 +78,7 @@ public class FileUtils {
(path.contains("\\") || path.contains("<") || path.contains(">") || (path.contains("\\") || path.contains("<") || path.contains(">") ||
path.contains(":") || path.contains("\"") || path.contains("|") || path.contains(":") || path.contains("\"") || path.contains("|") ||
path.contains("?") || path.contains("*"))) { path.contains("?") || path.contains("*"))) {
result = false; result = false;
} }
return result; return result;

View File

@ -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.http.methods.nonwebdav.GetMethod
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.common.operations.RemoteOperationResult.ResultCode.OK
import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.common.utils.Log_OC
import org.json.JSONObject import org.json.JSONObject
import java.net.URL import java.net.URL
import java.util.ArrayList 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. * Created by masensio on 08/10/2015.
* *
@ -73,7 +69,6 @@ import com.owncloud.android.lib.testing.OpenForTesting
* @author David A. Velasco * @author David A. Velasco
* @author David González Verdugo * @author David González Verdugo
*/ */
@OpenForTesting
class GetRemoteShareesOperation class GetRemoteShareesOperation
/** /**
* Constructor * Constructor

View File

@ -75,7 +75,7 @@ class GetRemoteSharesForFileOperation(
val getMethod = GetMethod(URL(uriBuilder.build().toString())) 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) val status = client.executeHttpMethod(getMethod)

View File

@ -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);
}
}

View File

@ -24,11 +24,7 @@
package com.owncloud.android.lib.resources.shares 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 com.owncloud.android.lib.resources.files.FileUtils
import java.io.Serializable
/** /**
* Contains the data of a Share from the Share API * Contains the data of a Share from the Share API
@ -37,124 +33,27 @@ import java.io.Serializable
* @author David A. Velasco * @author David A. Velasco
* @author David González Verdugo * @author David González Verdugo
*/ */
class RemoteShare : Parcelable, Serializable { data class RemoteShare(
var id: Long = 0 var id: Long = 0,
var shareWith: String = "" var shareWith: String = "",
var path: String = "" var path: String = "",
var token: String = "" var token: String = "",
var sharedWithDisplayName: String = "" var sharedWithDisplayName: String = "",
var sharedWithAdditionalInfo: String = "" var sharedWithAdditionalInfo: String = "",
var name: String = "" var name: String = "",
var shareLink: String = "" var shareLink: String = "",
var fileSource: Long = 0 var fileSource: Long = 0,
var itemSource: Long = 0 var itemSource: Long = 0,
var shareType: ShareType? = null var shareType: ShareType? = ShareType.UNKNOWN,
var permissions: Int = DEFAULT_PERMISSION var permissions: Int = DEFAULT_PERMISSION,
var sharedDate: Long = INIT_SHARED_DATE var sharedDate: Long = INIT_SHARED_DATE,
var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS,
var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR) var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR),
var userId: Long = 0 var userId: Long = 0,
val isValid: Boolean = id > -1 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 { 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 DEFAULT_PERMISSION = -1
const val READ_PERMISSION_FLAG = 1 const val READ_PERMISSION_FLAG = 1
const val UPDATE_PERMISSION_FLAG = 2 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_EXPIRATION_DATE_IN_MILLIS: Long = 0
const val INIT_SHARED_DATE: Long = 0 const val INIT_SHARED_DATE: Long = 0
}
}
/** /**
* Parcelable Methods * // 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
*/ *
@JvmField * Enum for Share Type, with values:
val CREATOR: Parcelable.Creator<RemoteShare> = object : Parcelable.Creator<RemoteShare> { * -1 - Unknown
override fun createFromParcel(source: Parcel): RemoteShare { * 0 - Shared by user
return RemoteShare(source) * 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<RemoteShare?> { enum class ShareType constructor(val value: Int) {
return arrayOfNulls(size) 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
} }
} }
} }

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<ShareParserResult>
fun insertShare(
remoteFilePath: String,
shareType: ShareType,
shareWith: String,
permissions: Int,
name: String,
password: String,
expirationDate: Long,
publicUpload: Boolean
): RemoteOperationResult<ShareParserResult>
fun updateShare(
remoteId: Long,
name: String,
password: String?,
expirationDate: Long,
permissions: Int,
publicUpload: Boolean
): RemoteOperationResult<ShareParserResult>
fun deleteShare(remoteId: Long): RemoteOperationResult<ShareParserResult>
}

View File

@ -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
}
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<ArrayList<JSONObject>>
}

View File

@ -47,7 +47,6 @@ import java.util.Locale
* @author David A. Velasco * @author David A. Velasco
* @author David González Verdugo * @author David González Verdugo
*/ */
class UpdateRemoteShareOperation class UpdateRemoteShareOperation
/** /**
* Constructor. No update is initialized by default, need to be applied with setters below. * Constructor. No update is initialized by default, need to be applied with setters below.

View File

@ -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
}
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<RemoteCapability>
}

View File

@ -36,6 +36,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.common.utils.Log_OC
import org.json.JSONObject import org.json.JSONObject
import java.net.URL import java.net.URL
import com.owncloud.android.lib.resources.status.RemoteCapability.CapabilityBooleanType
/** /**
* Get the Capabilities from the server * Get the Capabilities from the server
@ -124,7 +125,7 @@ class GetRemoteCapabilitiesOperation : RemoteOperation<RemoteCapability>() {
) )
} }
if (respFilesSharing.has(PROPERTY_SEARCH_MIN_LENGTH)){ if (respFilesSharing.has(PROPERTY_SEARCH_MIN_LENGTH)){
capability.filesSharingMinLength = respFilesSharing.getInt( capability.filesSharingSearchMinLength = respFilesSharing.getInt(
PROPERTY_SEARCH_MIN_LENGTH) PROPERTY_SEARCH_MIN_LENGTH)
} }

View File

@ -27,9 +27,7 @@ package com.owncloud.android.lib.resources.status
import android.os.Parcel import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
import com.owncloud.android.lib.testing.OpenForTesting
@OpenForTesting
class OwnCloudVersion(version: String) : Comparable<OwnCloudVersion>, Parcelable { class OwnCloudVersion(version: String) : Comparable<OwnCloudVersion>, Parcelable {
// format is in version // format is in version

View File

@ -29,76 +29,76 @@ package com.owncloud.android.lib.resources.status
/** /**
* Contains data of the Capabilities for an account, from the Capabilities API * Contains data of the Capabilities for an account, from the Capabilities API
*/ */
class RemoteCapability { data class RemoteCapability(
var accountName: String var accountName: String = "",
// Server version // Server version
var versionMayor: Int var versionMayor: Int = 0,
var versionMinor: Int var versionMinor: Int = 0,
var versionMicro: Int var versionMicro: Int = 0,
var versionString: String var versionString: String = "",
var versionEdition: String var versionEdition: String = "",
// Core PollInterval // Core PollInterval
var corePollinterval: Int var corePollinterval: Int = 0,
// Files Sharing // Files Sharing
var filesSharingApiEnabled: CapabilityBooleanType var filesSharingApiEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingMinLength: Int var filesSharingSearchMinLength: Int? = DEFAULT_MIN_CHARACTERS_TO_SEARCH,
var filesSharingPublicEnabled: CapabilityBooleanType var filesSharingPublicEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicPasswordEnforced: CapabilityBooleanType var filesSharingPublicPasswordEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicPasswordEnforcedReadWrite: CapabilityBooleanType var filesSharingPublicPasswordEnforcedReadWrite: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicPasswordEnforcedUploadOnly: CapabilityBooleanType var filesSharingPublicPasswordEnforcedUploadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicExpireDateEnabled: CapabilityBooleanType var filesSharingPublicExpireDateEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicExpireDateDays: Int var filesSharingPublicExpireDateDays: Int = 0,
var filesSharingPublicExpireDateEnforced: CapabilityBooleanType var filesSharingPublicExpireDateEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicSendMail: CapabilityBooleanType var filesSharingPublicSendMail: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicUpload: CapabilityBooleanType var filesSharingPublicUpload: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicMultiple: CapabilityBooleanType var filesSharingPublicMultiple: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingPublicSupportsUploadOnly: CapabilityBooleanType var filesSharingPublicSupportsUploadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingUserSendMail: CapabilityBooleanType var filesSharingUserSendMail: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingResharing: CapabilityBooleanType var filesSharingResharing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingFederationOutgoing: CapabilityBooleanType var filesSharingFederationOutgoing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesSharingFederationIncoming: CapabilityBooleanType var filesSharingFederationIncoming: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
// Files // Files
var filesBigFileChunking: CapabilityBooleanType var filesBigFileChunking: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesUndelete: CapabilityBooleanType var filesUndelete: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
var filesVersioning: CapabilityBooleanType 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 { companion object {
accountName = "" fun fromValue(value: Int): CapabilityBooleanType? {
return when (value) {
-1 -> UNKNOWN
0 -> FALSE
1 -> TRUE
else -> null
}
}
versionMayor = 0 fun fromBooleanValue(boolValue: Boolean): CapabilityBooleanType {
versionMinor = 0 return if (boolValue) {
versionMicro = 0 TRUE
versionString = "" } else {
versionEdition = "" FALSE
}
}
}
}
corePollinterval = 0 companion object {
private const val DEFAULT_MIN_CHARACTERS_TO_SEARCH = 2
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
} }
} }

View File

@ -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