diff --git a/build.gradle b/build.gradle
index e6a9c02d..1d1e60d2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -21,9 +21,6 @@ dependencies {
api 'com.squareup.okhttp3:okhttp:3.10.0'
api project(':dav4android')
- // Used for network and database debuging
- debugApi 'com.facebook.stetho:stetho:1.5.0'
- debugApi 'com.facebook.stetho:stetho-okhttp3:1.5.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.51"
}
diff --git a/sample_client/AndroidManifest.xml b/sample_client/AndroidManifest.xml
index c0885e36..58d5d6c1 100644
--- a/sample_client/AndroidManifest.xml
+++ b/sample_client/AndroidManifest.xml
@@ -24,23 +24,27 @@
-->
-
+ package="com.owncloud.android.lib.sampleclient"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+
-
-
+
+
-
-
+
+
-
+
\ No newline at end of file
diff --git a/src/com/owncloud/android/lib/common/OwnCloudAccount.java b/src/com/owncloud/android/lib/common/OwnCloudAccount.java
index 533247df..b3ebcd59 100644
--- a/src/com/owncloud/android/lib/common/OwnCloudAccount.java
+++ b/src/com/owncloud/android/lib/common/OwnCloudAccount.java
@@ -116,9 +116,8 @@ public class OwnCloudAccount {
* @throws IOException
* @throws OperationCanceledException
*/
- public void loadCredentials(Context context)
- throws AccountNotFoundException, AuthenticatorException,
- IOException, OperationCanceledException {
+ public void loadCredentials(Context context) throws AuthenticatorException,
+ IOException, OperationCanceledException {
if (context == null) {
throw new IllegalArgumentException("Parameter 'context' cannot be null");
diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java
index 3aba71d9..e05ccc30 100644
--- a/src/com/owncloud/android/lib/common/OwnCloudClient.java
+++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java
@@ -25,36 +25,36 @@
package com.owncloud.android.lib.common;
+import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountsException;
+import android.accounts.AuthenticatorException;
+import android.accounts.OperationCanceledException;
import android.content.Context;
import android.net.Uri;
+import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.http.HttpConstants;
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
-import com.owncloud.android.lib.common.http.methods.webdav.CopyMethod;
import com.owncloud.android.lib.common.network.RedirectionPath;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import at.bitfire.dav4android.exception.HttpException;
-import at.bitfire.dav4android.exception.RedirectException;
import okhttp3.Cookie;
import okhttp3.Headers;
import okhttp3.HttpUrl;
public class OwnCloudClient extends HttpClient {
- public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";
public static final String NEW_WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/";
public static final String NEW_WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
public static final String STATUS_PATH = "/status.php";
@@ -63,8 +63,6 @@ public class OwnCloudClient extends HttpClient {
private static final String TAG = OwnCloudClient.class.getSimpleName();
private static final int MAX_REDIRECTIONS_COUNT = 3;
private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1;
- private static final String PARAM_SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header";
- private static final boolean PARAM_SINGLE_COOKIE_HEADER_VALUE = true;
private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version";
private static byte[] sExhaustBuffer = new byte[1024];
@@ -101,15 +99,6 @@ public class OwnCloudClient extends HttpClient {
mInstanceNumber = sIntanceCounter++;
Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
- //TODO
-// getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
-// getParams().setParameter(
-// PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers
-// PARAM_SINGLE_COOKIE_HEADER_VALUE
-// );
-
-// applyProxySettings();
-
clearCredentials();
}
@@ -198,7 +187,7 @@ public class OwnCloudClient extends HttpClient {
// Release the connection to avoid reach the max number of connections per host
// due to it will be set a different url
- exhaustResponse(method.getResponseAsStream());
+ exhaustResponse(method.getResponseBodyAsStream());
method.setUrl(HttpUrl.parse(location));
final String destination = method.getRequestHeader("Destination") != null
@@ -206,7 +195,7 @@ public class OwnCloudClient extends HttpClient {
: method.getRequestHeader("destination");
if (destination != null) {
- final int suffixIndex = location.lastIndexOf(WEBDAV_PATH_4_0);
+ final int suffixIndex = location.lastIndexOf(getNewFilesWebDavUri().toString());
final String redirectionBase = location.substring(0, suffixIndex);
final String destinationPath = destination.substring(mBaseUri.toString().length());
@@ -250,10 +239,6 @@ public class OwnCloudClient extends HttpClient {
}
}
- public Uri getOldFilesWebdavUri() {
- return Uri.parse(mBaseUri + WEBDAV_PATH_4_0);
- }
-
public Uri getNewFilesWebDavUri() {
return mCredentials instanceof OwnCloudAnonymousCredentials
? Uri.parse(mBaseUri + NEW_WEBDAV_FILES_PATH_4_0)
@@ -288,6 +273,15 @@ public class OwnCloudClient extends HttpClient {
return mCredentials;
}
+ private void logCookie(Cookie cookie) {
+ Log_OC.d(TAG, "Cookie name: " + cookie.name());
+ Log_OC.d(TAG, " value: " + cookie.value());
+ Log_OC.d(TAG, " domain: " + cookie.domain());
+ Log_OC.d(TAG, " path: " + cookie.path());
+ Log_OC.d(TAG, " expiryDate: " + cookie.expiresAt());
+ Log_OC.d(TAG, " secure: " + cookie.secure());
+ }
+
private void logCookiesAtRequest(Headers headers, String when) {
int counter = 0;
for (final String cookieHeader : headers.toMultimap().get("cookie")) {
@@ -331,16 +325,6 @@ public class OwnCloudClient extends HttpClient {
getAccount().getBaseUri().toString()), cookies);
}
- private void logCookie(Cookie cookie) {
- Log_OC.d(TAG, "Cookie name: " + cookie.name());
- Log_OC.d(TAG, " value: " + cookie.value());
- Log_OC.d(TAG, " domain: " + cookie.domain());
- Log_OC.d(TAG, " path: " + cookie.path());
- Log_OC.d(TAG, " expiryDate: " + cookie.expiresAt());
- Log_OC.d(TAG, " secure: " + cookie.secure());
- }
-
-
public void setOwnCloudVersion(OwnCloudVersion version) {
mVersion = version;
}
diff --git a/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java
index a77568f5..94a0c51d 100644
--- a/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java
+++ b/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2016 ownCloud GmbH.
+ * Copyright (C) 2018 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
@@ -24,9 +24,6 @@
package com.owncloud.android.lib.common;
-import java.io.IOException;
-import java.security.GeneralSecurityException;
-
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerFuture;
@@ -40,12 +37,11 @@ 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.http.HttpClient;
-import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
-import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
+import java.io.IOException;
+
public class OwnCloudClientFactory {
final private static String TAG = OwnCloudClientFactory.class.getSimpleName();
@@ -123,9 +119,6 @@ public class OwnCloudClientFactory {
} else {
- //String password = am.getPassword(account);
- //String password = am.blockingGetAuthToken(account, MainApp.getAuthTokenTypePass(),
- // false);
AccountManagerFuture future = am.getAuthToken(
account,
AccountTypeUtils.getAuthTokenTypePass(account.type),
diff --git a/src/com/owncloud/android/lib/common/OwnCloudClientManager.java b/src/com/owncloud/android/lib/common/OwnCloudClientManager.java
index e7fe77af..5ef81382 100644
--- a/src/com/owncloud/android/lib/common/OwnCloudClientManager.java
+++ b/src/com/owncloud/android/lib/common/OwnCloudClientManager.java
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2016 ownCloud GmbH.
+ * Copyright (C) 2018 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,6 +38,7 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce
*
* @author David A. Velasco
* @author masensio
+ * @author Christian Schabesberger
*/
public interface OwnCloudClientManager {
@@ -51,5 +52,4 @@ public interface OwnCloudClientManager {
void saveAllClients(Context context, String accountType)
throws AccountNotFoundException, AuthenticatorException,
IOException, OperationCanceledException;
-
-}
+}
\ No newline at end of file
diff --git a/src/com/owncloud/android/lib/common/SingleSessionManager.java b/src/com/owncloud/android/lib/common/SingleSessionManager.java
index e36f5fe2..f041f465 100644
--- a/src/com/owncloud/android/lib/common/SingleSessionManager.java
+++ b/src/com/owncloud/android/lib/common/SingleSessionManager.java
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2016 ownCloud GmbH.
+ * Copyright (C) 2018 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
@@ -50,6 +50,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
*
* @author David A. Velasco
* @author masensio
+ * @author Christian Schabesberger
*/
public class SingleSessionManager implements OwnCloudClientManager {
diff --git a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java
index a1499481..bf3f92ab 100644
--- a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java
+++ b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2017 ownCloud GmbH.
+ * Copyright (C) 2018 ownCloud GmbH.
* Copyright (C) 2012 Bartek Przybylski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,10 +25,6 @@
package com.owncloud.android.lib.common.accounts;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountsException;
@@ -43,6 +39,10 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
import okhttp3.Cookie;
public class AccountUtils {
@@ -59,11 +59,23 @@ public class AccountUtils {
*/
public static String getWebDavUrlForAccount(Context context, Account account)
throws AccountNotFoundException {
+ String webDavUrlForAccount = "";
- return getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_PATH_4_0;
+ try {
+ OwnCloudCredentials ownCloudCredentials = getCredentialsForAccount(context, account);
+ webDavUrlForAccount = getBaseUrlForAccount(context, account) + OwnCloudClient.NEW_WEBDAV_FILES_PATH_4_0
+ + ownCloudCredentials.getUsername();
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (AuthenticatorException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return webDavUrlForAccount;
}
-
/**
* Extracts url server from the account
*
@@ -84,7 +96,6 @@ public class AccountUtils {
return baseurl;
}
-
/**
* Get the username corresponding to an OC account.
*
@@ -130,7 +141,7 @@ public class AccountUtils {
public static OwnCloudCredentials getCredentialsForAccount(Context context, Account account)
throws OperationCanceledException, AuthenticatorException, IOException {
- OwnCloudCredentials credentials = null;
+ OwnCloudCredentials credentials;
AccountManager am = AccountManager.get(context);
String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2);
@@ -174,10 +185,8 @@ public class AccountUtils {
}
return credentials;
-
}
-
public static String buildAccountNameOld(Uri serverBaseUrl, String username) {
if (serverBaseUrl.getScheme() == null) {
serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString());
@@ -216,7 +225,6 @@ public class AccountUtils {
// Log_OC.d(TAG, "Saving Cookies: "+ cookiesString );
}
}
-
}
/**
@@ -236,7 +244,7 @@ public class AccountUtils {
// Account Manager
AccountManager am = AccountManager.get(context.getApplicationContext());
- Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getOldFilesWebdavUri();
+ Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getNewFilesWebDavUri();
String cookiesString = am.getUserData(account, Constants.KEY_COOKIES);
if (cookiesString != null) {
@@ -275,7 +283,6 @@ public class AccountUtils {
}
}
-
public static class Constants {
/**
* Version should be 3 numbers separated by dot so it can be parsed by
@@ -316,5 +323,4 @@ public class AccountUtils {
public static final String KEY_OAUTH2_REFRESH_TOKEN = "oc_oauth2_refresh_token";
}
-
-}
+}
\ No newline at end of file
diff --git a/src/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java b/src/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java
index f83e6fd5..6d82bdb3 100644
--- a/src/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java
+++ b/src/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2016 ownCloud GmbH.
+ * Copyright (C) 2018 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
@@ -24,10 +24,9 @@
package com.owncloud.android.lib.common.authentication.oauth;
-
/**
- *
* @author David A. Velasco
+ * @author Christian Schabesberger
*/
public class BearerCredentials {
@@ -96,6 +95,4 @@ public class BearerCredentials {
}
return false;
}
-
-}
-
+}
\ No newline at end of file
diff --git a/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java b/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java
index a3cea994..a3e5666f 100644
--- a/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java
+++ b/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2GetAccessTokenOperation.java
@@ -1,7 +1,8 @@
/* ownCloud Android Library is available under MIT license
*
* @author David A. Velasco
- * Copyright (C) 2017 ownCloud GmbH.
+ * @author Christian Schabesberger
+ * Copyright (C) 2018 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
@@ -105,8 +106,6 @@ public class OAuth2GetAccessTokenOperation extends RemoteOperation